Fix issues with tree sorting

- Need to set parent ID based on the BOM items
- This is to prevent data duplication that was weird and dumb
This commit is contained in:
Oliver Walters 2020-08-18 21:24:11 +10:00
parent 82903d2bd6
commit 1767ef7a3a

View File

@ -280,48 +280,34 @@ function loadBomTable(table, options) {
params.sub_part_detail = true; params.sub_part_detail = true;
} }
function requestBomItems() { function requestSubItems(part_pk) {
var data = table.bootstrapTable('getData'); inventreeGet(
options.bom_url,
for (var idx = 0; idx < data.length; idx++) { {
var row = data[idx]; part: part_pk,
sub_part_detail: true,
if (row.sub_part_detail.assembly && !row.requested) { },
{
row.requested = true; success: function(response) {
for (var idx = 0; idx < response.length; idx++) {
// Mark this row as 'requested' so it doesn't get updated again response[idx].parentId = part_pk;
table.bootstrapTable('updateRow', idx, row, true);
inventreeGet(
options.bom_url,
{
part: row.sub_part,
sub_part_detail: true,
},
{
success: function(response) {
// Add the data to the table
table.bootstrapTable('append', response);
// Request any NEW sub BOMs
requestBomItems();
},
error: function() {
console.log('Error requesting BOM for part=' + row.sub_part);
}
} }
);
table.bootstrapTable('append', response);
},
error: function() {
console.log('Error requesting BOM for part=' + part_pk);
}
} }
} )
} }
table.bootstrapTable({ table.bootstrapTable({
treeEnable: true, treeEnable: true,
rootParentId: options.parent_id, rootParentId: options.parent_id,
idField: 'sub_part', idField: 'sub_part',
uniqueId: 'pk',
parentIdField: 'part', parentIdField: 'part',
treeShowField: 'sub_part', treeShowField: 'sub_part',
sortable: true, sortable: true,
@ -347,7 +333,28 @@ function loadBomTable(table, options) {
} }
}); });
}, },
onLoadSuccess: requestBomItems, onLoadSuccess: function() {
var data = table.bootstrapTable('getData');
for (var idx = 0; idx < data.length; idx++) {
var row = data[idx];
// If a row already has a parent ID set, it's already been updated!
if (row.parentId) {
continue;
}
// Set the parent ID of the top-level rows
row.parentId = options.parent_id;
table.bootstrapTable('updateRow', idx, row, true);
if (row.sub_part_detail.assembly) {
requestSubItems(row.sub_part);
}
}
},
}); });
// In editing mode, attached editables to the appropriate table elements // In editing mode, attached editables to the appropriate table elements