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" >