From fece0825f8c3159c69bdefc9b1e8e2686fdca474 Mon Sep 17 00:00:00 2001 From: iozeey Date: Wed, 13 Dec 2023 18:52:23 +0500 Subject: [PATCH] Show prefill date in pdf and view --- app/javascript/submission_form/area.vue | 19 ++++--------------- app/javascript/submission_form/form.vue | 4 ++-- app/javascript/template_builder/area.vue | 6 +++--- app/javascript/template_builder/builder.vue | 4 ++-- app/javascript/template_builder/field.vue | 2 +- app/javascript/template_builder/fields.vue | 2 +- app/views/submissions/_value.html.erb | 4 ++++ app/views/submissions/show.html.erb | 2 +- .../generate_result_attachments.rb | 4 ++-- 9 files changed, 20 insertions(+), 27 deletions(-) diff --git a/app/javascript/submission_form/area.vue b/app/javascript/submission_form/area.vue index 5607c29d..6fa0812e 100644 --- a/app/javascript/submission_form/area.vue +++ b/app/javascript/submission_form/area.vue @@ -48,7 +48,7 @@ class="!text-2xl w-full h-full" > {{ getFormattedDate }} - + @@ -300,8 +300,7 @@ export default { data () { return { textOverflowChars: 0, - showLocalText: '', - showLocalDate: '' + showLocalText: '' } }, computed: { @@ -393,9 +392,8 @@ export default { } }, getFormattedDate () { - if (this.field.type === 'my_date' && this.showLocalDate) { - console.log('date returned ___-----', new Intl.DateTimeFormat([], { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' }).format(new Date(this.showLocalDate))) - return new Intl.DateTimeFormat([], { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' }).format(new Date(this.showLocalDate)) + if (this.field.type === 'my_date' && this.templateValues[this.field.uuid]) { + return new Intl.DateTimeFormat([], { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' }).format(new Date(this.templateValues[this.field.uuid])) } else { return '' } @@ -435,15 +433,6 @@ export default { } } - if (this.field.type === 'my_date') { - const fieldUuid = this.field.uuid - if (this.templateValues && this.templateValues[fieldUuid]) { - this.showLocalDate = this.templateValues[fieldUuid] - } else { - this.showLocalDate = '' - } - } - if (this.field.type === 'text' && this.$refs.textContainer) { this.$nextTick(() => { this.textOverflowChars = this.$refs.textContainer.scrollHeight > this.$refs.textContainer.clientHeight ? this.modelValue.length : 0 diff --git a/app/javascript/submission_form/form.vue b/app/javascript/submission_form/form.vue index 55320d62..704912b4 100644 --- a/app/javascript/submission_form/form.vue +++ b/app/javascript/submission_form/form.vue @@ -66,7 +66,7 @@ @focus="$refs.areas.scrollIntoField(currentField)" /> -
+
{ const emptyRequiredField = this.stepFields.find((fields, index) => { - if (['redact', 'my_text', 'my_signature', 'my_initials'].includes(fields[0].type)) { + if (['redact', 'my_text', 'my_signature', 'my_initials', 'my_date'].includes(fields[0].type)) { fields[0].required = 'false' return false } else { diff --git a/app/javascript/template_builder/area.vue b/app/javascript/template_builder/area.vue index 7420b1bb..4799d4ee 100644 --- a/app/javascript/template_builder/area.vue +++ b/app/javascript/template_builder/area.vue @@ -39,7 +39,7 @@ @pointerdown.stop > {{ optionIndexText }} {{ field.name || defaultName }} + <% elsif field['type'] == 'my_date' %> +
+ <%= l(Date.parse(value), format: :long, locale: local_assigns[:locale]) %> +
<% elsif field['type'] == 'redact' %>
<% elsif field['type'] == 'my_text' %> diff --git a/app/views/submissions/show.html.erb b/app/views/submissions/show.html.erb index b09cd57e..8bbc1016 100644 --- a/app/views/submissions/show.html.erb +++ b/app/views/submissions/show.html.erb @@ -59,7 +59,7 @@ <%= render 'submissions/annotation', annot: %> <% end %> <% fields_index.dig(document.uuid, index)&.each do |(area, field)| %> - <% if ['my_text', 'my_signature', 'my_initials'].include?(field['type']) %> + <% if ['my_text', 'my_signature', 'my_initials', 'my_date'].include?(field['type']) %> <% value = @submission.template.values[field['uuid']] %> <% else %> <% value = values[field['uuid']] %> diff --git a/lib/submissions/generate_result_attachments.rb b/lib/submissions/generate_result_attachments.rb index d81a847b..e86f763a 100644 --- a/lib/submissions/generate_result_attachments.rb +++ b/lib/submissions/generate_result_attachments.rb @@ -33,7 +33,7 @@ module Submissions pdfs_index = build_pdfs_index(submitter) submitter.submission.template_fields.each do |field| - unless ['my_text', 'my_signature', 'my_initials'].include?(field['type']) + unless ['my_text', 'my_signature', 'my_initials', 'my_date'].include?(field['type']) next if field['submitter_uuid'] != submitter.uuid end field.fetch('areas', []).each do |area| @@ -205,7 +205,7 @@ module Submissions layouter_my_text.fit([text_my_text], w, height_diff_my_text.positive? ? box_height_my_text : h) .draw(canvas, x + TEXT_LEFT_MARGIN, y - height_diff_my_text + 17) else - value = I18n.l(Date.parse(value), format: :default, locale: account.locale) if field['type'] == 'date' + value = I18n.l(Date.parse(value), format: :default, locale: account.locale) if field['type'] == 'date'|| field['type'] == 'my_date' text = HexaPDF::Layout::TextFragment.create(Array.wrap(value).join(', '), font: pdf.fonts.add(FONT_NAME), font_size:)