Skip to content
Snippets Groups Projects
Commit fb4c4862 authored by Benedikt Heinrichs's avatar Benedikt Heinrichs
Browse files

Fix: Deal with odd list handling

parent 1500b10a
No related tags found
1 merge request!117Fix: List Handling
......@@ -485,8 +485,8 @@ export default defineComponent({
this.initFixedValues();
},
metadata() {
this.initMetadata();
this.setValuesFromMetadataValues();
this.fillMetadata();
},
},
beforeMount() {
......@@ -509,6 +509,15 @@ export default defineComponent({
}
this.setFixedValues(this.values);
},
fillMetadata() {
// Set values if they don't exist
if (!this.values.length) {
const numberOfNewFields = this.isNode ? 0 : 1;
// Setting more than one will not work since a dataset does not support multiple triples
// which are the same ?s ?p ?o
this.insertNewFields(numberOfNewFields);
}
},
initDefaultValues() {
if (
(!this.values.length ||
......@@ -563,13 +572,7 @@ export default defineComponent({
},
initMetadata() {
this.values = [...this.metadataValues];
// Set values if they don't exist
if (!this.values.length) {
const numberOfNewFields = this.isNode ? 0 : 1;
// Setting more than one will not work since a dataset does not support multiple triples
// which are the same ?s ?p ?o
this.insertNewFields(numberOfNewFields);
}
this.fillMetadata();
},
input(values: Quad_Object[], fixedValueTransfer = true) {
this.$emit('input', this.nodeName, values);
......@@ -640,16 +643,49 @@ export default defineComponent({
this.inputFixedValues(currentFixedValueObject);
},
setValuesFromMetadataValues() {
this.values = this.values.filter((entry) =>
// What values will be kept from this.values
const keptValues = this.values.map((entry) =>
this.metadataValues.some(
(metadataEntry) => entry.value === metadataEntry.value
)
? entry
: false
);
// What values are new in this.metadataValues
const newValues = this.metadataValues.filter(
(metadataEntry) =>
!this.values.some((entry) => entry.value === metadataEntry.value)
!keptValues.some(
(entry) => entry !== false && entry.value === metadataEntry.value
)
);
this.values = [...this.values, ...newValues];
let currentAddKey = 0;
const removeKeys: number[] = [];
// Update every value which is not kept with a new value
for (let i = 0; i < this.values.length; i++) {
if (keptValues[i] === false) {
if (currentAddKey < newValues.length) {
this.values[i] = newValues[currentAddKey];
currentAddKey++;
} else {
removeKeys.push(i);
}
}
}
// Add values which have not been added
for (let i = currentAddKey; i < newValues.length; i++) {
this.values.push(newValues[i]);
}
// Create a list with every to keep and new value
const setNewValues: Quad_Object[] = [];
for (let i = 0; i < this.values.length; i++) {
if (!removeKeys.includes(i)) {
setNewValues.push(this.values[i]);
}
}
this.values = setNewValues;
},
triggerValidation() {
this.$emit('triggerValidation');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment