adjust signature prefill
This commit is contained in:
@@ -8,7 +8,6 @@ class SubmitFormController < ApplicationController
|
||||
skip_authorization_check
|
||||
|
||||
CONFIG_KEYS = [].freeze
|
||||
PRELOAD_ALL_PAGES_AMOUNT = 200
|
||||
|
||||
def show
|
||||
@submitter = Submitter.find_by!(slug: params[:slug])
|
||||
@@ -16,20 +15,7 @@ class SubmitFormController < ApplicationController
|
||||
return redirect_to submit_form_completed_path(@submitter.slug) if @submitter.completed_at?
|
||||
return render :archived if @submitter.submission.template.archived_at? || @submitter.submission.archived_at?
|
||||
|
||||
ActiveRecord::Associations::Preloader.new(
|
||||
records: [@submitter],
|
||||
associations: [submission: [:template, { template_schema_documents: :blob }]]
|
||||
).call
|
||||
|
||||
total_pages =
|
||||
@submitter.submission.template_schema_documents.sum { |e| e.metadata.dig('pdf', 'number_of_pages').to_i }
|
||||
|
||||
if total_pages < PRELOAD_ALL_PAGES_AMOUNT
|
||||
ActiveRecord::Associations::Preloader.new(
|
||||
records: @submitter.submission.template_schema_documents,
|
||||
associations: [:blob, { preview_images_attachments: :blob }]
|
||||
).call
|
||||
end
|
||||
Submitters.preload_with_pages(@submitter)
|
||||
|
||||
Submitters::MaybeUpdateDefaultValues.call(@submitter, current_user)
|
||||
|
||||
@@ -40,7 +26,15 @@ class SubmitFormController < ApplicationController
|
||||
|
||||
return unless @form_configs[:prefill_signature]
|
||||
|
||||
@signature_attachment =
|
||||
if (user_signature = UserConfigs.load_signature(current_user))
|
||||
@signature_attachment = ActiveStorage::Attachment.find_or_create_by!(
|
||||
blob_id: user_signature.blob_id,
|
||||
name: 'attachments',
|
||||
record: @submitter
|
||||
)
|
||||
end
|
||||
|
||||
@signature_attachment ||=
|
||||
Submitters::MaybeAssignDefaultBrowserSignature.call(@submitter, params, cookies, @attachments_index.values)
|
||||
|
||||
@attachments_index[@signature_attachment.uuid] = @signature_attachment if @signature_attachment
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TemplatesFormPreviewController < ApplicationController
|
||||
PRELOAD_ALL_PAGES_AMOUNT = 200
|
||||
|
||||
layout 'form'
|
||||
|
||||
load_and_authorize_resource :template
|
||||
@@ -15,20 +13,7 @@ class TemplatesFormPreviewController < ApplicationController
|
||||
|
||||
@submitter.submission.submitters = @template.submitters.map { |item| Submitter.new(uuid: item['uuid']) }
|
||||
|
||||
ActiveRecord::Associations::Preloader.new(
|
||||
records: [@submitter],
|
||||
associations: [submission: [:template, { template_schema_documents: :blob }]]
|
||||
).call
|
||||
|
||||
total_pages =
|
||||
@submitter.submission.template_schema_documents.sum { |e| e.metadata.dig('pdf', 'number_of_pages').to_i }
|
||||
|
||||
if total_pages < PRELOAD_ALL_PAGES_AMOUNT
|
||||
ActiveRecord::Associations::Preloader.new(
|
||||
records: @submitter.submission.template_schema_documents,
|
||||
associations: [:blob, { preview_images_attachments: :blob }]
|
||||
).call
|
||||
end
|
||||
Submitters.preload_with_pages(@submitter)
|
||||
|
||||
@attachments_index = ActiveStorage::Attachment.where(record: @submitter.submission.submitters, name: :attachments)
|
||||
.preload(:blob).index_by(&:uuid)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
module Submitters
|
||||
TRUE_VALUES = ['1', 'true', true].freeze
|
||||
PRELOAD_ALL_PAGES_AMOUNT = 200
|
||||
|
||||
module_function
|
||||
|
||||
@@ -29,6 +30,25 @@ module Submitters
|
||||
end
|
||||
end
|
||||
|
||||
def preload_with_pages(submitter)
|
||||
ActiveRecord::Associations::Preloader.new(
|
||||
records: [submitter],
|
||||
associations: [submission: [:template, { template_schema_documents: :blob }]]
|
||||
).call
|
||||
|
||||
total_pages =
|
||||
submitter.submission.template_schema_documents.sum { |e| e.metadata.dig('pdf', 'number_of_pages').to_i }
|
||||
|
||||
if total_pages < PRELOAD_ALL_PAGES_AMOUNT
|
||||
ActiveRecord::Associations::Preloader.new(
|
||||
records: submitter.submission.template_schema_documents,
|
||||
associations: [:blob, { preview_images_attachments: :blob }]
|
||||
).call
|
||||
end
|
||||
|
||||
submitter
|
||||
end
|
||||
|
||||
def create_attachment!(submitter, params)
|
||||
blob =
|
||||
if (file = params[:file])
|
||||
|
||||
@@ -43,14 +43,6 @@ module Submitters
|
||||
record: submitter
|
||||
)
|
||||
|
||||
attachment.uuid
|
||||
elsif field['type'] == 'signature' && (signature = UserConfigs.load_signature(user))
|
||||
attachment = ActiveStorage::Attachment.find_or_create_by!(
|
||||
blob_id: signature.blob_id,
|
||||
name: 'attachments',
|
||||
record: submitter
|
||||
)
|
||||
|
||||
attachment.uuid
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user