diff --git a/app/controllers/api/attachments_controller.rb b/app/controllers/api/attachments_controller.rb index 7ff46fe7..e93dc53c 100644 --- a/app/controllers/api/attachments_controller.rb +++ b/app/controllers/api/attachments_controller.rb @@ -6,9 +6,12 @@ module Api skip_authorization_check def create - submitter = Submitter.find_by!(slug: params[:submitter_slug]) - - attachment = Submitters.create_attachment!(submitter, params) + record = if params[:template_slug].present? + Template.find_by!(slug: params[:template_slug]) + else + Submitter.find_by!(slug: params[:submitter_slug]) + end + attachment = Submitters.create_attachment!(record, params) render json: attachment.as_json(only: %i[uuid], methods: %i[url filename content_type]) end diff --git a/app/controllers/api/templates_controller.rb b/app/controllers/api/templates_controller.rb index 2b6b1d59..fa79b605 100644 --- a/app/controllers/api/templates_controller.rb +++ b/app/controllers/api/templates_controller.rb @@ -54,7 +54,7 @@ module Api def template_params params.require(:template).permit( - :name, + :name, values: {}, schema: [%i[attachment_uuid name]], submitters: [%i[name uuid]], fields: [[:uuid, :submitter_uuid, :name, :type, :required, :readonly, :default_value, diff --git a/app/controllers/api/templates_documents_controller.rb b/app/controllers/api/templates_documents_controller.rb index 04fdb12c..16dbf20a 100644 --- a/app/controllers/api/templates_documents_controller.rb +++ b/app/controllers/api/templates_documents_controller.rb @@ -23,5 +23,62 @@ module Api ) } end + + def del_image + template = Template.find(params[:template_id]) + 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 + Templates::ProcessDocument.delete_picture(template, document, img_attachment_id, page_number) + template.fields.each do |field| + field['areas'] = (field['areas'] || []).reject do |area| + area['attachment_uuid'] == document[:uuid] && area['page'] == page_number + end + end + template.fields = (template.fields || []).reject do |field| + field['areas'].empty? + end + template.save + updated_images = updated_preview_images(document) + new_metadata = document.metadata + render json: { success: true, message: 'image deleted successfully', updated_preview_images: updated_images, updated_metadata: new_metadata } + else + page_number = "No image found for deletion" + render json: { success: false, message: "Error: #{page_number}" }, status: :unprocessable_entity + end + end + + def add_new_image + template = Template.find(params[:template_id]) + raw_document = params[:document] + document = template.documents.find_by(id: raw_document[:id]) + begin + Templates::ProcessDocument.upload_new_blank_image(template, document) + updated_images = updated_preview_images(document) + new_metadata = document.metadata + render json: { success: true, message: 'New blank image added successfully', updated_preview_images: updated_images, updated_metadata: new_metadata } + rescue StandardError => e + render json: { success: false, message: "Error adding new blank image: #{e.message}" }, status: :unprocessable_entity + end + end + + def updated_preview_images(document) + updated_images = document.preview_images.map do |image| + { + "id": image.id, + "name": image.name, + "uuid": image.uuid, + "record_type": image.record_type, + "record_id": image.record_id, + "blob_id": image.blob_id, + "filename": image.filename.as_json, + "metadata": image.metadata, + "url": image.url, + "created_at": image.created_at + } + end + end + end end diff --git a/app/controllers/start_form_controller.rb b/app/controllers/start_form_controller.rb index 938ca2ab..e1732ab1 100644 --- a/app/controllers/start_form_controller.rb +++ b/app/controllers/start_form_controller.rb @@ -9,7 +9,7 @@ class StartFormController < ApplicationController before_action :load_template def show - @submitter = @template.submissions.new.submitters.new(uuid: @template.submitters.first['uuid']) + @submitter = @template.submitters.second.nil? ? @template.submissions.new.submitters.new(uuid: @template.submitters.first['uuid']) : @template.submissions.new.submitters.new(uuid: @template.submitters.second['uuid']) end def update diff --git a/app/controllers/submissions_preview_controller.rb b/app/controllers/submissions_preview_controller.rb index 878dfe26..d4601d9e 100644 --- a/app/controllers/submissions_preview_controller.rb +++ b/app/controllers/submissions_preview_controller.rb @@ -20,7 +20,7 @@ class SubmissionsPreviewController < ApplicationController if total_pages < PRELOAD_ALL_PAGES_AMOUNT ActiveRecord::Associations::Preloader.new( records: @submission.template_schema_documents, - associations: [:blob, { preview_images_attachments: :blob }] + associations: [:blob, { preview_secured_images_attachments: :blob }] ).call end diff --git a/app/javascript/application.js b/app/javascript/application.js index 178b3623..a65a679d 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -83,6 +83,7 @@ window.customElements.define('template-builder', class extends HTMLElement { this.app = createApp(TemplateBuilder, { template: reactive(JSON.parse(this.dataset.template)), + templateAttachments: reactive(JSON.parse(this.dataset.templateAttachmentsIndex)), backgroundColor: '#faf7f5', withPhone: this.dataset.withPhone === 'true', withLogo: this.dataset.withLogo !== 'false', diff --git a/app/javascript/application.scss b/app/javascript/application.scss index 991fc9cd..49efe35d 100644 --- a/app/javascript/application.scss +++ b/app/javascript/application.scss @@ -75,6 +75,10 @@ button[disabled] .enabled { @apply select base-input w-full font-normal; } +.bg-redact { + background: black; +} + .tooltip-bottom-end:before { transform: translateX(-95%); top: var(--tooltip-offset); @@ -105,7 +109,7 @@ button[disabled] .enabled { font: inherit; } -.autocomplete > div { +.autocomplete>div { @apply px-2 py-1 font-normal text-sm; } @@ -113,8 +117,8 @@ button[disabled] .enabled { background: #eee; } -.autocomplete > div:hover:not(.group), -.autocomplete > div.selected { +.autocomplete>div:hover:not(.group), +.autocomplete>div.selected { @apply bg-base-300; cursor: pointer; } @@ -125,3 +129,44 @@ button[disabled] .enabled { outline-offset: 3px; outline-color: hsl(var(--bc) / 0.2); } + +.my-display { + display: none; +} + +#loader { + background: rgba(0, 7, 14, 0.7); + text-align: center; + position: absolute; + top: 0em; + left: 0em; + padding: 20% 0px; + height: 100vh; + width: 100vw; + text-align: -webkit-center; +} + +.loader-animation { + width: 50px; + height: 50px; + border: 4px solid #fff; + border-top: 4px solid transparent; + border-radius: 50%; + animation: spin 1s linear infinite; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} + +@keyframes spin { + 0% { + transform: rotate(0deg); + } + + 100% { + transform: rotate(360deg); + } +} + +.text-load { + color: #fff; + font-size: large; +} diff --git a/app/javascript/form.js b/app/javascript/form.js index 601b45d0..29038984 100644 --- a/app/javascript/form.js +++ b/app/javascript/form.js @@ -10,6 +10,9 @@ window.customElements.define('submission-form', class extends HTMLElement { this.app = createApp(Form, { submitter: JSON.parse(this.dataset.submitter), + templateValues: JSON.parse(this.dataset.templateValues), + templateAttachments: reactive(JSON.parse(this.dataset.templateAttachmentsIndex)), + authenticityToken: this.dataset.authenticityToken, canSendEmail: this.dataset.canSendEmail === 'true', isDirectUpload: this.dataset.isDirectUpload === 'true', goToLast: this.dataset.goToLast === 'true', diff --git a/app/javascript/submission_form/area.vue b/app/javascript/submission_form/area.vue index 50f32288..05791fd5 100644 --- a/app/javascript/submission_form/area.vue +++ b/app/javascript/submission_form/area.vue @@ -1,5 +1,101 @@