Refactor createChildMetadataGroups to respect children_objects order.
This commit is contained in:
parent
ac9e82002f
commit
b0b8620fad
|
@ -163,49 +163,43 @@
|
||||||
|
|
||||||
if (childItemMetadata && childItemMetadata.length) {
|
if (childItemMetadata && childItemMetadata.length) {
|
||||||
|
|
||||||
// Loads the existing values
|
for (let childMetadatum of this.itemMetadatum.metadatum.metadata_type_options.children_objects) {
|
||||||
for (let childIndex = 0; childIndex < childItemMetadata.length; childIndex++) {
|
|
||||||
const childItemMetadatum = childItemMetadata[childIndex];
|
|
||||||
const childMetadatum = this.itemMetadatum.metadatum.metadata_type_options.children_objects.find((aMetadatum) => aMetadatum.id == childItemMetadatum.metadatum_id);
|
|
||||||
|
|
||||||
existingChildItemMetadata.push({
|
const childItemMetadatumIndex = childItemMetadata.findIndex((aChildItemMetadatum) => childMetadatum.id == aChildItemMetadatum.metadatum_id);
|
||||||
item: this.itemMetadatum.item,
|
// Loads the existing values
|
||||||
metadatum: childMetadatum,
|
if (childItemMetadatumIndex >= 0) {
|
||||||
parent_meta_id: childItemMetadatum.parent_meta_id,
|
const childItemMetadatum = childItemMetadata[childItemMetadatumIndex];
|
||||||
value: childItemMetadatum.value,
|
existingChildItemMetadata.push({
|
||||||
value_as_html: childItemMetadatum.value_as_html,
|
item: this.itemMetadatum.item,
|
||||||
value_as_string: childItemMetadatum.value_as_string,
|
metadatum: childMetadatum,
|
||||||
collapse: this.childItemMetadataGroups[groupIndex] && this.childItemMetadataGroups[groupIndex][childIndex] ? this.childItemMetadataGroups[groupIndex][childIndex].collapse : (this.collapseAllChildren ? this.collapseAllChildren : false)
|
parent_meta_id: childItemMetadatum.parent_meta_id,
|
||||||
})
|
value: childItemMetadatum.value,
|
||||||
}
|
value_as_html: childItemMetadatum.value_as_html,
|
||||||
|
value_as_string: childItemMetadatum.value_as_string,
|
||||||
// If some have empty childs, we need to create their input
|
collapse: this.childItemMetadataGroups[groupIndex] && this.childItemMetadataGroups[groupIndex][childItemMetadatumIndex] ? this.childItemMetadataGroups[groupIndex][childItemMetadatumIndex].collapse : (this.collapseAllChildren ? this.collapseAllChildren : false)
|
||||||
if (childItemMetadata.length < this.itemMetadatum.metadatum.metadata_type_options.children_objects.length) {
|
})
|
||||||
const existingParentMetaIdIndex = childItemMetadata.findIndex((anItemMetadatum) => anItemMetadatum.parent_meta_id > 0);
|
// Creates inputs for non existing ones
|
||||||
|
} else {
|
||||||
for (let child of this.itemMetadatum.metadatum.metadata_type_options.children_objects) {
|
const existingParentMetaIdIndex = childItemMetadata.findIndex((aChildItemMetadatum) => aChildItemMetadatum.parent_meta_id > 0);
|
||||||
|
existingChildItemMetadata.push({
|
||||||
const existingValueIndex = childItemMetadata.findIndex((anItemMetadatum) => anItemMetadatum.metadatum_id == child.id);
|
item: this.itemMetadatum.item,
|
||||||
if (existingValueIndex < 0) {
|
metadatum: childMetadatum,
|
||||||
existingChildItemMetadata.push({
|
parent_meta_id: existingParentMetaIdIndex >= 0 ? childItemMetadata[existingParentMetaIdIndex].parent_meta_id : 0,
|
||||||
item: this.itemMetadatum.item,
|
value: '',
|
||||||
metadatum: child,
|
value_as_html: '',
|
||||||
parent_meta_id: existingParentMetaIdIndex >= 0 ? childItemMetadata[existingParentMetaIdIndex].parent_meta_id : 0,
|
value_as_string: '',
|
||||||
value: '',
|
collapse: this.collapseAllChildren ? this.collapseAllChildren : false
|
||||||
value_as_html: '',
|
});
|
||||||
value_as_string: '',
|
|
||||||
collapse: this.collapseAllChildren ? this.collapseAllChildren : false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// A new input for each type of child metadatum
|
// A new input for each type of child metadatum
|
||||||
for (let child of this.itemMetadatum.metadatum.metadata_type_options.children_objects) {
|
for (let childMetadatum of this.itemMetadatum.metadatum.metadata_type_options.children_objects) {
|
||||||
let childObject = {
|
let childObject = {
|
||||||
item: this.itemMetadatum.item,
|
item: this.itemMetadatum.item,
|
||||||
metadatum: child,
|
metadatum: childMetadatum,
|
||||||
parent_meta_id: '0',
|
parent_meta_id: '0',
|
||||||
value: '',
|
value: '',
|
||||||
value_as_html: '',
|
value_as_html: '',
|
||||||
|
@ -250,10 +244,10 @@
|
||||||
this.itemMetadatum.metadatum.metadata_type_options &&
|
this.itemMetadatum.metadatum.metadata_type_options &&
|
||||||
this.itemMetadatum.metadatum.metadata_type_options.children_objects.length > 0
|
this.itemMetadatum.metadatum.metadata_type_options.children_objects.length > 0
|
||||||
) {
|
) {
|
||||||
for (let child of this.itemMetadatum.metadatum.metadata_type_options.children_objects) {
|
for (let childMetadatum of this.itemMetadatum.metadatum.metadata_type_options.children_objects) {
|
||||||
let childObject = {
|
let childObject = {
|
||||||
item: this.itemMetadatum.item,
|
item: this.itemMetadatum.item,
|
||||||
metadatum: child,
|
metadatum: childMetadatum,
|
||||||
parent_meta_id: parentMetaId,
|
parent_meta_id: parentMetaId,
|
||||||
value: '',
|
value: '',
|
||||||
value_as_html: '',
|
value_as_html: '',
|
||||||
|
|
Loading…
Reference in New Issue