diff --git a/src/lode/components/AddProperty.vue b/src/lode/components/AddProperty.vue index 38f666a66..5d6f7553a 100644 --- a/src/lode/components/AddProperty.vue +++ b/src/lode/components/AddProperty.vue @@ -508,6 +508,7 @@ export default { this.selectedPropertyToAddIsLangString = false; this.limitedTypes = []; this.limitedConcepts = []; + this.$store.commit('lode/setAddingValues', []); if (this.profile && this.profile[this.selectedPropertyToAdd.value]) { var range = []; var ary = this.profile[this.selectedPropertyToAdd.value]["http://schema.org/rangeIncludes"]; diff --git a/src/lode/components/ThingEditing.vue b/src/lode/components/ThingEditing.vue index f3af5942d..c23772495 100644 --- a/src/lode/components/ThingEditing.vue +++ b/src/lode/components/ThingEditing.vue @@ -842,9 +842,8 @@ export default { saveNewProperty: async function() { // Validate input var property = this.addingProperty; - // Remove unnecessary slash from end of url. github #827 - var value = (this.addingValues.length > 0) ? this.addingValues[0] : undefined; - value = value.endsWith("/") ? value.slice(0, value.length - 1) : value; + // It's possible to accumulate more than one value if user deleted values in textbox. Use the last added value. + var value = (this.addingValues.length > 0) ? this.addingValues[this.addingValues.length - 1] : undefined; var range = this.addingRange; this.errorMessage = []; this.errorMessage = []; diff --git a/src/store/modules/lode.js b/src/store/modules/lode.js index f1dd3e014..25a116577 100644 --- a/src/store/modules/lode.js +++ b/src/store/modules/lode.js @@ -70,15 +70,30 @@ const mutations = { setAddingProperty(state, value) { state.addingProperty = value; }, - setAddingValues(state, value) { - state.addingValues = value; + setAddingValues(state, values) { + let newValues = []; + if (Array.isArray(values)) { + values.forEach((value) => { + if (value) { + let newValue = trimUrl(value); + if (newValue) newValues.push(newValue); + } + }); + } else { + if (values) { + let newValue = trimUrl(values); + if (newValue) newValues.push(newValue); + } + } + state.addingValues = newValues; }, addToAddingValues(state, value) { + let newValue = trimUrl(value); if (!state.addingValues) { state.addingValues = []; - state.addingValues.push(value); - } else { - state.addingValues.push(value); + } + if (newValue) { + state.addingValues.push(newValue); } }, setAddingRange(state, value) { @@ -164,6 +179,29 @@ const getters = { } }; +function trimUrl(url) { + if (!url) { + return undefined; + } + if (url === "" || (url["@value"] && url["@value"] === "")) { + return undefined; + } + let trimmed = url; + if (trimmed["@value"] && typeof trimmed["@value"] === "string" && trimmed["@value"].endsWith("/")) { + trimmed["@value"] = trimmed["@value"].slice(0, trimmed["@value"].length - 2); + } + if (trimmed["@value"] && typeof trimmed["@value"] === "string" && trimmed["@value"].startsWith("/")) { + trimmed["@value"] = trimmed["@value"].slice(1); + } + if (trimmed && typeof trimmed === "string" && trimmed.endsWith("/")) { + trimmed = trimmed.slice(0, trimmed.length - 2); + } + if (trimmed && typeof trimmed === "string" && trimmed.startsWith("/")) { + trimmed = trimmed.slice(1); + } + return trimmed; +} + jsonld.documentLoader = async function(url) { if (url in state.rawSchemata) { return {