diff --git a/app/controllers/api/attachments_controller.rb b/app/controllers/api/attachments_controller.rb index 6f82da4e..e93dc53c 100644 --- a/app/controllers/api/attachments_controller.rb +++ b/app/controllers/api/attachments_controller.rb @@ -7,7 +7,7 @@ module Api def create record = if params[:template_slug].present? - Template.find_by(slug: params[:template_slug]) + Template.find_by!(slug: params[:template_slug]) else Submitter.find_by!(slug: params[:submitter_slug]) end diff --git a/app/controllers/api/templates_documents_controller.rb b/app/controllers/api/templates_documents_controller.rb index 196eeaaf..16dbf20a 100644 --- a/app/controllers/api/templates_documents_controller.rb +++ b/app/controllers/api/templates_documents_controller.rb @@ -26,7 +26,7 @@ module Api def del_image template = Template.find(params[:template_id]) - document = template.documents.find(params[:documentId]) + document = template.documents.find(params[:document_id]) img_attachment_id = params[:attachment_id] page_number = document.preview_images.find_index { |pic| pic.id == img_attachment_id } if page_number diff --git a/app/javascript/submission_form/form.vue b/app/javascript/submission_form/form.vue index ca4d91c7..21222993 100644 --- a/app/javascript/submission_form/form.vue +++ b/app/javascript/submission_form/form.vue @@ -733,7 +733,7 @@ export default { stepPromise().then(async () => { const emptyRequiredField = this.stepFields.find((fields, index) => { - if (['redact', 'my_text', 'my_signature', 'my_initials', 'my_date', 'my_check'].includes(fields[0].type)) { + if (['redact', 'my_text', 'my_signature', 'my_initials', 'my_date', 'my_check'].includes(fields[0]?.type)) { fields[0].required = 'false' return false } else { diff --git a/app/javascript/template_builder/builder.vue b/app/javascript/template_builder/builder.vue index 7d85ef78..41a35d15 100644 --- a/app/javascript/template_builder/builder.vue +++ b/app/javascript/template_builder/builder.vue @@ -564,7 +564,7 @@ export default { } }, scrollIntoDocument (item, page) { - const documentRef = this.documentRefs.find((e) => e.document.uuid === item.attachment_uuid) + const documentRef = this.documentRefs.find((e) => e.document?.uuid === item.attachment_uuid) documentRef.scrollIntoDocument(page) }, onKeyUp (e) { @@ -942,7 +942,7 @@ export default { body: JSON.stringify({ template: this.template.id, attachment_id: imageId, - documentId + document_id: documentId }) }) .then((response) => { diff --git a/app/javascript/template_builder/document.vue b/app/javascript/template_builder/document.vue index bc9fdcd7..b189f985 100644 --- a/app/javascript/template_builder/document.vue +++ b/app/javascript/template_builder/document.vue @@ -111,7 +111,7 @@ export default { this.pageRefs[area.page].areaRefs.find((e) => e.area === area).$el.scrollIntoView({ behavior: 'smooth', block: 'center' }) }, scrollIntoDocument (page) { - const ref = this.pageRefs.find((e) => e.image.uuid === page.uuid) + const ref = this.pageRefs.find((e) => e.image?.uuid === page.uuid) ref.$el.scrollIntoView({ behavior: 'smooth', block: 'start' }) }, setPageRefs (el) { diff --git a/app/javascript/template_builder/field_submitter.vue b/app/javascript/template_builder/field_submitter.vue index e743065c..3611cf47 100644 --- a/app/javascript/template_builder/field_submitter.vue +++ b/app/javascript/template_builder/field_submitter.vue @@ -57,7 +57,7 @@ -
  • +
  • - Add {{ names[submitters.length] }} + Add {{ names[submitters?.length] }}
  • @@ -157,7 +157,7 @@ -
  • +
  • - Add {{ names[submitters.length] }} + Add {{ names[submitters?.length] }}
  • @@ -288,13 +288,13 @@ export default { if (window.confirm('Are you sure?')) { this.$emit('remove', submitter) } - if (this.submitters.length === 1) { + if (this.submitters?.length === 1) { this.$emit('add-prefills', this.submitters[0].name) } }, addSubmitter () { const newSubmitter = { - name: this.names[this.submitters.length], + name: this.names[this.submitters?.length], uuid: v4() } diff --git a/app/javascript/template_builder/my_signature.vue b/app/javascript/template_builder/my_signature.vue index 361906f1..87cfe7af 100644 --- a/app/javascript/template_builder/my_signature.vue +++ b/app/javascript/template_builder/my_signature.vue @@ -86,7 +86,7 @@ > { if (this.$refs.canvas) { - this.$refs.canvas.width = this.$refs.canvas.parentNode.clientWidth - this.$refs.canvas.height = this.$refs.canvas.parentNode.clientWidth / 3 + this.$refs.canvas.width = this.$refs.canvas?.parentNode?.clientWidth + this.$refs.canvas.height = this.$refs.canvas?.parentNode?.clientWidth / 3 } }) diff --git a/lib/submissions/generate_result_attachments.rb b/lib/submissions/generate_result_attachments.rb index 1ef366bd..292451e0 100644 --- a/lib/submissions/generate_result_attachments.rb +++ b/lib/submissions/generate_result_attachments.rb @@ -59,9 +59,8 @@ module Submissions layouter = HexaPDF::Layout::TextLayouter.new(valign: :center, font: pdf.fonts.add(FONT_NAME), font_size:) - value = submitter.values[field['uuid']] || template.values[field['uuid']] - - if !field['type']=='redact' + if !field['type'].in?(%w[redact my_check]) + value = submitter.values[field['uuid']] || template.values[field['uuid']] next if Array.wrap(value).compact_blank.blank? end diff --git a/lib/templates/process_document.rb b/lib/templates/process_document.rb index 94219fa9..bb497a95 100644 --- a/lib/templates/process_document.rb +++ b/lib/templates/process_document.rb @@ -219,31 +219,6 @@ module Templates ensure File.delete(temp_file_path) if File.exist?(temp_file_path) end - - # def generate_blank_image - # # here height and width should be equal to height and width from existing pdf pages - # height = 2000 - # width = MAX_WIDTH - # Vips::Image.new_from_array([[255]* width] * height, 255) - # end - - # # def create_blob_from_image(image, attachment) - # def create_image_blob(image, attachment) - # begin - # previews_count = attachment.preview_images.count - # ActiveStorage::Attachment.create!( - # blob: ActiveStorage::Blob.create_and_upload!( - # io: StringIO.new(image.write_to_buffer(FORMAT, Q: Q, interlace: true)), - # filename: "#{previews_count}#{FORMAT}", - # metadata: { analyzed: true, identified: true, width: image.width, height: image.height } - # ), - # name: ATTACHMENT_NAME, - # record: attachment - # ) - # rescue => e - # Rails.logger.error("Error creating blob from image: #{e.message}") - # end - # end end end