From 3c224e02d9a27e9da2e0c5c00fe670f2458eddfa Mon Sep 17 00:00:00 2001 From: Severino Date: Tue, 6 Aug 2024 16:44:04 +0200 Subject: [PATCH] Fixed reset --- resources/js/api.js | 54 +++++++++---------- .../js/components/attribute/Attribute.vue | 11 ++-- resources/js/components/attribute/Entity.vue | 1 + .../js/components/attribute/SingleChoice.vue | 8 +-- resources/js/components/attribute/Tabular.vue | 15 +----- 5 files changed, 39 insertions(+), 50 deletions(-) diff --git a/resources/js/api.js b/resources/js/api.js index 760ff718..62ed7bac 100644 --- a/resources/js/api.js +++ b/resources/js/api.js @@ -97,8 +97,8 @@ export async function removePlugin(id) { } export async function fetchEntityMetadata(id) { - const {data} = await $httpQueue.add(() => http.get(`entity/${id}/metadata`)); - store.dispatch('updateEntityMetadata', {eid: id, data}); + const { data } = await $httpQueue.add(() => http.get(`entity/${id}/metadata`)); + store.dispatch('updateEntityMetadata', { eid: id, data }); return data; } @@ -270,7 +270,7 @@ async function fetchComments(id, type, aid = null) { if(!!aid) { endpoint = `${endpoint}&aid=${aid}`; } - return $httpQueue.add(() => http.get(endpoint).then(response => response.data).catch(error => {throw error;})); + return $httpQueue.add(() => http.get(endpoint).then(response => response.data).catch(error => { throw error; })); } export async function exportBibtexFile(selection) { @@ -358,7 +358,7 @@ export async function resetUserPassword(uid, password) { } export async function confirmUserPassword(uid, password = null) { - const data = !!password ? {password: password} : {}; + const data = !!password ? { password: password } : {}; return $httpQueue.add( () => http.patch(`user/${uid}/password/confirm`, data).then(response => response.data) ); @@ -482,7 +482,7 @@ export async function duplicateEntity(entity) { export async function importEntityData(data) { return $httpQueue.add( - () => http.post(`/entity/import`, data).then(response => response.data).catch(e => {throw e;}) + () => http.post(`/entity/import`, data).then(response => response.data).catch(e => { throw e; }) ); } @@ -525,29 +525,29 @@ export async function addAttribute(attribute) { data.restricted_types = attribute.restrictedTypes.map(t => t.id); } if(attribute.columns && attribute.columns.length > 0) { - data.columns = attribute.columns.map(c => { - const mappedC = {...c}; - if(mappedC.label) { - mappedC.label_id = mappedC.label.id; - delete mappedC.label; + data.columns = attribute.columns.map(column => { + const mappedColumn = { ...column }; + if(mappedColumn.label) { + mappedColumn.label_id = mappedColumn.label.id; + delete mappedColumn.label; } - if(mappedC.rootLabel) { - mappedC.root_id = mappedC.rootLabel.id; - delete mappedC.rootLabel; + if(mappedColumn.rootLabel) { + mappedColumn.root_id = mappedColumn.rootLabel.id; + delete mappedColumn.rootLabel; } - if(mappedC.restrictedTypes) { - mappedC.restricted_types = mappedC.restrictedTypes.map(t => t.id); - delete mappedC.restrictedTypes; + if(mappedColumn.restrictedTypes) { + mappedColumn.restricted_types = mappedColumn.restrictedTypes.map(t => t.id); + delete mappedColumn.restrictedTypes; } - if(mappedC.siGroup) { - mappedC.si_base = mappedC.siGroup; - mappedC.si_default = mappedC.siGroupUnit; - delete mappedC.siGroup; - delete mappedC.siGroupUnit; + if(mappedColumn.siGroup) { + mappedColumn.si_base = mappedColumn.siGroup; + mappedColumn.si_default = mappedColumn.siGroupUnit; + delete mappedColumn.siGroup; + delete mappedColumn.siGroupUnit; } - mappedC.datatype = mappedC.type; - delete mappedC.type; - return mappedC; + mappedColumn.datatype = mappedColumn.type; + delete mappedColumn.type; + return mappedColumn; }); } if(attribute.textContent) { @@ -640,7 +640,7 @@ export async function patchEntityName(eid, name) { export async function patchEntityMetadata(eid, metadata) { return $httpQueue.add( - () => http.patch(`entity/${eid}/metadata`, metadata).then(response => response.data).catch(error => {throw error;}) + () => http.patch(`entity/${eid}/metadata`, metadata).then(response => response.data).catch(error => { throw error; }) ); } @@ -652,7 +652,7 @@ export async function patchAttribute(entityId, attributeId, data) { export async function patchAttributes(entityId, data) { return $httpQueue.add( - () => http.patch(`/entity/${entityId}/attributes`, data).then(response => response.data).catch(error => {throw error;}) + () => http.patch(`/entity/${entityId}/attributes`, data).then(response => response.data).catch(error => { throw error; }) ); } @@ -681,7 +681,7 @@ export async function handleModeration(modAction, entity_id, attribute_id, overw }); } return response.data; - }).catch(error => {throw error;}) + }).catch(error => { throw error; }) ); } diff --git a/resources/js/components/attribute/Attribute.vue b/resources/js/components/attribute/Attribute.vue index 8a417b8f..17ad1ef9 100644 --- a/resources/js/components/attribute/Attribute.vue +++ b/resources/js/components/attribute/Attribute.vue @@ -255,6 +255,7 @@ import { getAttributeSelection, getEmptyAttributeValue, + _cloneDeep, } from '@/helpers/helpers.js'; import StringAttr from '@/components/attribute/String.vue'; @@ -357,12 +358,16 @@ disabled, } = toRefs(props); // FETCH + + const getValueOrDefault = _ => { + return valueWrapper.value.value || getEmptyAttributeValue(data.value.datatype); + }; const attrRef = ref({}); const state = reactive({ type: computed(_ => data.value.datatype), disabled: computed(_ => data.value.isDisabled || disabled.value), - value: computed(_ => getValueOrDefault()), + value: _cloneDeep(getValueOrDefault()), // TODO check for selection need? selection: computed(_ => getAttributeSelection(data.value.id) || []), @@ -397,10 +402,6 @@ } }; - const getValueOrDefault = _ => { - return valueWrapper.value.value || getEmptyAttributeValue(state.type); - }; - const undirtyField = _ => { if(attrRef.value && attrRef.value.undirtyField) { attrRef.value.undirtyField(); diff --git a/resources/js/components/attribute/Entity.vue b/resources/js/components/attribute/Entity.vue index ca5abe4c..b79eb46a 100644 --- a/resources/js/components/attribute/Entity.vue +++ b/resources/js/components/attribute/Entity.vue @@ -8,6 +8,7 @@ :disabled="disabled" @selected="e => entitySelected(e)" @entry-click="e => entryClicked(e)" + @deselect="v.handleChange(null)" /> +f