make public storage and direct upload optional
This commit is contained in:
@@ -7,7 +7,14 @@ module Api
|
|||||||
def create
|
def create
|
||||||
submitter = Submitter.find_by!(slug: params[:submitter_slug])
|
submitter = Submitter.find_by!(slug: params[:submitter_slug])
|
||||||
|
|
||||||
blob = ActiveStorage::Blob.find_signed(params[:blob_signed_id])
|
blob =
|
||||||
|
if (file = params[:file])
|
||||||
|
ActiveStorage::Blob.create_and_upload!(io: file.open,
|
||||||
|
filename: file.original_filename,
|
||||||
|
content_type: file.content_type)
|
||||||
|
else
|
||||||
|
ActiveStorage::Blob.find_signed(params[:blob_signed_id])
|
||||||
|
end
|
||||||
|
|
||||||
attachment = ActiveStorage::Attachment.create!(
|
attachment = ActiveStorage::Attachment.create!(
|
||||||
blob:,
|
blob:,
|
||||||
|
|||||||
@@ -6,9 +6,7 @@ module Api
|
|||||||
@template = current_account.templates.find(params[:template_id])
|
@template = current_account.templates.find(params[:template_id])
|
||||||
|
|
||||||
documents =
|
documents =
|
||||||
params[:blobs].map do |blob|
|
find_or_create_blobs.map do |blob|
|
||||||
blob = ActiveStorage::Blob.find_signed(blob[:signed_id])
|
|
||||||
|
|
||||||
document = @template.documents.create!(blob:)
|
document = @template.documents.create!(blob:)
|
||||||
|
|
||||||
Templates::ProcessDocument.call(document)
|
Templates::ProcessDocument.call(document)
|
||||||
@@ -27,5 +25,19 @@ module Api
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def find_or_create_blobs
|
||||||
|
blobs = params[:blobs]&.map do |attrs|
|
||||||
|
ActiveStorage::Blob.find_signed(attrs[:signed_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
blobs || params[:files].map do |file|
|
||||||
|
ActiveStorage::Blob.create_and_upload!(io: file.open,
|
||||||
|
filename: file.original_filename,
|
||||||
|
content_type: file.content_type)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,21 +2,17 @@
|
|||||||
|
|
||||||
class EsignSettingsController < ApplicationController
|
class EsignSettingsController < ApplicationController
|
||||||
def create
|
def create
|
||||||
blobs =
|
|
||||||
params[:blob_signed_ids].map do |sid|
|
|
||||||
ActiveStorage::Blob.find_signed(sid)
|
|
||||||
end
|
|
||||||
|
|
||||||
pdfs =
|
pdfs =
|
||||||
blobs.map do |blob|
|
params[:files].map do |file|
|
||||||
HexaPDF::Document.new(io: StringIO.new(blob.download))
|
HexaPDF::Document.new(io: file.open)
|
||||||
end
|
end
|
||||||
|
|
||||||
certs = Accounts.load_signing_certs(current_account)
|
certs = Accounts.load_signing_certs(current_account)
|
||||||
|
|
||||||
trusted_certs = [certs[:cert], certs[:sub_ca], certs[:root_ca]]
|
trusted_certs = [certs[:cert], certs[:sub_ca], certs[:root_ca]]
|
||||||
|
|
||||||
render turbo_stream: turbo_stream.replace('result', partial: 'result', locals: { pdfs:, blobs:, trusted_certs: })
|
render turbo_stream: turbo_stream.replace('result', partial: 'result',
|
||||||
|
locals: { pdfs:, files: params[:files], trusted_certs: })
|
||||||
rescue HexaPDF::MalformedPDFError
|
rescue HexaPDF::MalformedPDFError
|
||||||
render turbo_stream: turbo_stream.replace('result', html: helpers.tag.div('Invalid PDF', id: 'result'))
|
render turbo_stream: turbo_stream.replace('result', html: helpers.tag.div('Invalid PDF', id: 'result'))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ window.customElements.define('template-builder', class extends HTMLElement {
|
|||||||
this.appElem = document.createElement('div')
|
this.appElem = document.createElement('div')
|
||||||
|
|
||||||
this.app = createApp(TemplateBuilder, {
|
this.app = createApp(TemplateBuilder, {
|
||||||
template: reactive(JSON.parse(this.dataset.template))
|
template: reactive(JSON.parse(this.dataset.template)),
|
||||||
|
isDirectUpload: this.dataset.isDirectUpload === 'true'
|
||||||
})
|
})
|
||||||
|
|
||||||
this.app.mount(this.appElem)
|
this.app.mount(this.appElem)
|
||||||
|
|||||||
@@ -9,28 +9,36 @@ export default actionable(targetable(class extends HTMLElement {
|
|||||||
]
|
]
|
||||||
|
|
||||||
connectedCallback () {
|
connectedCallback () {
|
||||||
import('@rails/activestorage')
|
if (this.dataset.isDirectUpload === 'true') {
|
||||||
|
import('@rails/activestorage')
|
||||||
|
}
|
||||||
|
|
||||||
this.addEventListener('drop', this.onDrop)
|
this.addEventListener('drop', this.onDrop)
|
||||||
|
|
||||||
this.addEventListener('dragover', (e) => e.preventDefault())
|
this.addEventListener('dragover', (e) => e.preventDefault())
|
||||||
|
|
||||||
|
document.addEventListener('turbo:submit-end', this.toggleLoading)
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnectedCallback () {
|
||||||
|
document.removeEventListener('turbo:submit-end', this.toggleLoading)
|
||||||
}
|
}
|
||||||
|
|
||||||
onDrop (e) {
|
onDrop (e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
|
this.input.files = e.dataTransfer.files
|
||||||
|
|
||||||
this.uploadFiles(e.dataTransfer.files)
|
this.uploadFiles(e.dataTransfer.files)
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelectFiles (e) {
|
onSelectFiles (e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
this.uploadFiles(this.input.files).then(() => {
|
this.uploadFiles(this.input.files)
|
||||||
this.input.value = ''
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleLoading () {
|
toggleLoading = () => {
|
||||||
this.loading.classList.toggle('hidden')
|
this.loading.classList.toggle('hidden')
|
||||||
this.icon.classList.toggle('hidden')
|
this.icon.classList.toggle('hidden')
|
||||||
this.classList.toggle('opacity-50')
|
this.classList.toggle('opacity-50')
|
||||||
@@ -39,50 +47,56 @@ export default actionable(targetable(class extends HTMLElement {
|
|||||||
async uploadFiles (files) {
|
async uploadFiles (files) {
|
||||||
this.toggleLoading()
|
this.toggleLoading()
|
||||||
|
|
||||||
const { DirectUpload } = await import('@rails/activestorage')
|
if (this.dataset.isDirectUpload === 'true') {
|
||||||
|
const { DirectUpload } = await import('@rails/activestorage')
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Array.from(files).map(async (file) => {
|
Array.from(files).map(async (file) => {
|
||||||
const upload = new DirectUpload(
|
const upload = new DirectUpload(
|
||||||
file,
|
file,
|
||||||
'/direct_uploads',
|
'/direct_uploads',
|
||||||
this.input
|
this.input
|
||||||
)
|
)
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
upload.create((error, blob) => {
|
upload.create((error, blob) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|
||||||
return reject(error)
|
return reject(error)
|
||||||
} else {
|
} else {
|
||||||
return resolve(blob)
|
return resolve(blob)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error)
|
||||||
})
|
})
|
||||||
}).catch((error) => {
|
|
||||||
console.error(error)
|
|
||||||
})
|
})
|
||||||
|
).then((blobs) => {
|
||||||
|
if (this.dataset.submitOnUpload) {
|
||||||
|
this.querySelectorAll('[name="blob_signed_ids[]"]').forEach((e) => e.remove())
|
||||||
|
}
|
||||||
|
|
||||||
|
blobs.forEach((blob) => {
|
||||||
|
const input = document.createElement('input')
|
||||||
|
|
||||||
|
input.type = 'hidden'
|
||||||
|
input.name = 'blob_signed_ids[]'
|
||||||
|
input.value = blob.signed_id
|
||||||
|
|
||||||
|
this.append(input)
|
||||||
|
})
|
||||||
|
|
||||||
|
if (this.dataset.submitOnUpload) {
|
||||||
|
this.closest('form').querySelector('button[type="submit"]').click()
|
||||||
|
}
|
||||||
|
}).finally(() => {
|
||||||
|
this.toggleLoading()
|
||||||
})
|
})
|
||||||
).then((blobs) => {
|
} else {
|
||||||
if (this.dataset.submitOnUpload) {
|
|
||||||
this.querySelectorAll('[name="blob_signed_ids[]"]').forEach((e) => e.remove())
|
|
||||||
}
|
|
||||||
|
|
||||||
blobs.forEach((blob) => {
|
|
||||||
const input = document.createElement('input')
|
|
||||||
|
|
||||||
input.type = 'hidden'
|
|
||||||
input.name = 'blob_signed_ids[]'
|
|
||||||
input.value = blob.signed_id
|
|
||||||
|
|
||||||
this.append(input)
|
|
||||||
})
|
|
||||||
|
|
||||||
if (this.dataset.submitOnUpload) {
|
if (this.dataset.submitOnUpload) {
|
||||||
this.closest('form').querySelector('button[type="submit"]').click()
|
this.closest('form').querySelector('button[type="submit"]').click()
|
||||||
}
|
}
|
||||||
}).finally(() => {
|
}
|
||||||
this.toggleLoading()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ window.customElements.define('submission-form', class extends HTMLElement {
|
|||||||
submitterUuid: this.dataset.submitterUuid,
|
submitterUuid: this.dataset.submitterUuid,
|
||||||
authenticityToken: this.dataset.authenticityToken,
|
authenticityToken: this.dataset.authenticityToken,
|
||||||
canSendEmail: this.dataset.canSendEmail === 'true',
|
canSendEmail: this.dataset.canSendEmail === 'true',
|
||||||
|
isDirectUpload: this.dataset.isDirectUpload === 'true',
|
||||||
values: reactive(JSON.parse(this.dataset.values)),
|
values: reactive(JSON.parse(this.dataset.values)),
|
||||||
attachments: reactive(JSON.parse(this.dataset.attachments)),
|
attachments: reactive(JSON.parse(this.dataset.attachments)),
|
||||||
fields: JSON.parse(this.dataset.fields)
|
fields: JSON.parse(this.dataset.fields)
|
||||||
|
|||||||
@@ -47,6 +47,8 @@
|
|||||||
<FileDropzone
|
<FileDropzone
|
||||||
:message="`Upload ${field.name || 'Attachments'}${field.required ? '' : ' (optional)'}`"
|
:message="`Upload ${field.name || 'Attachments'}${field.required ? '' : ' (optional)'}`"
|
||||||
:submitter-slug="submitterSlug"
|
:submitter-slug="submitterSlug"
|
||||||
|
:is-direct-upload="isDirectUpload"
|
||||||
|
:multiple="true"
|
||||||
@upload="onUpload"
|
@upload="onUpload"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -77,6 +79,11 @@ export default {
|
|||||||
required: false,
|
required: false,
|
||||||
default: () => ({})
|
default: () => ({})
|
||||||
},
|
},
|
||||||
|
isDirectUpload: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: Array,
|
type: Array,
|
||||||
required: false,
|
required: false,
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ export default {
|
|||||||
required: false,
|
required: false,
|
||||||
default: '*/*'
|
default: '*/*'
|
||||||
},
|
},
|
||||||
|
isDirectUpload: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
multiple: {
|
multiple: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
required: false,
|
required: false,
|
||||||
@@ -87,7 +92,9 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
import('@rails/activestorage')
|
if (this.isDirectUpload) {
|
||||||
|
import('@rails/activestorage')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onDropFiles (e) {
|
onDropFiles (e) {
|
||||||
@@ -105,50 +112,72 @@ export default {
|
|||||||
async uploadFiles (files) {
|
async uploadFiles (files) {
|
||||||
this.isLoading = true
|
this.isLoading = true
|
||||||
|
|
||||||
const { DirectUpload } = await import('@rails/activestorage')
|
if (this.isDirectUpload) {
|
||||||
|
const { DirectUpload } = await import('@rails/activestorage')
|
||||||
|
|
||||||
const blobs = await Promise.all(
|
const blobs = await Promise.all(
|
||||||
Array.from(files).map(async (file) => {
|
Array.from(files).map(async (file) => {
|
||||||
const upload = new DirectUpload(
|
const upload = new DirectUpload(
|
||||||
file,
|
file,
|
||||||
'/direct_uploads',
|
'/direct_uploads',
|
||||||
this.$refs.input
|
this.$refs.input
|
||||||
)
|
)
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
upload.create((error, blob) => {
|
upload.create((error, blob) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|
||||||
return reject(error)
|
return reject(error)
|
||||||
} else {
|
} else {
|
||||||
return resolve(blob)
|
return resolve(blob)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error)
|
||||||
})
|
})
|
||||||
}).catch((error) => {
|
|
||||||
console.error(error)
|
|
||||||
})
|
})
|
||||||
})
|
)
|
||||||
)
|
|
||||||
|
|
||||||
return await Promise.all(
|
return await Promise.all(
|
||||||
blobs.map((blob) => {
|
blobs.map((blob) => {
|
||||||
return fetch('/api/attachments', {
|
return fetch('/api/attachments', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name: 'attachments',
|
name: 'attachments',
|
||||||
blob_signed_id: blob.signed_id,
|
blob_signed_id: blob.signed_id,
|
||||||
submitter_slug: this.submitterSlug
|
submitter_slug: this.submitterSlug
|
||||||
}),
|
}),
|
||||||
headers: { 'Content-Type': 'application/json' }
|
headers: { 'Content-Type': 'application/json' }
|
||||||
}).then(resp => resp.json()).then((data) => {
|
}).then(resp => resp.json()).then((data) => {
|
||||||
return data
|
return data
|
||||||
})
|
})
|
||||||
})).then((result) => {
|
})).then((result) => {
|
||||||
this.$emit('upload', result)
|
this.$emit('upload', result)
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
this.isLoading = false
|
this.isLoading = false
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
return await Promise.all(
|
||||||
|
Array.from(files).map((file) => {
|
||||||
|
const formData = new FormData()
|
||||||
|
|
||||||
|
formData.append('file', file)
|
||||||
|
formData.append('submitter_slug', this.submitterSlug)
|
||||||
|
formData.append('name', 'attachments')
|
||||||
|
|
||||||
|
return fetch('/api/attachments', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
}).then(resp => resp.json()).then((data) => {
|
||||||
|
return data
|
||||||
|
})
|
||||||
|
})).then((result) => {
|
||||||
|
this.$emit('upload', result)
|
||||||
|
}).finally(() => {
|
||||||
|
this.isLoading = false
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,6 +201,7 @@
|
|||||||
v-else-if="currentField.type === 'image'"
|
v-else-if="currentField.type === 'image'"
|
||||||
v-model="values[currentField.uuid]"
|
v-model="values[currentField.uuid]"
|
||||||
:field="currentField"
|
:field="currentField"
|
||||||
|
:is-direct-upload="isDirectUpload"
|
||||||
:attachments-index="attachmentsIndex"
|
:attachments-index="attachmentsIndex"
|
||||||
:submitter-slug="submitterSlug"
|
:submitter-slug="submitterSlug"
|
||||||
@attached="[attachments.push($event), $refs.areas.scrollIntoField(currentField)]"
|
@attached="[attachments.push($event), $refs.areas.scrollIntoField(currentField)]"
|
||||||
@@ -210,6 +211,7 @@
|
|||||||
ref="currentStep"
|
ref="currentStep"
|
||||||
v-model="values[currentField.uuid]"
|
v-model="values[currentField.uuid]"
|
||||||
:field="currentField"
|
:field="currentField"
|
||||||
|
:is-direct-upload="isDirectUpload"
|
||||||
:attachments-index="attachmentsIndex"
|
:attachments-index="attachmentsIndex"
|
||||||
:submitter-slug="submitterSlug"
|
:submitter-slug="submitterSlug"
|
||||||
@attached="attachments.push($event)"
|
@attached="attachments.push($event)"
|
||||||
@@ -217,6 +219,7 @@
|
|||||||
<AttachmentStep
|
<AttachmentStep
|
||||||
v-else-if="currentField.type === 'file'"
|
v-else-if="currentField.type === 'file'"
|
||||||
v-model="values[currentField.uuid]"
|
v-model="values[currentField.uuid]"
|
||||||
|
:is-direct-upload="isDirectUpload"
|
||||||
:field="currentField"
|
:field="currentField"
|
||||||
:attachments-index="attachmentsIndex"
|
:attachments-index="attachmentsIndex"
|
||||||
:submitter-slug="submitterSlug"
|
:submitter-slug="submitterSlug"
|
||||||
@@ -315,6 +318,11 @@ export default {
|
|||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
isDirectUpload: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
values: {
|
values: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: false,
|
required: false,
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
:message="`Upload ${field.name || 'Image'}${field.required ? '' : ' (optional)'}`"
|
:message="`Upload ${field.name || 'Image'}${field.required ? '' : ' (optional)'}`"
|
||||||
:submitter-slug="submitterSlug"
|
:submitter-slug="submitterSlug"
|
||||||
:accept="'image/*'"
|
:accept="'image/*'"
|
||||||
|
:is-direct-upload="isDirectUpload"
|
||||||
@upload="onImageUpload"
|
@upload="onImageUpload"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -50,6 +51,11 @@ export default {
|
|||||||
type: Object,
|
type: Object,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
isDirectUpload: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
submitterSlug: {
|
submitterSlug: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ export default {
|
|||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
isDirectUpload: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
attachmentsIndex: {
|
attachmentsIndex: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: false,
|
required: false,
|
||||||
@@ -79,7 +84,10 @@ export default {
|
|||||||
this.$refs.canvas.height = this.$refs.canvas.parentNode.clientWidth / 3
|
this.$refs.canvas.height = this.$refs.canvas.parentNode.clientWidth / 3
|
||||||
})
|
})
|
||||||
|
|
||||||
import('@rails/activestorage')
|
if (this.isDirectUpload) {
|
||||||
|
import('@rails/activestorage')
|
||||||
|
}
|
||||||
|
|
||||||
const { default: SignaturePad } = await import('signature_pad')
|
const { default: SignaturePad } = await import('signature_pad')
|
||||||
|
|
||||||
this.pad = new SignaturePad(this.$refs.canvas)
|
this.pad = new SignaturePad(this.$refs.canvas)
|
||||||
@@ -102,31 +110,49 @@ export default {
|
|||||||
return Promise.resolve({})
|
return Promise.resolve({})
|
||||||
}
|
}
|
||||||
|
|
||||||
const { DirectUpload } = await import('@rails/activestorage')
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.$refs.canvas.toBlob((blob) => {
|
this.$refs.canvas.toBlob(async (blob) => {
|
||||||
const file = new File([blob], 'signature.png', { type: 'image/png' })
|
const file = new File([blob], 'signature.png', { type: 'image/png' })
|
||||||
|
|
||||||
new DirectUpload(
|
if (this.isDirectUpload) {
|
||||||
file,
|
const { DirectUpload } = await import('@rails/activestorage')
|
||||||
'/direct_uploads'
|
|
||||||
).create((_error, data) => {
|
new DirectUpload(
|
||||||
fetch('/api/attachments', {
|
file,
|
||||||
|
'/direct_uploads'
|
||||||
|
).create((_error, data) => {
|
||||||
|
fetch('/api/attachments', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
submitter_slug: this.submitterSlug,
|
||||||
|
blob_signed_id: data.signed_id,
|
||||||
|
name: 'attachments'
|
||||||
|
}),
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
}).then((resp) => resp.json()).then((attachment) => {
|
||||||
|
this.$emit('update:model-value', attachment.uuid)
|
||||||
|
this.$emit('attached', attachment)
|
||||||
|
|
||||||
|
return resolve(attachment)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const formData = new FormData()
|
||||||
|
|
||||||
|
formData.append('file', file)
|
||||||
|
formData.append('submitter_slug', this.submitterSlug)
|
||||||
|
formData.append('name', 'attachments')
|
||||||
|
|
||||||
|
return fetch('/api/attachments', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: formData
|
||||||
submitter_slug: this.submitterSlug,
|
|
||||||
blob_signed_id: data.signed_id,
|
|
||||||
name: 'attachments'
|
|
||||||
}),
|
|
||||||
headers: { 'Content-Type': 'application/json' }
|
|
||||||
}).then((resp) => resp.json()).then((attachment) => {
|
}).then((resp) => resp.json()).then((attachment) => {
|
||||||
this.$emit('update:model-value', attachment.uuid)
|
this.$emit('update:model-value', attachment.uuid)
|
||||||
this.$emit('attached', attachment)
|
this.$emit('attached', attachment)
|
||||||
|
|
||||||
return resolve(attachment)
|
return resolve(attachment)
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
}, 'image/png')
|
}, 'image/png')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
<Upload
|
<Upload
|
||||||
v-if="sortedDocuments.length"
|
v-if="sortedDocuments.length"
|
||||||
:template-id="template.id"
|
:template-id="template.id"
|
||||||
|
:is-direct-upload="isDirectUpload"
|
||||||
@success="updateFromUpload"
|
@success="updateFromUpload"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -83,12 +84,12 @@
|
|||||||
ref="documents"
|
ref="documents"
|
||||||
class="pr-3.5 pl-0.5"
|
class="pr-3.5 pl-0.5"
|
||||||
>
|
>
|
||||||
<template v-if="!sortedDocuments.length">
|
<Dropzone
|
||||||
<Dropzone
|
v-if="!sortedDocuments.length"
|
||||||
:template-id="template.id"
|
:template-id="template.id"
|
||||||
@success="updateFromUpload"
|
:is-direct-upload="isDirectUpload"
|
||||||
/>
|
@success="updateFromUpload"
|
||||||
</template>
|
/>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<Document
|
<Document
|
||||||
v-for="document in sortedDocuments"
|
v-for="document in sortedDocuments"
|
||||||
@@ -194,6 +195,11 @@ export default {
|
|||||||
template: {
|
template: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
isDirectUpload: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
|
|||||||
@@ -33,15 +33,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<input
|
<form
|
||||||
:id="inputId"
|
ref="form"
|
||||||
ref="input"
|
|
||||||
type="file"
|
|
||||||
class="hidden"
|
class="hidden"
|
||||||
accept="image/*, application/pdf"
|
|
||||||
multiple
|
|
||||||
@change="upload"
|
|
||||||
>
|
>
|
||||||
|
<input
|
||||||
|
:id="inputId"
|
||||||
|
ref="input"
|
||||||
|
type="file"
|
||||||
|
name="files[]"
|
||||||
|
accept="image/*, application/pdf"
|
||||||
|
multiple
|
||||||
|
@change="upload"
|
||||||
|
>
|
||||||
|
</form>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -60,6 +65,11 @@ export default {
|
|||||||
templateId: {
|
templateId: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
isDirectUpload: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['success'],
|
emits: ['success'],
|
||||||
|
|||||||
@@ -24,15 +24,20 @@
|
|||||||
Add Document
|
Add Document
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
<input
|
<form
|
||||||
:id="inputId"
|
ref="form"
|
||||||
ref="input"
|
|
||||||
type="file"
|
|
||||||
class="hidden"
|
class="hidden"
|
||||||
accept="image/*, application/pdf"
|
|
||||||
multiple
|
|
||||||
@change="upload"
|
|
||||||
>
|
>
|
||||||
|
<input
|
||||||
|
:id="inputId"
|
||||||
|
ref="input"
|
||||||
|
name="files[]"
|
||||||
|
type="file"
|
||||||
|
accept="image/*, application/pdf"
|
||||||
|
multiple
|
||||||
|
@change="upload"
|
||||||
|
>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -49,6 +54,11 @@ export default {
|
|||||||
templateId: {
|
templateId: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
isDirectUpload: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['success'],
|
emits: ['success'],
|
||||||
@@ -64,52 +74,66 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
import('@rails/activestorage')
|
if (this.isDirectUpload) {
|
||||||
|
import('@rails/activestorage')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async upload () {
|
async upload () {
|
||||||
this.isLoading = true
|
this.isLoading = true
|
||||||
|
|
||||||
const { DirectUpload } = await import('@rails/activestorage')
|
if (this.isDirectUpload) {
|
||||||
|
const { DirectUpload } = await import('@rails/activestorage')
|
||||||
|
|
||||||
const blobs = await Promise.all(
|
const blobs = await Promise.all(
|
||||||
Array.from(this.$refs.input.files).map(async (file) => {
|
Array.from(this.$refs.input.files).map(async (file) => {
|
||||||
const upload = new DirectUpload(
|
const upload = new DirectUpload(
|
||||||
file,
|
file,
|
||||||
'/direct_uploads',
|
'/direct_uploads',
|
||||||
this.$refs.input
|
this.$refs.input
|
||||||
)
|
)
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
upload.create((error, blob) => {
|
upload.create((error, blob) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|
||||||
return reject(error)
|
return reject(error)
|
||||||
} else {
|
} else {
|
||||||
return resolve(blob)
|
return resolve(blob)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error)
|
||||||
})
|
})
|
||||||
}).catch((error) => {
|
|
||||||
console.error(error)
|
|
||||||
})
|
})
|
||||||
|
).finally(() => {
|
||||||
|
this.isLoading = false
|
||||||
})
|
})
|
||||||
).finally(() => {
|
|
||||||
this.isLoading = false
|
|
||||||
})
|
|
||||||
|
|
||||||
this.isProcessing = true
|
this.isProcessing = true
|
||||||
|
|
||||||
fetch(`/api/templates/${this.templateId}/documents`, {
|
fetch(`/api/templates/${this.templateId}/documents`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ blobs }),
|
body: JSON.stringify({ blobs }),
|
||||||
headers: { 'Content-Type': 'application/json' }
|
headers: { 'Content-Type': 'application/json' }
|
||||||
}).then(resp => resp.json()).then((data) => {
|
}).then(resp => resp.json()).then((data) => {
|
||||||
this.$emit('success', data)
|
this.$emit('success', data)
|
||||||
this.$refs.input.value = ''
|
this.$refs.input.value = ''
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
this.isProcessing = false
|
this.isProcessing = false
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
fetch(`/api/templates/${this.templateId}/documents`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: new FormData(this.$refs.form)
|
||||||
|
}).then(resp => resp.json()).then((data) => {
|
||||||
|
this.$emit('success', data)
|
||||||
|
this.$refs.input.value = ''
|
||||||
|
}).finally(() => {
|
||||||
|
this.isLoading = false
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<div id="result">
|
<div id="result">
|
||||||
<% blobs.zip(pdfs).each do |blob, pdf| %>
|
<% files.zip(pdfs).each do |file, pdf| %>
|
||||||
<div class="mb-4 border border-base-300 rounded-md py-2 px-3">
|
<div class="mb-4 border border-base-300 rounded-md py-2 px-3">
|
||||||
<% if pdf.signatures.to_a.size == 0 %>
|
<% if pdf.signatures.to_a.size == 0 %>
|
||||||
<div class="text-sm">
|
<div class="text-sm">
|
||||||
<%= blob.filename %>
|
<%= file.original_filename %>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-xl font-medium">
|
<p class="text-xl font-medium">
|
||||||
There are no signatures...
|
There are no signatures...
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
<% else %>
|
<% else %>
|
||||||
<div class="flex items-center space-x-1 border-b border-dashed border-base-300 pb-2">
|
<div class="flex items-center space-x-1 border-b border-dashed border-base-300 pb-2">
|
||||||
<%= svg_icon('file_text', class: 'w-5 h-5 inline') %>
|
<%= svg_icon('file_text', class: 'w-5 h-5 inline') %>
|
||||||
<span><%= blob.filename %> - <%= pluralize(pdf.signatures.to_a.size, 'Signature') %></span>
|
<span><%= file.original_filename %> - <%= pluralize(pdf.signatures.to_a.size, 'Signature') %></span>
|
||||||
</div>
|
</div>
|
||||||
<% pdf.signatures.to_a.each do |signature| %>
|
<% pdf.signatures.to_a.each do |signature| %>
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
|
|||||||
@@ -7,14 +7,14 @@
|
|||||||
Upload signed PDF file to validate its signature:
|
Upload signed PDF file to validate its signature:
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<%= form_for '', url: settings_esign_index_path, method: :post do |f| %>
|
<%= form_for '', url: settings_esign_index_path, method: :post, html: { enctype: 'multipart/form-data' } do |f| %>
|
||||||
<%= f.button type: 'submit', class: 'flex' do %>
|
<%= f.button type: 'submit', class: 'flex' do %>
|
||||||
<div class="disabled mb-3">
|
<div class="disabled mb-3">
|
||||||
<%= svg_icon('loader', class: 'w-5 h-5 animate-spin inline') %>
|
<%= svg_icon('loader', class: 'w-5 h-5 animate-spin inline') %>
|
||||||
Analyzing...
|
Analyzing...
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<file-dropzone data-name="verify_attachments" data-submit-on-upload="true" class="w-full">
|
<file-dropzone data-is-direct-upload="false" data-name="verify_attachments" data-submit-on-upload="true" class="w-full">
|
||||||
<label for="file" class="w-full block h-32 relative bg-base-200 hover:bg-base-200/70 rounded-md border border-base-content border-dashed">
|
<label for="file" class="w-full block h-32 relative bg-base-200 hover:bg-base-200/70 rounded-md border border-base-content border-dashed">
|
||||||
<div class="absolute top-0 right-0 left-0 bottom-0 flex items-center justify-center">
|
<div class="absolute top-0 right-0 left-0 bottom-0 flex items-center justify-center">
|
||||||
<div class="flex flex-col items-center">
|
<div class="flex flex-col items-center">
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
<span class="font-medium">Click to upload</span> or drag and drop
|
<span class="font-medium">Click to upload</span> or drag and drop
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<input id="file" class="hidden" data-action="change:file-dropzone#onSelectFiles" data-target="file-dropzone.input" type="file" accept="application/pdf" multiple>
|
<input id="file" name="files[]" class="hidden" data-action="change:file-dropzone#onSelectFiles" data-target="file-dropzone.input" type="file" accept="application/pdf" multiple>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</file-dropzone>
|
</file-dropzone>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
<div class="mx-auto" style="max-width: 1000px">
|
<div class="mx-auto" style="max-width: 1000px">
|
||||||
<div class="relative md:mx-32">
|
<div class="relative md:mx-32">
|
||||||
<div id="form_container" class="shadow-md bg-base-100 absolute bottom-0 md:bottom-4 w-full border border-base-200 border p-4 rounded">
|
<div id="form_container" class="shadow-md bg-base-100 absolute bottom-0 md:bottom-4 w-full border border-base-200 border p-4 rounded">
|
||||||
<submission-form data-submitter-uuid="<%= @submitter.uuid %>" data-submitter-slug="<%= @submitter.slug %>" data-can-send-email="<%= Accounts.can_send_emails?(Struct.new(:id).new(@submitter.submission.template.account_id)) %>" data-attachments="<%= attachments_index.values.select { |e| e.record_id == @submitter.id }.to_json(only: %i[uuid], methods: %i[url filename content_type]) %>" data-fields="<%= @submitter.submission.template.fields.select { |f| f['submitter_uuid'] == @submitter.uuid }.to_json %>" data-values="<%= @submitter.values.to_json %>" data-authenticity-token="<%= form_authenticity_token %>"></submission-form>
|
<submission-form data-is-direct-upload="<%= Docuseal.active_storage_public? %>" data-submitter-uuid="<%= @submitter.uuid %>" data-submitter-slug="<%= @submitter.slug %>" data-can-send-email="<%= Accounts.can_send_emails?(Struct.new(:id).new(@submitter.submission.template.account_id)) %>" data-attachments="<%= attachments_index.values.select { |e| e.record_id == @submitter.id }.to_json(only: %i[uuid], methods: %i[url filename content_type]) %>" data-fields="<%= @submitter.submission.template.fields.select { |f| f['submitter_uuid'] == @submitter.uuid }.to_json %>" data-values="<%= @submitter.values.to_json %>" data-authenticity-token="<%= form_authenticity_token %>"></submission-form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
<template-builder data-template="<%= @template.to_json(include: { documents: { include: { preview_images: { methods: %i[url metadata filename] } } } }) %>"></template-builder>
|
<template-builder data-is-direct-upload="<%= Docuseal.active_storage_public? %>" data-template="<%= @template.to_json(include: { documents: { include: { preview_images: { methods: %i[url metadata filename] } } } }) %>"></template-builder>
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ Rails.application.configure do
|
|||||||
|
|
||||||
# Do not eager load code on boot.
|
# Do not eager load code on boot.
|
||||||
config.eager_load = false
|
config.eager_load = false
|
||||||
|
config.hosts = nil
|
||||||
|
|
||||||
# Show full error reports.
|
# Show full error reports.
|
||||||
config.consider_all_requests_local = true
|
config.consider_all_requests_local = true
|
||||||
@@ -45,7 +46,8 @@ Rails.application.configure do
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Store uploaded files on the local file system (see config/storage.yml for options).
|
# Store uploaded files on the local file system (see config/storage.yml for options).
|
||||||
config.active_storage.service = :local
|
config.active_storage.service = :disk
|
||||||
|
config.active_storage.resolve_model_to_route = :rails_storage_proxy
|
||||||
|
|
||||||
# Don't care if the mailer can't send.
|
# Don't care if the mailer can't send.
|
||||||
config.action_mailer.raise_delivery_errors = true
|
config.action_mailer.raise_delivery_errors = true
|
||||||
|
|||||||
@@ -46,9 +46,11 @@ Rails.application.configure do
|
|||||||
elsif ENV['AZURE_CONTAINER'].present?
|
elsif ENV['AZURE_CONTAINER'].present?
|
||||||
:azure
|
:azure
|
||||||
else
|
else
|
||||||
:local
|
:disk
|
||||||
end
|
end
|
||||||
|
|
||||||
|
config.active_storage.resolve_model_to_route = :rails_storage_proxy if ENV['ACTIVE_STORAGE_PUBLIC'] != 'true'
|
||||||
|
|
||||||
# Mount Action Cable outside main process or domain.
|
# Mount Action Cable outside main process or domain.
|
||||||
# config.action_cable.mount_path = nil
|
# config.action_cable.mount_path = nil
|
||||||
# config.action_cable.url = "wss://example.com/cable"
|
# config.action_cable.url = "wss://example.com/cable"
|
||||||
|
|||||||
+3
-8
@@ -1,8 +1,3 @@
|
|||||||
local:
|
|
||||||
service: Disk
|
|
||||||
root: <%= ENV['WORKDIR'] || '.' %>/attachments
|
|
||||||
public: true
|
|
||||||
|
|
||||||
disk:
|
disk:
|
||||||
service: Disk
|
service: Disk
|
||||||
root: <%= ENV['WORKDIR'] || '.' %>/attachments
|
root: <%= ENV['WORKDIR'] || '.' %>/attachments
|
||||||
@@ -14,7 +9,7 @@ aws_s3:
|
|||||||
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
|
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
|
||||||
region: <%= ENV['AWS_REGION'] || 'us-east-1' %>
|
region: <%= ENV['AWS_REGION'] || 'us-east-1' %>
|
||||||
bucket: <%= ENV['S3_ATTACHMENTS_BUCKET'] %>
|
bucket: <%= ENV['S3_ATTACHMENTS_BUCKET'] %>
|
||||||
public: true
|
public: <%= ENV['ACTIVE_STORAGE_PUBLIC'] == 'true' %>
|
||||||
upload:
|
upload:
|
||||||
cache_control: 'public, max-age=31536000'
|
cache_control: 'public, max-age=31536000'
|
||||||
|
|
||||||
@@ -23,7 +18,7 @@ google:
|
|||||||
credentials: <%= JSON.parse(ENV['GCS_CREDENTIALS'] || '{}') %>
|
credentials: <%= JSON.parse(ENV['GCS_CREDENTIALS'] || '{}') %>
|
||||||
project: <%= ENV['GCS_PROJECT'] %>
|
project: <%= ENV['GCS_PROJECT'] %>
|
||||||
bucket: <%= ENV['GCS_BUCKET'] %>
|
bucket: <%= ENV['GCS_BUCKET'] %>
|
||||||
public: true
|
public: <%= ENV['ACTIVE_STORAGE_PUBLIC'] == 'true' %>
|
||||||
cache_control: "public, max-age=31536000"
|
cache_control: "public, max-age=31536000"
|
||||||
|
|
||||||
azure:
|
azure:
|
||||||
@@ -31,4 +26,4 @@ azure:
|
|||||||
storage_account_name: <%= ENV['AZURE_STORAGE_ACCOUNT_NAME'] %>
|
storage_account_name: <%= ENV['AZURE_STORAGE_ACCOUNT_NAME'] %>
|
||||||
storage_access_key: <%= ENV['AZURE_STORAGE_ACCESS_KEY'] %>
|
storage_access_key: <%= ENV['AZURE_STORAGE_ACCESS_KEY'] %>
|
||||||
container: <%= ENV['AZURE_CONTAINER'] %>
|
container: <%= ENV['AZURE_CONTAINER'] %>
|
||||||
public: true
|
public: <%= ENV['ACTIVE_STORAGE_PUBLIC'] == 'true' %>
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ module Docuseal
|
|||||||
ENV['MULTITENANT'] == 'true'
|
ENV['MULTITENANT'] == 'true'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def active_storage_public?
|
||||||
|
ENV['ACTIVE_STORAGE_PUBLIC'] == 'true'
|
||||||
|
end
|
||||||
|
|
||||||
def default_url_options
|
def default_url_options
|
||||||
return DEFAULT_URL_OPTIONS if multitenant?
|
return DEFAULT_URL_OPTIONS if multitenant?
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,8 @@ module Submissions
|
|||||||
(area['x'] * width) + (area['w'] * width) + TEXT_LEFT_MARGIN,
|
(area['x'] * width) + (area['w'] * width) + TEXT_LEFT_MARGIN,
|
||||||
height - (area['y'] * height) - lines[..next_index].sum(&:height) + height_diff
|
height - (area['y'] * height) - lines[..next_index].sum(&:height) + height_diff
|
||||||
],
|
],
|
||||||
A: { Type: :Action, S: :URI, URI: attachment.url }
|
A: { Type: :Action, S: :URI,
|
||||||
|
URI: h.rails_blob_url(attachment, **Docuseal.default_url_options) }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -260,5 +261,9 @@ module Submissions
|
|||||||
.write_to_buffer('.png')
|
.write_to_buffer('.png')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def h
|
||||||
|
Rails.application.routes.url_helpers
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user