add ability to reorder fields
This commit is contained in:
@@ -187,6 +187,7 @@
|
|||||||
@remove="onDocumentRemove"
|
@remove="onDocumentRemove"
|
||||||
@replace="onDocumentReplace"
|
@replace="onDocumentReplace"
|
||||||
@up="moveDocument(item, -1)"
|
@up="moveDocument(item, -1)"
|
||||||
|
@reorder="reorderFields"
|
||||||
@down="moveDocument(item, 1)"
|
@down="moveDocument(item, 1)"
|
||||||
@change="save"
|
@change="save"
|
||||||
/>
|
/>
|
||||||
@@ -818,6 +819,89 @@ export default {
|
|||||||
this.documentRefs = []
|
this.documentRefs = []
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
reorderFields (item) {
|
||||||
|
const itemFields = []
|
||||||
|
const fields = []
|
||||||
|
const fieldAreasIndex = {}
|
||||||
|
|
||||||
|
const attachmentUuids = this.template.schema.map((e) => e.attachment_uuid)
|
||||||
|
|
||||||
|
this.template.fields.forEach((f) => {
|
||||||
|
if (f.areas?.length) {
|
||||||
|
const firstArea = f.areas.reduce((min, a) => {
|
||||||
|
return attachmentUuids.indexOf(a.attachment_uuid) < attachmentUuids.indexOf(min.attachment_uuid) ? a : min
|
||||||
|
}, f.areas[0])
|
||||||
|
|
||||||
|
if (firstArea.attachment_uuid === item.attachment_uuid) {
|
||||||
|
itemFields.push(f)
|
||||||
|
} else {
|
||||||
|
fields.push(f)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fields.push(f)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const sortArea = (aArea, bArea) => {
|
||||||
|
if (aArea.attachment_uuid === bArea.attachment_uuid) {
|
||||||
|
if (aArea.page === bArea.page) {
|
||||||
|
if (Math.abs(aArea.y - bArea.y) < 0.01) {
|
||||||
|
if (aArea.x === bArea.x) {
|
||||||
|
return 0
|
||||||
|
} else {
|
||||||
|
return aArea.x - bArea.x
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return aArea.y - bArea.y
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return aArea.page - bArea.page
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return attachmentUuids.indexOf(aArea.attachment_uuid) - attachmentUuids.indexOf(bArea.attachment_uuid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
itemFields.sort((aField, bField) => {
|
||||||
|
const aArea = (fieldAreasIndex[aField.uuid] ||= [...(aField.areas || [])].sort(sortArea)[0])
|
||||||
|
const bArea = (fieldAreasIndex[bField.uuid] ||= [...(bField.areas || [])].sort(sortArea)[0])
|
||||||
|
|
||||||
|
return sortArea(aArea, bArea)
|
||||||
|
})
|
||||||
|
|
||||||
|
const insertBeforeAttachmentUuids = attachmentUuids.slice(this.template.schema.indexOf(item) + 1)
|
||||||
|
|
||||||
|
let sortedFields = []
|
||||||
|
|
||||||
|
if (insertBeforeAttachmentUuids.length) {
|
||||||
|
const insertAfterField = fields.find((f) => {
|
||||||
|
if (f.areas?.length) {
|
||||||
|
return f.areas.find((a) => insertBeforeAttachmentUuids.includes(a.attachment_uuid))
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (insertAfterField) {
|
||||||
|
fields.splice(fields.indexOf(insertAfterField), 0, ...itemFields)
|
||||||
|
|
||||||
|
sortedFields = fields
|
||||||
|
} else {
|
||||||
|
sortedFields = fields.concat(itemFields)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (fields.length && itemFields.length && this.template.fields.indexOf(fields[0]) > this.template.fields.indexOf(itemFields[0])) {
|
||||||
|
sortedFields = itemFields.concat(fields)
|
||||||
|
} else {
|
||||||
|
sortedFields = fields.concat(itemFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.template.fields.length === sortedFields.length) {
|
||||||
|
this.template.fields = sortedFields
|
||||||
|
this.save()
|
||||||
|
}
|
||||||
|
},
|
||||||
closeDropdown () {
|
closeDropdown () {
|
||||||
document.activeElement.blur()
|
document.activeElement.blur()
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const en = {
|
const en = {
|
||||||
|
reorder_fields: 'Reorder fields',
|
||||||
verify_id: 'Verify ID',
|
verify_id: 'Verify ID',
|
||||||
obtain_qualified_electronic_signature_with_the_trusted_provider_click_to_learn_more: 'Obtain qualified electronic signature (QeS) with the trusted provider. Click to learn more.',
|
obtain_qualified_electronic_signature_with_the_trusted_provider_click_to_learn_more: 'Obtain qualified electronic signature (QeS) with the trusted provider. Click to learn more.',
|
||||||
editable: 'Editable',
|
editable: 'Editable',
|
||||||
@@ -158,6 +159,7 @@ const en = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const es = {
|
const es = {
|
||||||
|
reorder_fields: 'Reordenar campos',
|
||||||
verify_id: 'Verificar ID',
|
verify_id: 'Verificar ID',
|
||||||
obtain_qualified_electronic_signature_with_the_trusted_provider_click_to_learn_more: 'Obtenga una firma electrónica cualificada (QeS) con el proveedor de confianza. Haga clic para obtener más información.',
|
obtain_qualified_electronic_signature_with_the_trusted_provider_click_to_learn_more: 'Obtenga una firma electrónica cualificada (QeS) con el proveedor de confianza. Haga clic para obtener más información.',
|
||||||
recurrent: 'Recurrente',
|
recurrent: 'Recurrente',
|
||||||
@@ -317,6 +319,7 @@ const es = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const it = {
|
const it = {
|
||||||
|
reorder_fields: 'Riordina i campi',
|
||||||
verify_id: 'Verifica ID',
|
verify_id: 'Verifica ID',
|
||||||
obtain_qualified_electronic_signature_with_the_trusted_provider_click_to_learn_more: 'Ottieni una firma elettronica qualificata (QeS) con il fornitore di fiducia. Clicca per saperne di più.',
|
obtain_qualified_electronic_signature_with_the_trusted_provider_click_to_learn_more: 'Ottieni una firma elettronica qualificata (QeS) con il fornitore di fiducia. Clicca per saperne di più.',
|
||||||
ricorrente: 'Ricorrente',
|
ricorrente: 'Ricorrente',
|
||||||
@@ -476,6 +479,7 @@ const it = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pt = {
|
const pt = {
|
||||||
|
reorder_fields: 'Reorganizar campos',
|
||||||
verify_id: 'Verificar ID',
|
verify_id: 'Verificar ID',
|
||||||
obtain_qualified_electronic_signature_with_the_trusted_provider_click_to_learn_more: 'Obtenha a assinatura eletrônica qualificada (QeS) com o provedor confiável. Clique para saber mais.',
|
obtain_qualified_electronic_signature_with_the_trusted_provider_click_to_learn_more: 'Obtenha a assinatura eletrônica qualificada (QeS) com o provedor confiável. Clique para saber mais.',
|
||||||
recurrent: 'Recurrente',
|
recurrent: 'Recurrente',
|
||||||
@@ -635,6 +639,7 @@ const pt = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fr = {
|
const fr = {
|
||||||
|
reorder_fields: 'Réorganiser les champs',
|
||||||
verify_id: "Vérifier l'ID",
|
verify_id: "Vérifier l'ID",
|
||||||
obtain_qualified_electronic_signature_with_the_trusted_provider_click_to_learn_more: 'Obtenez une signature électronique qualifiée (QeS) avec le fournisseur de confiance. Cliquez pour en savoir plus.',
|
obtain_qualified_electronic_signature_with_the_trusted_provider_click_to_learn_more: 'Obtenez une signature électronique qualifiée (QeS) avec le fournisseur de confiance. Cliquez pour en savoir plus.',
|
||||||
recurrent: 'Récurrent',
|
recurrent: 'Récurrent',
|
||||||
@@ -794,6 +799,7 @@ const fr = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const de = {
|
const de = {
|
||||||
|
reorder_fields: 'Felder neu anordnen',
|
||||||
verify_id: 'ID überprüfen',
|
verify_id: 'ID überprüfen',
|
||||||
obtain_qualified_electronic_signature_with_the_trusted_provider_click_to_learn_more: 'Erhalten Sie eine qualifizierte elektronische Signatur (QeS) beim vertrauenswürdigen Anbieter. Klicken Sie hier, um mehr zu erfahren.',
|
obtain_qualified_electronic_signature_with_the_trusted_provider_click_to_learn_more: 'Erhalten Sie eine qualifizierte elektronische Signatur (QeS) beim vertrauenswürdigen Anbieter. Klicken Sie hier, um mehr zu erfahren.',
|
||||||
wiederkehrend: 'Wiederkehrend',
|
wiederkehrend: 'Wiederkehrend',
|
||||||
|
|||||||
@@ -56,23 +56,39 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="withArrows"
|
|
||||||
class="flex flex-col space-y-1"
|
class="flex flex-col space-y-1"
|
||||||
>
|
>
|
||||||
<button
|
<span
|
||||||
class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-base-content hover:border-base-content w-full transition-colors"
|
:data-tip="t('reorder_fields')"
|
||||||
style="width: 24px; height: 24px"
|
class="tooltip tooltip-left before:text-xs"
|
||||||
@click.stop="$emit('up', item)"
|
|
||||||
>
|
>
|
||||||
↑
|
<button
|
||||||
</button>
|
class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-base-content hover:border-base-content w-full transition-colors p-0"
|
||||||
<button
|
@click.stop="$emit('reorder', item)"
|
||||||
class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-base-content hover:border-base-content w-full transition-colors"
|
>
|
||||||
style="width: 24px; height: 24px"
|
<IconSortDescending2
|
||||||
@click.stop="$emit('down', item)"
|
:width="18"
|
||||||
>
|
:height="18"
|
||||||
↓
|
:stroke-width="1.6"
|
||||||
</button>
|
/>
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
<template v-if="withArrows">
|
||||||
|
<button
|
||||||
|
class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-base-content hover:border-base-content w-full transition-colors"
|
||||||
|
style="width: 24px; height: 24px"
|
||||||
|
@click.stop="$emit('up', item)"
|
||||||
|
>
|
||||||
|
↑
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-base-content hover:border-base-content w-full transition-colors"
|
||||||
|
style="width: 24px; height: 24px"
|
||||||
|
@click.stop="$emit('down', item)"
|
||||||
|
>
|
||||||
|
↓
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -104,7 +120,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import Contenteditable from './contenteditable'
|
import Contenteditable from './contenteditable'
|
||||||
import Upload from './upload'
|
import Upload from './upload'
|
||||||
import { IconRouteAltLeft } from '@tabler/icons-vue'
|
import { IconRouteAltLeft, IconSortDescending2 } from '@tabler/icons-vue'
|
||||||
import ConditionsModal from './conditions_modal'
|
import ConditionsModal from './conditions_modal'
|
||||||
import ReplaceButton from './replace'
|
import ReplaceButton from './replace'
|
||||||
import Field from './field'
|
import Field from './field'
|
||||||
@@ -116,7 +132,8 @@ export default {
|
|||||||
Contenteditable,
|
Contenteditable,
|
||||||
IconRouteAltLeft,
|
IconRouteAltLeft,
|
||||||
ConditionsModal,
|
ConditionsModal,
|
||||||
ReplaceButton
|
ReplaceButton,
|
||||||
|
IconSortDescending2
|
||||||
},
|
},
|
||||||
inject: ['t'],
|
inject: ['t'],
|
||||||
props: {
|
props: {
|
||||||
@@ -153,7 +170,7 @@ export default {
|
|||||||
default: true
|
default: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['scroll-to', 'change', 'remove', 'up', 'down', 'replace'],
|
emits: ['scroll-to', 'change', 'remove', 'up', 'down', 'replace', 'reorder'],
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
isShowConditionsModal: false
|
isShowConditionsModal: false
|
||||||
|
|||||||
Reference in New Issue
Block a user