Skip to content

Commit

Permalink
allow to upload initial
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Aug 19, 2024
1 parent 5f3a8bf commit 9dcd8cc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
38 changes: 35 additions & 3 deletions app/javascript/submission_form/initials_step.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@
</span>
</a>
</span>
<span
class="tooltip"
:data-tip="t('click_to_upload')"
>
<label
class="btn btn-outline btn-sm font-medium inline-flex flex-nowrap"
>
<IconUpload :width="16" />
<input
:key="uploadImageInputKey"
type="file"
hidden
accept="image/*"
@change="drawImage"
>
<span class="hidden sm:inline">
{{ t('upload') }}
</span>
</label>
</span>
<a
v-if="modelValue || computedPreviousValue"
href="#"
Expand Down Expand Up @@ -97,7 +117,7 @@
<img
v-if="modelValue || computedPreviousValue"
:src="attachmentsIndex[modelValue || computedPreviousValue].url"
class="mx-auto bg-white border border-base-300 rounded max-h-72"
class="mx-auto bg-white border border-base-300 rounded max-h-44"
>
<canvas
v-show="!modelValue && !computedPreviousValue"
Expand All @@ -120,16 +140,18 @@

<script>
import { cropCanvasAndExportToPNG } from './crop_canvas'
import { IconReload, IconTextSize, IconSignature, IconArrowsDiagonalMinimize2 } from '@tabler/icons-vue'
import { IconReload, IconTextSize, IconUpload, IconSignature, IconArrowsDiagonalMinimize2 } from '@tabler/icons-vue'
import SignaturePad from 'signature_pad'
import AppearsOn from './appears_on'
import MarkdownContent from './markdown_content'
import SignatureStep from './signature_step'
const scale = 3
export default {
name: 'InitialsStep',
components: {
IconUpload,
AppearsOn,
IconReload,
IconTextSize,
Expand Down Expand Up @@ -178,7 +200,8 @@ export default {
return {
isInitialsStarted: !!this.previousValue,
isUsePreviousValue: true,
isDrawInitials: false
isDrawInitials: false,
uploadImageInputKey: Math.random().toString()
}
},
computed: {
Expand Down Expand Up @@ -229,6 +252,15 @@ export default {
this.intersectionObserver?.disconnect()
},
methods: {
drawOnCanvas: SignatureStep.methods.drawOnCanvas,
drawImage (event) {
this.remove()
this.isInitialsStarted = true
this.drawOnCanvas(this.$refs.canvas)
this.uploadImageInputKey = Math.random().toString()
},
remove () {
this.$emit('update:model-value', '')
Expand Down
8 changes: 5 additions & 3 deletions app/javascript/submission_form/signature_step.vue
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@ export default {
this.remove()
this.isSignatureStarted = true
this.drawOnCanvas(this.$refs.canvas)
this.uploadImageInputKey = Math.random().toString()
},
drawOnCanvas (canvas) {
const file = event.target.files[0]
if (file && file.type.match('image.*')) {
Expand All @@ -580,7 +585,6 @@ export default {
img.src = event.target.result
img.onload = () => {
const canvas = this.$refs.canvas
const context = canvas.getContext('2d')
const aspectRatio = img.width / img.height
Expand Down Expand Up @@ -615,8 +619,6 @@ export default {
}
reader.readAsDataURL(file)
this.uploadImageInputKey = Math.random().toString()
}
},
maybeSetSignedUuid (signedUuid) {
Expand Down

0 comments on commit 9dcd8cc

Please sign in to comment.