diff --git a/app/javascript/template_builder/builder.vue b/app/javascript/template_builder/builder.vue index cf666159..4a72277c 100644 --- a/app/javascript/template_builder/builder.vue +++ b/app/javascript/template_builder/builder.vue @@ -64,8 +64,11 @@ :with-arrows="template.schema.length > 1" :item="item" :document="sortedDocuments[index]" + :template="template" + :is-direct-upload="isDirectUpload" @scroll-to="scrollIntoDocument(item)" @remove="onDocumentRemove" + @replace="onDocumentReplace" @up="moveDocument(item, -1)" @down="moveDocument(item, 1)" @change="save" @@ -419,6 +422,19 @@ export default { this.save() }, + onDocumentReplace ({ replaceSchemaItem, schema, documents }) { + this.template.schema.splice(this.template.schema.indexOf(replaceSchemaItem), 1, schema[0]) + this.template.documents.push(...documents) + this.template.fields.forEach((field) => { + field.areas.forEach((area) => { + if (area.attachment_uuid === replaceSchemaItem.attachment_uuid) { + area.attachment_uuid = schema[0].attachment_uuid + } + }) + }) + + this.save() + }, moveDocument (item, direction) { const currentIndex = this.template.schema.indexOf(item) diff --git a/app/javascript/template_builder/dropzone.vue b/app/javascript/template_builder/dropzone.vue index 65f2ef16..8f30606d 100644 --- a/app/javascript/template_builder/dropzone.vue +++ b/app/javascript/template_builder/dropzone.vue @@ -93,6 +93,11 @@ export default { } } }, + mounted () { + if (this.isDirectUpload) { + import('@rails/activestorage') + } + }, methods: { upload: Upload.methods.upload, onDropFiles (e) { diff --git a/app/javascript/template_builder/preview.vue b/app/javascript/template_builder/preview.vue index d4146092..b34be086 100644 --- a/app/javascript/template_builder/preview.vue +++ b/app/javascript/template_builder/preview.vue @@ -9,39 +9,51 @@ loading="lazy" >
-
-
- +
+
+
+
- - +
+
- ↓ - + + +
@@ -60,34 +72,52 @@ diff --git a/app/models/template.rb b/app/models/template.rb index 97db25d3..0e8a8df6 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -44,6 +44,9 @@ class Template < ApplicationRecord has_many_attached :documents + has_many :schema_documents, ->(e) { where(uuid: e.schema.pluck('attachment_uuid')) }, + class_name: 'ActiveStorage::Attachment', dependent: :destroy, as: :record, inverse_of: :record + has_many :submissions, dependent: :destroy scope :active, -> { where(deleted_at: nil) } diff --git a/app/views/templates/edit.html.erb b/app/views/templates/edit.html.erb index 0867a976..30dffaff 100644 --- a/app/views/templates/edit.html.erb +++ b/app/views/templates/edit.html.erb @@ -1 +1 @@ - +