add builder dashboard dropzone

This commit is contained in:
Alex Turchyn
2025-04-25 21:19:28 +03:00
committed by Pete Matsyburka
parent e34a763dd9
commit 97b8ac4444
18 changed files with 535 additions and 36 deletions
@@ -0,0 +1,36 @@
# frozen_string_literal: true
class TemplateReplaceDocumentsController < ApplicationController
load_and_authorize_resource :template
def create
if params[:blobs].blank? && params[:files].blank?
return respond_to do |f|
f.html { redirect_back fallback_location: template_path(@template), alert: I18n.t('file_is_missing') }
f.json { render json: { error: I18n.t('file_is_missing') }, status: :unprocessable_entity }
end
end
ActiveRecord::Associations::Preloader.new(
records: [@template],
associations: [schema_documents: :preview_images_attachments]
).call
cloned_template = Templates::Clone.call(@template, author: current_user)
cloned_template.save!
documents = Templates::ReplaceAttachments.call(cloned_template, params, extract_fields: true)
cloned_template.save!
Templates::CloneAttachments.call(template: cloned_template, original_template: @template,
excluded_attachment_uuids: documents.map(&:uuid))
respond_to do |f|
f.html { redirect_to edit_template_path(cloned_template) }
f.json { render json: { id: cloned_template.id } }
end
rescue Templates::CreateAttachments::PdfEncrypted
render json: { error: 'PDF encrypted', status: 'pdf_encrypted' }, status: :unprocessable_entity
end
end