From 436d947f6aa520eec7f2c1819056d62d3380ebfe Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Wed, 2 Sep 2026 20:08:42 +0300 Subject: [PATCH] detect fields autosave false --- .../templates_detect_fields_controller.rb | 10 ++++++++-- app/javascript/template_builder/fields.vue | 13 ++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/controllers/templates_detect_fields_controller.rb b/app/controllers/templates_detect_fields_controller.rb index a0cd54ff..d01925a1 100644 --- a/app/controllers/templates_detect_fields_controller.rb +++ b/app/controllers/templates_detect_fields_controller.rb @@ -10,8 +10,14 @@ class TemplatesDetectFieldsController < ApplicationController sse = SSE.new(response.stream) - documents = @template.schema_documents.preload(:blob) - documents = documents.where(uuid: params[:attachment_uuid]) if params[:attachment_uuid].present? + documents = + if params[:attachment_uuid].present? + @template.documents.where(uuid: params[:attachment_uuid]) + else + @template.schema_documents + end + + documents = documents.preload(:blob) page_number = params[:page].presence&.to_i diff --git a/app/javascript/template_builder/fields.vue b/app/javascript/template_builder/fields.vue index cab03639..29107103 100644 --- a/app/javascript/template_builder/fields.vue +++ b/app/javascript/template_builder/fields.vue @@ -555,8 +555,10 @@ export default { return this.template.schema.some((item) => item.dynamic) }, numberOfPages () { - return this.template.documents.reduce((acc, doc) => { - return acc + doc.metadata?.pdf?.number_of_pages || doc.preview_images.length + return this.template.schema.reduce((acc, item) => { + const doc = this.template.documents.find((d) => d.uuid === item.attachment_uuid) + + return acc + (doc?.metadata?.pdf?.number_of_pages || doc?.preview_images?.length || 0) }, 0) }, isShowFieldSearch () { @@ -774,9 +776,10 @@ export default { headers: { 'Content-Type': 'application/json' }, - ...(this.withDetectExistingFields - ? { body: JSON.stringify({ fields: this.buildExistingFields() }) } - : {}) + body: JSON.stringify({ + attachment_uuid: this.template.schema.map((item) => item.attachment_uuid), + ...(this.withDetectExistingFields ? { fields: this.buildExistingFields() } : {}) + }) }).then(async (response) => { const reader = response.body.getReader() const decoder = new TextDecoder('utf-8')