set dynamic fields
This commit is contained in:
@@ -3027,9 +3027,7 @@ export default {
|
|||||||
this.template.fields.splice(this.template.fields.indexOf(field), 1)
|
this.template.fields.splice(this.template.fields.indexOf(field), 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (toRemove.length) {
|
this.save()
|
||||||
this.save()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ import ReplaceButton from './replace'
|
|||||||
import GoogleDriveDocumentSettings from './google_drive_document_settings'
|
import GoogleDriveDocumentSettings from './google_drive_document_settings'
|
||||||
import Field from './field'
|
import Field from './field'
|
||||||
import FieldType from './field_type'
|
import FieldType from './field_type'
|
||||||
|
import { v4 } from 'uuid'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'DocumentPreview',
|
name: 'DocumentPreview',
|
||||||
@@ -246,7 +247,7 @@ export default {
|
|||||||
default: true
|
default: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['scroll-to', 'change', 'remove', 'up', 'down', 'replace', 'reorder', 'make-dynamic'],
|
emits: ['scroll-to', 'change', 'remove', 'up', 'down', 'replace', 'reorder'],
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
isShowConditionsModal: false,
|
isShowConditionsModal: false,
|
||||||
@@ -282,17 +283,78 @@ export default {
|
|||||||
}).then(async (resp) => {
|
}).then(async (resp) => {
|
||||||
const dynamicDocument = await resp.json()
|
const dynamicDocument = await resp.json()
|
||||||
|
|
||||||
if (dynamicDocument.uuid) {
|
this.template.schema.find((item) => item.attachment_uuid === dynamicDocument.uuid).dynamic = true
|
||||||
this.dynamicDocuments.push(dynamicDocument)
|
|
||||||
|
this.removeFieldAreas()
|
||||||
|
|
||||||
|
if (dynamicDocument.fields?.length) {
|
||||||
|
this.addDynamicFields(dynamicDocument.fields)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.template.schema.find((item) => item.attachment_uuid === dynamicDocument.uuid).dynamic = true
|
if (dynamicDocument.uuid) {
|
||||||
|
delete dynamicDocument.fields
|
||||||
|
|
||||||
|
this.dynamicDocuments.push(dynamicDocument)
|
||||||
|
}
|
||||||
|
|
||||||
this.$emit('change')
|
this.$emit('change')
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
this.isMakeDynamicLoading = false
|
this.isMakeDynamicLoading = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
removeFieldAreas () {
|
||||||
|
this.template.fields.forEach((field) => {
|
||||||
|
if (field.areas?.length) {
|
||||||
|
field.areas = field.areas.filter((a) => a.attachment_uuid !== this.document.uuid)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.template.fields = this.template.fields.filter((field) => field.areas?.length)
|
||||||
|
},
|
||||||
|
addDynamicFields (fields) {
|
||||||
|
const submittersNameIndex = this.template.submitters.reduce((acc, submitter) => {
|
||||||
|
acc[submitter.name] = submitter
|
||||||
|
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
|
||||||
|
fields.forEach((field) => {
|
||||||
|
const roleName = field.role || this.template.submitters[0]?.name || this.t('first_party')
|
||||||
|
|
||||||
|
let submitter = submittersNameIndex[roleName]
|
||||||
|
|
||||||
|
if (!submitter) {
|
||||||
|
submitter = { name: roleName, uuid: v4() }
|
||||||
|
|
||||||
|
this.template.submitters.push(submitter)
|
||||||
|
|
||||||
|
submittersNameIndex[roleName] = submitter
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingField = this.template.fields.find((f) => {
|
||||||
|
return f.name && f.name === field.name && f.type === (field.type || 'text') && f.submitter_uuid === submitter.uuid
|
||||||
|
})
|
||||||
|
|
||||||
|
if (existingField) {
|
||||||
|
field.areas.forEach((area) => {
|
||||||
|
area.attachment_uuid = this.document.uuid
|
||||||
|
|
||||||
|
existingField.areas = existingField.areas || []
|
||||||
|
existingField.areas.push(area)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
field.submitter_uuid = submitter.uuid
|
||||||
|
|
||||||
|
delete field.role
|
||||||
|
|
||||||
|
field.areas.forEach((area) => {
|
||||||
|
area.attachment_uuid = this.document.uuid
|
||||||
|
})
|
||||||
|
|
||||||
|
this.template.fields.push(field)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
onUpdateName (value) {
|
onUpdateName (value) {
|
||||||
this.item.name = value
|
this.item.name = value
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ class DynamicDocument < ApplicationRecord
|
|||||||
|
|
||||||
has_many :versions, class_name: 'DynamicDocumentVersion', dependent: :destroy
|
has_many :versions, class_name: 'DynamicDocumentVersion', dependent: :destroy
|
||||||
|
|
||||||
|
attribute :fields, :json
|
||||||
|
|
||||||
before_validation :set_sha1
|
before_validation :set_sha1
|
||||||
|
|
||||||
def set_sha1
|
def set_sha1
|
||||||
|
|||||||
Reference in New Issue
Block a user