Skip to content

Commit

Permalink
Merge pull request #47 from ConductionNL/feature/DIMOC-288/publicatio…
Browse files Browse the repository at this point in the history
…n-type-default-value

feature/DIMOC-288/publication-type-default-value
  • Loading branch information
remko48 authored Aug 26, 2024
2 parents 0674061 + 4d869ea commit 66bdcbe
Show file tree
Hide file tree
Showing 3 changed files with 278 additions and 14 deletions.
138 changes: 132 additions & 6 deletions src/modals/metaData/AddMetaDataPropertyModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ import { navigationStore, metadataStore } from '../../store/store.js'

<div v-if="!success" class="form-group">
<NcTextField :disabled="loading"
label="Eigenschap naam"
required
label="Eigenschap naam*"
:error="checkIfTitleIsUnique(properties.name)"
:helper-text="checkIfTitleIsUnique(properties.name) ? 'Deze naam is al in gebruik. Kies een andere naam.' : ''"
:value.sync="properties.name" />

<NcTextField :disabled="loading"
label="Titel"
required
label="Titel*"
:value.sync="properties.title" />

<NcTextField :disabled="loading"
Expand All @@ -44,7 +42,115 @@ import { navigationStore, metadataStore } from '../../store/store.js'
label="Patroon (regex)"
:value.sync="properties.pattern" />

<NcTextField :disabled="loading"
<NcTextField v-if="!properties.type"
:disabled="loading || !properties.type"
label="Default waarde"
:value.sync="properties.default" />

<!-- TYPE : STRING -->
<div v-if="properties.type === 'string'">
<NcDateTimePicker v-if="properties.format === 'date'"
v-model="properties.default"
type="date"
label="Default waarde"
:disabled="loading"
:loading="loading" />

<NcDateTimePicker v-else-if="properties.format === 'time'"
v-model="properties.default"
type="time"
label="Default waarde"
:disabled="loading"
:loading="loading" />

<NcDateTimePicker v-else-if="properties.format === 'date-time'"
v-model="properties.default"
type="datetime"
label="Default waarde"
:disabled="loading"
:loading="loading" />

<NcInputField v-else-if="properties.format === 'email'"
:value.sync="properties.default"
type="email"
label="Default waarde (Email)"
:disabled="loading"
:loading="loading" />

<NcInputField v-else-if="properties.format === 'idn-email'"
:value.sync="properties.default"
type="email"
label="Default waarde (Email)"
helper-text="email"
:disabled="loading"
:loading="loading" />

<NcTextField v-else-if="properties.format === 'regex'"
:value.sync="properties.default"
label="Default waarde (Regex)"
:disabled="loading"
:loading="loading" />

<NcInputField v-else-if="properties.format === 'password'"
:value.sync="properties.default"
type="password"
label="Default waarde (Wachtwoord)"
:disabled="loading"
:loading="loading" />

<NcInputField v-else-if="properties.format === 'telephone'"
:value.sync="properties.default"
type="tel"
label="Default waarde (Telefoonnummer)"
:disabled="loading"
:loading="loading" />

<NcTextField v-else
:value.sync="properties.default"
label="Default waarde"
:disabled="loading"
:loading="loading" />
</div>

<!-- TYPE : NUMBER -->
<NcInputField v-else-if="properties.type === 'number'"
:disabled="loading"
type="number"
step="any"
label="Default waarde"
:value.sync="properties.default"
:loading="loading" />
<!-- TYPE : INTEGER -->
<NcInputField v-else-if="properties.type === 'integer'"
:disabled="loading"
type="number"
step="1"
label="Default waarde"
:value.sync="properties.default"
:loading="loading" />
<!-- TYPE : OBJECT -->
<NcTextArea v-else-if="properties.type === 'object'"
:disabled="loading"
label="Default waarde"
:value.sync="properties.default"
:loading="loading" />
<!-- TYPE : ARRAY -->
<NcTextArea v-else-if="properties.type === 'array'"
:disabled="loading"
label="Waarde lijst (split op ,)"
:value.sync="properties.default"
:loading="loading" />
<!-- TYPE : BOOLEAN -->
<NcCheckboxRadioSwitch v-else-if="properties.type === 'boolean'"
:disabled="loading"
:checked.sync="properties.default"
:loading="loading">
Default waarde
</NcCheckboxRadioSwitch>

<!-- TYPE : STRING -->
<NcTextField v-else-if="properties.type === 'dictionary'"
:disabled="loading || !properties.type"
label="Default waarde"
:value.sync="properties.default" />

