process acro form fields
This commit is contained in:
committed by
Pete Matsyburka
parent
320fe02e35
commit
749043dfbb
@@ -10,7 +10,7 @@ class TemplateDocumentsController < ApplicationController
|
||||
|
||||
old_fields_hash = @template.fields.hash
|
||||
|
||||
documents = Templates::CreateAttachments.call(@template, params)
|
||||
documents = Templates::CreateAttachments.call(@template, params, extract_fields: true)
|
||||
|
||||
schema = documents.map do |doc|
|
||||
{ attachment_uuid: doc.uuid, name: doc.filename.base }
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TemplatesDebugController < ApplicationController
|
||||
load_and_authorize_resource :template
|
||||
|
||||
def show
|
||||
attachment = @template.documents.first
|
||||
|
||||
pdf = HexaPDF::Document.new(io: StringIO.new(attachment.download))
|
||||
|
||||
fields = Templates::FindAcroFields.call(pdf, attachment)
|
||||
|
||||
attachment.metadata['pdf'] ||= {}
|
||||
attachment.metadata['pdf']['fields'] = fields
|
||||
|
||||
@template.update!(fields: Templates::ProcessDocument.normalize_attachment_fields(@template, [attachment]))
|
||||
|
||||
ActiveRecord::Associations::Preloader.new(
|
||||
records: [@template],
|
||||
associations: [schema_documents: { preview_images_attachments: :blob }]
|
||||
).call
|
||||
|
||||
@template_data =
|
||||
@template.as_json.merge(
|
||||
documents: @template.schema_documents.as_json(
|
||||
methods: %i[metadata signed_uuid],
|
||||
include: { preview_images: { methods: %i[url metadata filename] } }
|
||||
)
|
||||
).to_json
|
||||
|
||||
render 'templates/edit', layout: 'plain'
|
||||
end
|
||||
end
|
||||
@@ -12,11 +12,14 @@ class TemplatesUploadsController < ApplicationController
|
||||
|
||||
save_template!(@template, url_params)
|
||||
|
||||
documents = Templates::CreateAttachments.call(@template, url_params || params)
|
||||
|
||||
documents = Templates::CreateAttachments.call(@template, url_params || params, extract_fields: true)
|
||||
schema = documents.map { |doc| { attachment_uuid: doc.uuid, name: doc.filename.base } }
|
||||
|
||||
@template.update!(schema:)
|
||||
fields = Templates::ProcessDocument.normalize_attachment_fields(@template, documents)
|
||||
|
||||
schema.each { |item| item['pending_fields'] = true } if fields.present?
|
||||
|
||||
@template.update!(schema:, fields:)
|
||||
|
||||
SendTemplateCreatedWebhookRequestJob.perform_async('template_id' => @template.id)
|
||||
|
||||
|
||||
@@ -164,16 +164,16 @@
|
||||
<span
|
||||
v-if="field"
|
||||
class="flex justify-center items-center space-x-1 h-full"
|
||||
:class="{'w-full h-full': field.type == 'checkbox'}"
|
||||
:class="{ 'w-full h-full': ['cells', 'checkbox'].includes(field.type) }"
|
||||
>
|
||||
<div
|
||||
v-if="isDefaultValuePresent || isContenteditable"
|
||||
:class="{ 'w-full h-full': field.type == 'checkbox', 'text-[1.5vw] lg:text-base': !textOverflowChars, 'text-[1.0vw] lg:text-xs': textOverflowChars }"
|
||||
:class="{ 'w-full h-full': ['cells', 'checkbox'].includes(field.type), 'text-[1.5vw] lg:text-base': !textOverflowChars, 'text-[1.0vw] lg:text-xs': textOverflowChars }"
|
||||
>
|
||||
<div
|
||||
ref="textContainer"
|
||||
class="flex items-center px-0.5"
|
||||
:class="{'w-full h-full': field.type == 'checkbox'}"
|
||||
:class="{ 'w-full h-full': ['cells', 'checkbox'].includes(field.type) }"
|
||||
>
|
||||
<IconCheck
|
||||
v-if="field.type == 'checkbox'"
|
||||
@@ -189,6 +189,19 @@
|
||||
>
|
||||
{{ t('signing_date') }}
|
||||
</span>
|
||||
<div
|
||||
v-else-if="field.type === 'cells' && field.default_value"
|
||||
class="w-full flex items-center"
|
||||
>
|
||||
<div
|
||||
v-for="(char, index) in field.default_value"
|
||||
:key="index"
|
||||
class="text-center flex-none"
|
||||
:style="{ width: (area.cell_w / area.w * 100) + '%' }"
|
||||
>
|
||||
{{ char }}
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
v-else
|
||||
ref="defaultValue"
|
||||
|
||||
@@ -3,6 +3,31 @@
|
||||
style="max-width: 1600px"
|
||||
class="mx-auto pl-3 md:pl-4 h-full"
|
||||
>
|
||||
<div
|
||||
v-if="pendingFieldAttachmentUuids.length"
|
||||
class="top-1.5 sticky h-0 z-20 max-w-2xl mx-auto"
|
||||
>
|
||||
<div class="alert border-base-300 py-2 px-2.5 rounded-xl">
|
||||
<IconInfoCircle
|
||||
class="stroke-info shrink-0 w-6 h-6"
|
||||
/>
|
||||
<span>{{ t('uploaded_pdf_contains_form_fields_keep_or_remove_them') }}</span>
|
||||
<div>
|
||||
<button
|
||||
class="btn btn-sm"
|
||||
@click.prevent="removePendingFields"
|
||||
>
|
||||
{{ t('remove') }}
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-sm btn-neutral text-white"
|
||||
@click.prevent="save"
|
||||
>
|
||||
{{ t('keep') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="$slots.buttons || withTitle"
|
||||
id="title_container"
|
||||
@@ -296,7 +321,7 @@ import Contenteditable from './contenteditable'
|
||||
import DocumentPreview from './preview'
|
||||
import DocumentControls from './controls'
|
||||
import MobileFields from './mobile_fields'
|
||||
import { IconUsersPlus, IconDeviceFloppy, IconWritingSign, IconInnerShadowTop } from '@tabler/icons-vue'
|
||||
import { IconUsersPlus, IconDeviceFloppy, IconWritingSign, IconInnerShadowTop, IconInfoCircle } from '@tabler/icons-vue'
|
||||
import { v4 } from 'uuid'
|
||||
import { ref, computed } from 'vue'
|
||||
import { en as i18nEn } from './i18n'
|
||||
@@ -307,6 +332,7 @@ export default {
|
||||
Upload,
|
||||
Document,
|
||||
Fields,
|
||||
IconInfoCircle,
|
||||
MobileDrawField,
|
||||
IconWritingSign,
|
||||
MobileFields,
|
||||
@@ -512,6 +538,7 @@ export default {
|
||||
isSaving: false,
|
||||
selectedSubmitter: null,
|
||||
showDrawField: false,
|
||||
pendingFieldAttachmentUuids: [],
|
||||
drawField: null,
|
||||
copiedArea: null,
|
||||
drawFieldType: null,
|
||||
@@ -594,6 +621,12 @@ export default {
|
||||
document.querySelector('form[action="/auth/stripe_connect"]')?.closest('.dropdown')?.querySelector('label')?.focus()
|
||||
}
|
||||
})
|
||||
|
||||
this.template.schema.forEach((item) => {
|
||||
if (item.pending_fields) {
|
||||
this.pendingFieldAttachmentUuids.push(item.attachment_uuid)
|
||||
}
|
||||
})
|
||||
},
|
||||
unmounted () {
|
||||
document.removeEventListener('keyup', this.onKeyUp)
|
||||
@@ -608,6 +641,13 @@ export default {
|
||||
t (key) {
|
||||
return this.i18n[key] || i18nEn[key] || key
|
||||
},
|
||||
removePendingFields () {
|
||||
this.template.fields = this.template.fields.filter((f) => {
|
||||
return this.template.schema.find((item) => item.attachment_uuid === f.attachment_uuid && item.pending_fields)
|
||||
})
|
||||
|
||||
this.save()
|
||||
},
|
||||
addField (type, area = null) {
|
||||
const field = {
|
||||
name: '',
|
||||
@@ -1066,6 +1106,18 @@ export default {
|
||||
}
|
||||
|
||||
this.save()
|
||||
|
||||
data.documents.forEach((attachment) => {
|
||||
if (attachment.metadata?.pdf?.fields?.length) {
|
||||
this.pendingFieldAttachmentUuids.push(attachment.uuid)
|
||||
|
||||
attachment.metadata.pdf.fields.forEach((field) => {
|
||||
field.submitter_uuid = this.selectedSubmitter.uuid
|
||||
|
||||
this.template.fields.push(field)
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
updateName (value) {
|
||||
this.template.name = value
|
||||
@@ -1232,6 +1284,8 @@ export default {
|
||||
})
|
||||
},
|
||||
save ({ force } = { force: false }) {
|
||||
this.pendingFieldAttachmentUuids = []
|
||||
|
||||
if (this.onChange) {
|
||||
this.onChange(this.template)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ const en = {
|
||||
clear: 'Clear',
|
||||
align: 'Align',
|
||||
add_all_required_fields_to_continue: 'Add all required fields to continue',
|
||||
uploaded_pdf_contains_form_fields_keep_or_remove_them: 'Uploaded PDF contains form fields. Keep or remove them?',
|
||||
keep: 'Keep',
|
||||
left: 'Left',
|
||||
validation: 'Validation',
|
||||
right: 'Right',
|
||||
|
||||
Reference in New Issue
Block a user