From e21d6811b60ae9dd4bd9fef79cea55f550b1eaf4 Mon Sep 17 00:00:00 2001 From: Thijn Date: Mon, 12 Aug 2024 13:01:12 +0200 Subject: [PATCH] finished metadata properties being null Dit was veel stoeien met Typescript --- src/entities/metadata/metadata.ts | 19 ++++++++++++++++++ .../metaData/AddMetaDataPropertyModal.vue | 20 ++++++++++++++++--- .../metaData/EditMetaDataPropertyModal.vue | 14 ++++++------- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/entities/metadata/metadata.ts b/src/entities/metadata/metadata.ts index d668ce4b..a48c0109 100644 --- a/src/entities/metadata/metadata.ts +++ b/src/entities/metadata/metadata.ts @@ -52,6 +52,25 @@ export class Metadata implements TMetadata { valuation: 'n', class: 1, } + + // convert null's to the respective default value from predefined list of props + Object.keys(this.properties).forEach(obj => { + const defaultPropertiesProps = { + minimum: 0, + maximum: 0, + multipleOf: 0, + minItems: 0, + maxItems: 0, + minLength: 0, + maxLength: 0, + } as Pick + + Object.keys(defaultPropertiesProps).forEach((key: keyof typeof defaultPropertiesProps) => { + if (this.properties[obj][key] === null) { + this.properties[obj][key] = defaultPropertiesProps[key] + } + }) + }) } /* istanbul ignore next */ diff --git a/src/modals/metaData/AddMetaDataPropertyModal.vue b/src/modals/metaData/AddMetaDataPropertyModal.vue index 1ed900a9..0b2b0ef3 100644 --- a/src/modals/metaData/AddMetaDataPropertyModal.vue +++ b/src/modals/metaData/AddMetaDataPropertyModal.vue @@ -213,8 +213,6 @@ export default { }, methods: { AddMetadata() { - metadataStore.metaDataItem.properties[this.properties.title] = this.properties - this.loading = true fetch( `/index.php/apps/opencatalogi/api/metadata/${metadataStore.metaDataItem.id}`, @@ -223,7 +221,23 @@ export default { headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify(metadataStore.metaDataItem), + body: JSON.stringify({ + ...metadataStore.metaDataItem, + properties: { // due to bad (no) support for number fields inside nextcloud/vue, parse the text to a number + ...metadataStore.metaDataItem.properties, + [this.properties.title]: { + ...this.properties, + pattern: parseFloat(this.properties.pattern) || 0, + minLength: parseFloat(this.properties.minLength) || null, + maxLength: parseFloat(this.properties.maxLength) || null, + minimum: parseFloat(this.properties.minimum) || null, + maximum: parseFloat(this.properties.maximum) || null, + multipleOf: parseFloat(this.properties.multipleOf) || null, + minItems: parseFloat(this.properties.minItems) || null, + maxItems: parseFloat(this.properties.maxItems) || null, + }, + }, + }), }, ) .then((response) => { diff --git a/src/modals/metaData/EditMetaDataPropertyModal.vue b/src/modals/metaData/EditMetaDataPropertyModal.vue index 40fba50c..d3f20c07 100644 --- a/src/modals/metaData/EditMetaDataPropertyModal.vue +++ b/src/modals/metaData/EditMetaDataPropertyModal.vue @@ -252,13 +252,13 @@ export default { [metadataStore.metadataDataKey]: { ...this.metadata.properties[metadataStore.metadataDataKey], pattern: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].pattern) || 0, - minLength: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].minLength) || 0, - maxLength: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].maxLength) || 0, - minimum: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].minimum) || 0, - maximum: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].maximum) || 0, - multipleOf: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].multipleOf) || 0, - minItems: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].minItems) || 0, - maxItems: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].maxItems) || 0, + minLength: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].minLength) || null, + maxLength: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].maxLength) || null, + minimum: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].minimum) || null, + maximum: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].maximum) || null, + multipleOf: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].multipleOf) || null, + minItems: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].minItems) || null, + maxItems: parseFloat(this.metadata.properties[metadataStore.metadataDataKey].maxItems) || null, }, }, }),