Expand Down Expand Up @@ -161,6 +267,8 @@ import {
NcInputField,
NcNoteCard,
NcLoadingIcon,
NcDateTimePicker,
NcTextArea,
} from '@nextcloud/vue'
// icons
Expand All @@ -177,6 +285,8 @@ export default {
NcButton,
NcNoteCard,
NcLoadingIcon,
NcDateTimePicker,
NcTextArea,
},
data() {
return {
Expand All @@ -203,7 +313,7 @@ export default {
maxItems: 0,
},
typeOptions: {
inputLabel: 'Type',
inputLabel: 'Type*',
multiple: false,
options: ['string', 'number', 'integer', 'object', 'array', 'boolean', 'dictionary'],
},
Expand All @@ -218,6 +328,22 @@ export default {
hasUpdated: false,
}
},
computed: {
metadataProperty() {
return Object.assign({}, this.properties)
},
},
watch: {
metadataProperty: {
deep: true,
handler(newVal, oldVal) {
if (newVal.type !== oldVal.type) {
if (newVal.type === 'boolean') this.properties.default = false
if (newVal.type !== 'boolean' && oldVal.type === 'boolean') this.properties.default = ''
}
},
},
},
methods: {
addMetadata() {
this.loading = true
Expand Down
142 changes: 137 additions & 5 deletions src/modals/metaData/EditMetaDataPropertyModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { navigationStore, metadataStore } from '../../store/store.js'
<div v-if="success === null && metadata.properties[metadataStore.metadataDataKey]" class="form-group">
<NcTextField
:disabled="loading"
label="Title"
label="Title*"
required
:value.sync="metadata.properties[metadataStore.metadataDataKey].title" />

Expand All @@ -43,7 +43,115 @@ import { navigationStore, metadataStore } from '../../store/store.js'
label="Patroon (regex)"
:value.sync="metadata.properties[metadataStore.metadataDataKey].pattern" />

<NcTextField :disabled="loading"
<NcTextField v-if="!metadata.properties[metadataStore.metadataDataKey].type"
:disabled="loading"
label="Default waarde"
:value.sync="metadata.properties[metadataStore.metadataDataKey].default" />

<!-- TYPE : STRING -->
<div v-if="metadata.properties[metadataStore.metadataDataKey].type === 'string'">
<NcDateTimePicker v-if="metadata.properties[metadataStore.metadataDataKey].format === 'date'"
v-model="metadata.properties[metadataStore.metadataDataKey].default"
type="date"
label="Default waarde"
:disabled="loading"
:loading="loading" />

<NcDateTimePicker v-else-if="metadata.properties[metadataStore.metadataDataKey].format === 'time'"
v-model="metadata.properties[metadataStore.metadataDataKey].default"
type="time"
label="Default waarde"
:disabled="loading"
:loading="loading" />

<NcDateTimePicker v-else-if="metadata.properties[metadataStore.metadataDataKey].format === 'date-time'"
v-model="metadata.properties[metadataStore.metadataDataKey].default"
type="datetime"
label="Default waarde"
:disabled="loading"
:loading="loading" />

<NcInputField v-else-if="metadata.properties[metadataStore.metadataDataKey].format === 'email'"
:value.sync="metadata.properties[metadataStore.metadataDataKey].default"
type="email"
label="Default waarde (Email)"
:disabled="loading"
:loading="loading" />

<NcInputField v-else-if="metadata.properties[metadataStore.metadataDataKey].format === 'idn-email'"
:value.sync="metadata.properties[metadataStore.metadataDataKey].default"
type="email"
label="Default waarde (Email)"
helper-text="email"
:disabled="loading"
:loading="loading" />

<NcTextField v-else-if="metadata.properties[metadataStore.metadataDataKey].format === 'regex'"
:value.sync="metadata.properties[metadataStore.metadataDataKey].default"
label="Default waarde (Regex)"
:disabled="loading"
:loading="loading" />

<NcInputField v-else-if="metadata.properties[metadataStore.metadataDataKey].format === 'password'"
:value.sync="metadata.properties[metadataStore.metadataDataKey].default"
type="password"
label="Default waarde (Wachtwoord)"
:disabled="loading"
:loading="loading" />

<NcInputField v-else-if="metadata.properties[metadataStore.metadataDataKey].format === 'telephone'"
:value.sync="metadata.properties[metadataStore.metadataDataKey].default"
type="tel"
label="Default waarde (Telefoonnummer)"
:disabled="loading"
:loading="loading" />

<NcTextField v-else
:value.sync="metadata.properties[metadataStore.metadataDataKey].default"
label="Default waarde"
:disabled="loading"
:loading="loading" />
</div>

<!-- TYPE : NUMBER -->
<NcInputField v-else-if="metadata.properties[metadataStore.metadataDataKey].type === 'number'"
:disabled="loading"
type="number"
step="any"
label="Default waarde"
:value.sync="metadata.properties[metadataStore.metadataDataKey].default"
:loading="loading" />
<!-- TYPE : INTEGER -->
<NcInputField v-else-if="metadata.properties[metadataStore.metadataDataKey].type === 'integer'"
:disabled="loading"
type="number"
step="1"
label="Default waarde"
:value.sync="metadata.properties[metadataStore.metadataDataKey].default"
:loading="loading" />
<!-- TYPE : OBJECT -->
<NcTextArea v-else-if="metadata.properties[metadataStore.metadataDataKey].type === 'object'"
:disabled="loading"
label="Default waarde"
:value.sync="metadata.properties[metadataStore.metadataDataKey].default"
:loading="loading" />
<!-- TYPE : ARRAY -->
<NcTextArea v-else-if="metadata.properties[metadataStore.metadataDataKey].type === 'array'"
:disabled="loading"
label="Waarde lijst (split op ,)"
:value.sync="metadata.properties[metadataStore.metadataDataKey].default"
:loading="loading" />
<!-- TYPE : BOOLEAN -->
<NcCheckboxRadioSwitch v-else-if="metadata.properties[metadataStore.metadataDataKey].type === 'boolean'"
:disabled="loading"
:checked.sync="metadata.properties[metadataStore.metadataDataKey].default"
:loading="loading">
Default waarde
</NcCheckboxRadioSwitch>

<!-- TYPE : DICTIONARY -->
<NcTextField v-else-if="metadata.properties[metadataStore.metadataDataKey].type === 'dictionary'"
:disabled="loading"
label="Default waarde"
:value.sync="metadata.properties[metadataStore.metadataDataKey].default" />

Expand Down Expand Up @@ -122,8 +230,8 @@ import { navigationStore, metadataStore } from '../../store/store.js'
</div>
</div>

<NcButton v-if="success === null"
:disabled="loading"
<NcButton v-if="success === null && metadata.properties[metadataStore.metadataDataKey]"
:disabled="!metadata.properties[metadataStore.metadataDataKey].title || !metadata.properties[metadataStore.metadataDataKey].type || loading"
type="primary"
@click="updateMetadata(metadata.id)">
<template #icon>
Expand All @@ -147,6 +255,9 @@ import {
NcCheckboxRadioSwitch,
NcNoteCard,
NcLoadingIcon,
NcDateTimePicker,
NcInputField,
NcTextArea,
} from '@nextcloud/vue'
// icons
Expand All @@ -162,6 +273,9 @@ export default {
NcButton,
NcNoteCard,
NcLoadingIcon,
NcDateTimePicker,
NcInputField,
NcTextArea,
},
data() {
return {
Expand Down Expand Up @@ -190,7 +304,7 @@ export default {
},
dataKey: '',
typeOptions: {
inputLabel: 'Type',
inputLabel: 'Type*',
multiple: false,
options: ['string', 'number', 'integer', 'object', 'array', 'boolean', 'dictionary'],
},
Expand All @@ -206,6 +320,24 @@ export default {
hasUpdated: false,
}
},
computed: {
metadataProperty() {
return Object.assign({}, this.metadata.properties[metadataStore.metadataDataKey] && this.metadata.properties[metadataStore.metadataDataKey])
},
},
watch: {
metadataProperty: {
deep: true,
handler(newVal, oldVal) {
if (newVal.type !== oldVal.type) {
if (newVal.type === 'boolean' && newVal.default === 'true') this.metadata.properties[metadataStore.metadataDataKey].default = true
if (newVal.type === 'boolean' && newVal.default !== 'true') this.metadata.properties[metadataStore.metadataDataKey].default = false
if (newVal.type !== 'boolean' && oldVal.type === 'boolean') this.metadata.properties[metadataStore.metadataDataKey].default = ''
}
},
},
},
updated() {
if (navigationStore.modal === 'editMetadataDataModal' && this.hasUpdated) {
if (this.dataKey !== metadataStore.metadataDataKey) this.hasUpdated = false
Expand Down
Loading

0 comments on commit 66bdcbe

Please sign in to comment.