3
0

Add configuration update for system fields

This commit is contained in:
Kelani Tolulope
2022-11-16 19:08:56 +01:00
parent d493077b7d
commit 97c8516b0b
5 changed files with 85 additions and 16 deletions
@@ -10,8 +10,17 @@
<b-form-checkbox
v-if="allowOmitStrategy"
v-model="use"
:disabled="disabled"
>
{{ label }}
<b-badge
v-if="!use"
variant="info"
class="ml-2 align-middle"
>
{{ $t('unavailable') }}
</b-badge>
</b-form-checkbox>
<div
v-else
@@ -98,6 +107,11 @@ export default {
type: Boolean,
default: true,
},
disabled: {
type: Boolean,
default: false,
},
},
data () {
@@ -47,17 +47,33 @@
</b-form-group>
<b-form-group
:label="$t('system-fields.label')"
:description="$t('system-fields.description')"
>
<div class="my-4 d-flex justify-content-between align-items-center flex-wrap">
<label>
{{ $t('system-fields.label') }}
</label>
<b-form-radio-group
v-model="selectedGroup"
buttons
button-variant="outline-secondary"
size="sm"
name="buttons"
:options="optionsGroups"
class="mb-3"
@change="applySelectedSystemFields"
/>
</div>
<dal-field-store-encoding
v-for="({ field, storeIdent, label }) in systemFields"
v-for="({ field, storeIdent, label, disabled }) in systemFields"
:key="field"
:config="systemFieldEncoding[field] || {}"
:field="field"
:label="label"
:store-ident="storeIdent"
:allow-omit-strategy="true"
:disabled="disabled"
@change="applySystemFieldStrategyConfig(field, $event)"
/>
</b-form-group>
@@ -93,18 +109,18 @@ export default {
data () {
const systemFieldEncoding = this.module.config.dal.systemFieldEncoding || {}
const systemFields = [
{ field: 'id', storeIdent: 'id' },
{ field: 'namespaceID', storeIdent: 'rel_namespace' },
{ field: 'moduleID', storeIdent: 'rel_module' },
{ field: 'revision', storeIdent: 'revision' },
{ field: 'meta', storeIdent: 'meta' },
{ field: 'ownedBy', storeIdent: 'owned_by' },
{ field: 'createdAt', storeIdent: 'created_at' },
{ field: 'createdBy', storeIdent: 'created_by' },
{ field: 'updatedAt', storeIdent: 'updated_at' },
{ field: 'updatedBy', storeIdent: 'updated_by' },
{ field: 'deletedAt', storeIdent: 'deleted_at' },
{ field: 'deletedBy', storeIdent: 'deleted_by' },
{ field: 'id', storeIdent: 'id', disabled: true },
{ field: 'namespaceID', storeIdent: 'rel_namespace', group: 'partition' },
{ field: 'moduleID', storeIdent: 'rel_module', group: 'partition' },
{ field: 'revision', storeIdent: 'revision', group: 'extras' },
{ field: 'meta', storeIdent: 'meta', group: 'extras' },
{ field: 'ownedBy', storeIdent: 'owned_by', group: 'user_reference' },
{ field: 'createdAt', storeIdent: 'created_at', group: 'timestamps' },
{ field: 'createdBy', storeIdent: 'created_by', group: 'user_reference' },
{ field: 'updatedAt', storeIdent: 'updated_at', group: 'timestamps' },
{ field: 'updatedBy', storeIdent: 'updated_by', group: 'user_reference' },
{ field: 'deletedAt', storeIdent: 'deleted_at', group: 'timestamps' },
{ field: 'deletedBy', storeIdent: 'deleted_by', group: 'user_reference' },
].map(sf => ({ ...sf, label: this.$t(`field:system.${sf.field}`) }))
return {
@@ -113,12 +129,20 @@ export default {
moduleFields: [],
moduleFieldEncoding: [],
selectedGroup: '',
systemFields,
systemFieldEncoding: systemFields.reduce((enc, { field }) => {
enc[field] = systemFieldEncoding[field] || {}
return enc
}, {}),
optionsGroups: [
{ text: this.$t('system-fields.grouptypes.all'), value: 'all' },
{ text: this.$t('system-fields.grouptypes.partition'), value: 'partition' },
{ text: this.$t('system-fields.grouptypes.userReference'), value: 'user_reference' },
{ text: this.$t('system-fields.grouptypes.timestamps'), value: 'timestamps' },
{ text: this.$t('system-fields.grouptypes.extras'), value: 'extras' },
],
}
},
@@ -218,6 +242,19 @@ export default {
return enc
}, {})
},
applySelectedSystemFields (selectedOption) {
this.systemFieldEncoding = this.systemFields.reduce((enc, { field, group }) => {
if (field !== 'id') {
if (selectedOption === 'all') {
enc[field] = {}
} else {
enc[field] = group === selectedOption ? {} : { omit: true }
}
}
return enc
}, {})
},
},
}
</script>
@@ -3,6 +3,13 @@
<td />
<td class="pl-3">
{{ field.name }}
<b-badge
v-if="field.omit"
variant="info"
class="ml-2 align-middle"
>
{{ $t('unavailable') }}
</b-badge>
</td>
<td class="pl-3">
{{ field.label }}
@@ -581,10 +581,13 @@ export default {
},
systemFields () {
const systemFieldEncoding = this.module.config.dal.systemFieldEncoding || {}
return this.module.systemFields().map(sf => {
if (!sf) return
sf.label = this.$t(`field:system.${sf.name}`)
return sf
})
return { ...sf, ...(systemFieldEncoding[sf.name] || {}) }
}).filter(sf => sf)
},
editModalTitle () {
@@ -111,8 +111,16 @@ edit:
System fields are used to store metadata about the record.
Configure to skip or store them into a column with the same name (Column),
a different column (Alias) or encode them into JSON.
grouptypes:
all: All
partition: Partition
userReference: User reference
timestamps: Timestamps
extras: Extras
encoding-strategy:
unavailable: unavailable
ident:
placeholder: Field or database table column name