From 79e8e34eafe78a965273e035b4ba4980d2b26ac7 Mon Sep 17 00:00:00 2001 From: Stefan Peters Date: Thu, 25 Jun 2020 10:40:06 +0200 Subject: [PATCH] Deleting a mapping should clear the is-mapped indicator (#558) --- src/mixins/cdk.js | 22 +++++++++++++++++++--- src/mixins/mapped-status.js | 2 +- src/store/index.js | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/mixins/cdk.js b/src/mixins/cdk.js index c46106c8e..a130f3433 100644 --- a/src/mixins/cdk.js +++ b/src/mixins/cdk.js @@ -536,13 +536,13 @@ export default { this.$set(concept, "__MAPPED__", []) } const existing = concept.__MAPPED__.find(item => jskos.compare(item.registry, registry) && jskos.compare(item.scheme, targetScheme)) - if (existing && !existing.exist) { - existing.exist = true + if (existing && !existing.exist.length) { + existing.exist.push(mapping.uri) } else if (!existing) { concept.__MAPPED__.push({ registry, scheme: targetScheme, - exist: true, + exist: [mapping.uri], }) } } @@ -812,6 +812,22 @@ export default { // Set original to null this.$store.commit({ type: "mapping/set" }) } + // 3. Adjust __MAPPED__ property of conceps in mapping + if (jskos.mappingRegistryIsStored(registry)) { + for (let [from, to] of [["from", "to"], ["to", "from"]]) { + const targetScheme = mapping[`${to}Scheme`] + const sourceConcepts = jskos.conceptsOfMapping(mapping, from) + if (targetScheme) { + for (let concept of sourceConcepts) { + const existing = (concept.__MAPPED__ || []).find(item => jskos.compare(item.registry, registry) && jskos.compare(item.scheme, targetScheme)) + if (!existing || !existing.exist.length) { + continue + } + this.$set(existing, "exist", existing.exist.filter(uri => uri != mapping.uri)) + } + } + } + } }, canCreateMapping({ registry, mapping, user = this.user }) { if (!mapping || !registry) { diff --git a/src/mixins/mapped-status.js b/src/mixins/mapped-status.js index 0c287e5b1..abe2e31c4 100644 --- a/src/mixins/mapped-status.js +++ b/src/mixins/mapped-status.js @@ -59,7 +59,7 @@ export default { concept.__MAPPED__.push({ registry, scheme: otherScheme, - exist: false, + exist: [], }) } }) diff --git a/src/store/index.js b/src/store/index.js index a023666b6..19feeb176 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -87,7 +87,7 @@ const getters = { * Returns the mapped status for a concept. */ mappedStatus: (state) => (concept, isLeft) => { - return !!_.get(concept, "__MAPPED__", []).find(item => item.exist && jskos.compare(item.registry, getters.getCurrentRegistry(state)) && jskos.compare(item.scheme, state.selected.scheme[!isLeft])) + return !!_.get(concept, "__MAPPED__", []).find(item => item.exist.length && jskos.compare(item.registry, getters.getCurrentRegistry(state)) && jskos.compare(item.scheme, state.selected.scheme[!isLeft])) }, languages: (state) => { const defaultLanguages = ["en", "de"]