mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
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:
parent
82903d2bd6
commit
1767ef7a3a
@ -280,48 +280,34 @@ function loadBomTable(table, options) {
|
||||
params.sub_part_detail = true;
|
||||
}
|
||||
|
||||
function requestBomItems() {
|
||||
|
||||
var data = table.bootstrapTable('getData');
|
||||
|
||||
for (var idx = 0; idx < data.length; idx++) {
|
||||
var row = data[idx];
|
||||
|
||||
if (row.sub_part_detail.assembly && !row.requested) {
|
||||
|
||||
row.requested = true;
|
||||
|
||||
// Mark this row as 'requested' so it doesn't get updated again
|
||||
table.bootstrapTable('updateRow', idx, row, true);
|
||||
function requestSubItems(part_pk) {
|
||||
|
||||
inventreeGet(
|
||||
options.bom_url,
|
||||
{
|
||||
part: row.sub_part,
|
||||
part: part_pk,
|
||||
sub_part_detail: true,
|
||||
},
|
||||
{
|
||||
success: function(response) {
|
||||
for (var idx = 0; idx < response.length; idx++) {
|
||||
response[idx].parentId = part_pk;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
);
|
||||
console.log('Error requesting BOM for part=' + part_pk);
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
table.bootstrapTable({
|
||||
treeEnable: true,
|
||||
rootParentId: options.parent_id,
|
||||
idField: 'sub_part',
|
||||
uniqueId: 'pk',
|
||||
parentIdField: 'part',
|
||||
treeShowField: 'sub_part',
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user