add pdf generation
This commit is contained in:
@@ -5,12 +5,14 @@ import { createApp, reactive } from 'vue'
|
||||
import ToggleVisible from './elements/toggle_visible'
|
||||
import DisableHidden from './elements/disable_hidden'
|
||||
import TurboModal from './elements/turbo_modal'
|
||||
import FileDropzone from './elements/file_dropzone'
|
||||
|
||||
import FlowBuilder from './flow_builder/builder'
|
||||
|
||||
window.customElements.define('toggle-visible', ToggleVisible)
|
||||
window.customElements.define('disable-hidden', DisableHidden)
|
||||
window.customElements.define('turbo-modal', TurboModal)
|
||||
window.customElements.define('file-dropzone', FileDropzone)
|
||||
|
||||
window.customElements.define('flow-builder', class extends HTMLElement {
|
||||
connectedCallback () {
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import { DirectUpload } from '@rails/activestorage'
|
||||
|
||||
import { actionable } from '@github/catalyst/lib/actionable'
|
||||
import { target, targetable } from '@github/catalyst/lib/targetable'
|
||||
|
||||
export default actionable(targetable(class extends HTMLElement {
|
||||
static [target.static] = [
|
||||
'loading',
|
||||
'input',
|
||||
'valueField'
|
||||
]
|
||||
|
||||
connectedCallback () {
|
||||
this.addEventListener('drop', this.onDrop)
|
||||
|
||||
this.addEventListener('dragover', (e) => e.preventDefault())
|
||||
}
|
||||
|
||||
onDrop (e) {
|
||||
e.preventDefault()
|
||||
|
||||
this.uploadFiles(e.dataTransfer.files)
|
||||
}
|
||||
|
||||
onSelectFiles (e) {
|
||||
e.preventDefault()
|
||||
|
||||
this.uploadFiles(this.input.files).then(() => {
|
||||
this.input.value = ''
|
||||
})
|
||||
}
|
||||
|
||||
async uploadFiles (files) {
|
||||
console.log( files )
|
||||
const blobs = await Promise.all(
|
||||
Array.from(files).map(async (file) => {
|
||||
const upload = new DirectUpload(
|
||||
file,
|
||||
'/direct_uploads',
|
||||
this.input
|
||||
)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
upload.create((error, blob) => {
|
||||
if (error) {
|
||||
console.error(error)
|
||||
|
||||
return reject(error)
|
||||
} else {
|
||||
return resolve(blob)
|
||||
}
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.error(error)
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
await Promise.all(
|
||||
blobs.map((blob) => {
|
||||
return fetch('/api/attachments', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
name: this.dataset.name,
|
||||
blob_signed_id: blob.signed_id,
|
||||
submission_slug: this.dataset.submissionSlug
|
||||
}),
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
}).then(resp => resp.json()).then((data) => {
|
||||
return data
|
||||
})
|
||||
})).then((result) => {
|
||||
result.forEach((attachment) => {
|
||||
if (this.valueField) {
|
||||
this.valueField.value = attachment.uuid
|
||||
}
|
||||
|
||||
this.dispatchEvent(new CustomEvent('upload', { detail: attachment }))
|
||||
})
|
||||
})
|
||||
}
|
||||
}))
|
||||
@@ -91,7 +91,7 @@ export default {
|
||||
onDrop (e) {
|
||||
this.$emit('drop-field', {
|
||||
x: e.layerX / this.$refs.mask.clientWidth,
|
||||
y: e.layerY / this.$refs.mask.clientHeight,
|
||||
y: e.layerY / this.$refs.mask.clientHeight - (this.$refs.mask.clientWidth / 30 / this.$refs.mask.clientWidth) / 2,
|
||||
w: this.$refs.mask.clientWidth / 5 / this.$refs.mask.clientWidth,
|
||||
h: this.$refs.mask.clientWidth / 30 / this.$refs.mask.clientWidth,
|
||||
page: this.number
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
<template>
|
||||
<div
|
||||
class="flex cursor-pointer bg-red-100 absolute"
|
||||
class="flex cursor-pointer bg-red-100 bg-opacity-60 absolute"
|
||||
:style="computedStyle"
|
||||
>
|
||||
<img
|
||||
v-if="field.type === 'image' && image"
|
||||
class="object-contain"
|
||||
:src="image.url"
|
||||
>
|
||||
<img
|
||||
v-else-if="field.type === 'signature' && signature"
|
||||
class="object-contain"
|
||||
:src="signature.url"
|
||||
>
|
||||
<div v-else-if="field.type === 'attachment'">
|
||||
|
||||
@@ -83,7 +83,7 @@ export default {
|
||||
body: JSON.stringify({
|
||||
submission_slug: this.submissionSlug,
|
||||
blob_signed_id: data.signed_id,
|
||||
name: 'signatures'
|
||||
name: 'attachments'
|
||||
}),
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
}).then((resp) => resp.json()).then((attachment) => {
|
||||
|
||||
Reference in New Issue
Block a user