-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
卒業証書のPDFファイルをアップロードできる機能を追加 #8190
base: main
Are you sure you want to change the base?
Changes from 12 commits
496b8ec
8385b8a
3d8dc4e
f3bc5cc
d16a661
fd1d8db
b2ff53d
3aeb25a
6b5d653
9b55b38
7d82332
97b19ed
ba692b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,41 @@ function extractField(elements) { | |
} | ||
} | ||
|
||
function initializeDiplomaUploadField() { | ||
const uploadField = document.getElementById('js-pdf-upload-field') | ||
if (!uploadField) return | ||
|
||
const removeButton = document.getElementById('js-remove-pdf-button') | ||
const fileLink = document.getElementById('js-pdf-file-link') | ||
const removeFlag = document.getElementById('js-remove-pdf-flag') | ||
const fileName = document.getElementById('js-pdf-name') | ||
const fileInput = uploadField.querySelector('input[type="file"]') | ||
|
||
uploadField.style.display = fileLink ? 'none' : 'flex' | ||
removeButton.style.display = fileLink ? 'block' : 'none' | ||
|
||
const updateDisplayedFileName = (name = '') => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 細かい点ですが、 "表示状態をアップデートする"ということで もっと良いものがあればそちらにしていただいて構いません🙇♂️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
fileName.textContent = name | ||
const displayedStatus = name ? 'block' : 'none' | ||
fileName.style.display = displayedStatus | ||
removeButton.style.display = displayedStatus | ||
} | ||
|
||
removeButton.addEventListener('click', () => { | ||
if (fileLink) fileLink.style.display = 'none' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ファイルがアップロードされている時のみ削除ボタンが表示されていれば、if文は不要になるかもです There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fileLinkはHTMLが生成されない場合があるのでエラーになるようです。 |
||
uploadField.style.display = 'flex' | ||
fileInput.value = '' | ||
removeFlag.value = '1' | ||
updateDisplayedFileName() | ||
}) | ||
|
||
fileInput.addEventListener('change', () => { | ||
const selectedFile = fileInput.files[0] | ||
updateDisplayedFileName(selectedFile.name) | ||
if (selectedFile) removeFlag.value = '0' | ||
}) | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const ref = document.querySelector('#reference_books') | ||
if (ref) { | ||
|
@@ -84,4 +119,5 @@ document.addEventListener('DOMContentLoaded', () => { | |
}) | ||
} | ||
initializeFileInput(document) | ||
initializeDiplomaUploadField() | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,48 @@ | ||
.a-file-input | ||
label | ||
height: 10rem | ||
max-width: 100% | ||
margin-inline: auto | ||
border: solid 1px var(--input-border) | ||
background-color: var(--base) | ||
display: flex | ||
align-items: center | ||
justify-content: center | ||
+position(relative) | ||
overflow: hidden | ||
cursor: pointer | ||
border-radius: .25rem | ||
padding: .5rem .5rem 2.75rem .5rem | ||
&.is-thumbnail | ||
label | ||
height: 15rem | ||
img | ||
max-height: 100% | ||
transition: all .2s ease-out | ||
&:hover | ||
opacity: .6 | ||
&.is-square img | ||
+size(7rem) | ||
object-fit: cover | ||
&.is-book img | ||
max-height: 100% | ||
max-width: 100% | ||
object-fit: contain | ||
border: solid 1px var(--border-tint) | ||
.a-pdf-input | ||
display: flex | ||
gap: .75rem | ||
+media-breakpoint-down(sm) | ||
flex-direction: column | ||
|
||
.a-pdf-input__inner | ||
flex: 1 | ||
background-color: var(--base) | ||
display: flex | ||
align-items: center | ||
justify-content: center | ||
+position(relative) | ||
overflow: hidden | ||
cursor: pointer | ||
border-radius: .25rem | ||
height: 2.25rem | ||
input | ||
overflow: hidden | ||
+size(0) | ||
+position(absolute, left 0, top 0) | ||
opacity: 0 | ||
p | ||
+size(100% 2.25rem) | ||
background-color: var(--base) | ||
+position(absolute, left 0, bottom 0, right 0) | ||
+text-block(.8125rem 1, flex 600) | ||
justify-content: center | ||
align-items: center | ||
border-top: solid 1px var(--input-border) | ||
transition: all .2s ease-out | ||
&:hover | ||
background-color: #e8e8e8 | ||
|
||
a.a-pdf-input__inner | ||
text-decoration: none | ||
color: var(--default-text) | ||
|
||
.a-pdf-input__file | ||
padding: .5rem | ||
flex: 1 | ||
border-radius: .25rem 0 0 .25rem | ||
border: solid 1px var(--input-border) | ||
border-right: none | ||
height: 2.25rem | ||
|
||
.a-pdf-input__file-name | ||
font-size: .875rem | ||
white-space: nowrap | ||
overflow: hidden | ||
text-overflow: ellipsis | ||
display: block | ||
+media-breakpoint-up(md) | ||
max-width: 18rem | ||
+media-breakpoint-down(sm) | ||
max-width: 8rem | ||
|
||
.a-pdf-input__upload.a-button | ||
border-radius: 0 .25rem .25rem 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
.a-pdf-input | ||
display: flex | ||
gap: .75rem | ||
+media-breakpoint-down(sm) | ||
flex-direction: column | ||
|
||
.a-pdf-input__inner | ||
flex: 1 | ||
background-color: var(--base) | ||
display: flex | ||
align-items: center | ||
justify-content: center | ||
+position(relative) | ||
overflow: hidden | ||
cursor: pointer | ||
border-radius: .25rem | ||
height: 2.25rem | ||
input | ||
overflow: hidden | ||
+size(0) | ||
+position(absolute, left 0, top 0) | ||
opacity: 0 | ||
|
||
a.a-pdf-input__inner | ||
text-decoration: none | ||
color: var(--default-text) | ||
|
||
.a-pdf-input__file | ||
padding: .5rem | ||
flex: 1 | ||
border-radius: .25rem 0 0 .25rem | ||
border: solid 1px var(--input-border) | ||
border-right: none | ||
height: 2.25rem | ||
|
||
.a-pdf-input__file-name | ||
font-size: .875rem | ||
white-space: nowrap | ||
overflow: hidden | ||
text-overflow: ellipsis | ||
display: block | ||
+media-breakpoint-up(md) | ||
max-width: 18rem | ||
+media-breakpoint-down(sm) | ||
max-width: 8rem | ||
|
||
.a-pdf-input__upload.a-button | ||
border-radius: 0 .25rem .25rem 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,25 @@ | |
.form-item-block__item | ||
= render 'users/form/graduate', f: f | ||
|
||
.form-item | ||
= f.hidden_field :remove_diploma, value: '0', id: 'js-remove-pdf-flag' | ||
= f.label :diploma_file, class: 'a-form-label' | ||
.a-pdf-input | ||
- if @user.diploma_file.attached? | ||
= link_to url_for(@user.diploma_file), class: 'a-pdf-input__inner', id: 'js-pdf-file-link', target: '_blank', rel: 'noopener' do | ||
.a-pdf-input__file | ||
span.a-pdf-input__file-name | ||
= @user.diploma_file.filename | ||
.a-pdf-input__upload.a-button.is-md.is-secondary | ||
| PDFを確認 | ||
label.a-pdf-input__inner#js-pdf-upload-field | ||
= f.file_field :diploma_file | ||
.a-pdf-input__file | ||
span.a-pdf-input__file-name#js-pdf-name | ||
.a-pdf-input__upload.a-button.is-md.is-secondary | ||
| PDFを選択 | ||
= button_tag '削除', type: 'button', class: 'a-button is-md is-secondary', id: 'js-remove-pdf-button' | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. button_tagが使えそうです! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 変更しました There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ファイルがアップロードされていない状態で削除ボタンがあるのはおかしい気がします🤔 |
||
.form-item-block | ||
.form-item-block__inner | ||
header.form-item-block__header | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="ja"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>卒業証書</title> | ||
</head> | ||
<body> | ||
<h1>卒業証書</h1> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fileLinkをよくif文に使われているので、if文の条件として分かりやすい名前をつけてあげると可読性があがるかもです。
こんな感じでどうでしょうか。
const isFileUploaded = fileLink
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
必要あるか微妙なんですけど
isFileUploaded
は名前的に真偽値を期待させるので二重否定して真偽値になるようにしました。