mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
Build filters (#4773)
* Add optional callback to table filtering function * Add custom filters to build item table
This commit is contained in:
parent
434a00b55f
commit
09083d2de1
@ -117,12 +117,6 @@ src="{% static 'img/blank_image.png' %}"
|
|||||||
{% trans "No build outputs have been created for this build order" %}<br>
|
{% trans "No build outputs have been created for this build order" %}<br>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if build.parent %}
|
|
||||||
<div class='alert alert-block alert-info'>
|
|
||||||
{% object_link 'build-detail' build.parent.id build.parent as link %}
|
|
||||||
{% blocktrans %}This Build Order is a child of Build Order {{link}}{% endblocktrans %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if build.active %}
|
{% if build.active %}
|
||||||
{% if build.can_complete %}
|
{% if build.can_complete %}
|
||||||
|
@ -1461,16 +1461,58 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var table = options.table;
|
// Apply filters to build table
|
||||||
|
// As the table is constructed locally, we can apply filters directly
|
||||||
|
function filterBuildAllocationTable(filters={}) {
|
||||||
|
$(table).bootstrapTable(
|
||||||
|
'filterBy',
|
||||||
|
filters,
|
||||||
|
{
|
||||||
|
'filterAlgorithm': function(row, filters) {
|
||||||
|
let result = true;
|
||||||
|
|
||||||
if (options.table == null) {
|
if (!filters) {
|
||||||
table = `#allocation-table-${outputId}`;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter by 'consumable' flag
|
||||||
|
if ('consumable' in filters) {
|
||||||
|
result &= filters.consumable == '1' ? row.consumable : !row.consumable;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter by 'optional' flag
|
||||||
|
if ('optional' in filters) {
|
||||||
|
result &= filters.optional == '1' ? row.optional : !row.optional;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter by 'allocated' flag
|
||||||
|
if ('allocated' in filters) {
|
||||||
|
let fully_allocated = row.consumable || isRowFullyAllocated(row);
|
||||||
|
result &= filters.allocated == '1' ? fully_allocated : !fully_allocated;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter by 'available' flag
|
||||||
|
if ('available' in filters) {
|
||||||
|
let available = row.available_stock > 0;
|
||||||
|
result &= filters.available == '1' ? available : !available;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var table = options.table || `#allocation-table-${outputId}`;
|
||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
let filters = loadTableFilters('builditems', options.params);
|
let filters = loadTableFilters('builditems', options.params);
|
||||||
|
|
||||||
setupFilterList('builditems', $(table), options.filterTarget);
|
setupFilterList('builditems', $(table), options.filterTarget, {
|
||||||
|
callback: function(table, filters, options) {
|
||||||
|
filterBuildAllocationTable(filters);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var allocated_items = output == null ? null : output.allocations;
|
var allocated_items = output == null ? null : output.allocations;
|
||||||
|
|
||||||
@ -1685,6 +1727,9 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
|
|||||||
search: options.search || false,
|
search: options.search || false,
|
||||||
queryParams: filters,
|
queryParams: filters,
|
||||||
original: options.params,
|
original: options.params,
|
||||||
|
onRefresh: function(data) {
|
||||||
|
filterBuildAllocationTable(filters);
|
||||||
|
},
|
||||||
onPostBody: function(data) {
|
onPostBody: function(data) {
|
||||||
// Setup button callbacks
|
// Setup button callbacks
|
||||||
setupCallbacks();
|
setupCallbacks();
|
||||||
@ -2037,6 +2082,8 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
filterBuildAllocationTable(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -429,7 +429,7 @@ function setupFilterList(tableKey, table, target, options={}) {
|
|||||||
|
|
||||||
// Callback for reloading the table
|
// Callback for reloading the table
|
||||||
element.find(`#reload-${tableKey}`).click(function() {
|
element.find(`#reload-${tableKey}`).click(function() {
|
||||||
reloadTableFilters(table);
|
reloadTableFilters(table, {}, options);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add a callback for downloading table data
|
// Add a callback for downloading table data
|
||||||
@ -472,7 +472,7 @@ function setupFilterList(tableKey, table, target, options={}) {
|
|||||||
// Only add the new filter if it is not empty!
|
// Only add the new filter if it is not empty!
|
||||||
if (tag && tag.length > 0) {
|
if (tag && tag.length > 0) {
|
||||||
var filters = addTableFilter(tableKey, tag, val);
|
var filters = addTableFilter(tableKey, tag, val);
|
||||||
reloadTableFilters(table, filters);
|
reloadTableFilters(table, filters, options);
|
||||||
|
|
||||||
// Run this function again
|
// Run this function again
|
||||||
setupFilterList(tableKey, table, target, options);
|
setupFilterList(tableKey, table, target, options);
|
||||||
@ -491,8 +491,7 @@ function setupFilterList(tableKey, table, target, options={}) {
|
|||||||
element.find(`#${clear}`).click(function() {
|
element.find(`#${clear}`).click(function() {
|
||||||
var filters = clearTableFilters(tableKey);
|
var filters = clearTableFilters(tableKey);
|
||||||
|
|
||||||
reloadTableFilters(table, filters);
|
reloadTableFilters(table, filters, options);
|
||||||
|
|
||||||
setupFilterList(tableKey, table, target, options);
|
setupFilterList(tableKey, table, target, options);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -504,7 +503,7 @@ function setupFilterList(tableKey, table, target, options={}) {
|
|||||||
|
|
||||||
var filters = removeTableFilter(tableKey, filter);
|
var filters = removeTableFilter(tableKey, filter);
|
||||||
|
|
||||||
reloadTableFilters(table, filters);
|
reloadTableFilters(table, filters, options);
|
||||||
|
|
||||||
// Run this function again!
|
// Run this function again!
|
||||||
setupFilterList(tableKey, table, target, options);
|
setupFilterList(tableKey, table, target, options);
|
||||||
|
@ -459,6 +459,29 @@ function getBuildTableFilters() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Return a dictionary of filters for the "build item" table
|
||||||
|
function getBuildItemTableFilters() {
|
||||||
|
return {
|
||||||
|
allocated: {
|
||||||
|
type: 'bool',
|
||||||
|
title: '{% trans "Allocated" %}',
|
||||||
|
},
|
||||||
|
available: {
|
||||||
|
type: 'bool',
|
||||||
|
title: '{% trans "Available" %}',
|
||||||
|
},
|
||||||
|
consumable: {
|
||||||
|
type: 'bool',
|
||||||
|
title: '{% trans "Consumable" %}',
|
||||||
|
},
|
||||||
|
optional: {
|
||||||
|
type: 'bool',
|
||||||
|
title: '{% trans "Optional" %}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return a dictionary of filters for the "purchase order line item" table
|
// Return a dictionary of filters for the "purchase order line item" table
|
||||||
function getPurchaseOrderLineItemFilters() {
|
function getPurchaseOrderLineItemFilters() {
|
||||||
return {
|
return {
|
||||||
@ -682,6 +705,8 @@ function getAvailableTableFilters(tableKey) {
|
|||||||
return getBOMTableFilters();
|
return getBOMTableFilters();
|
||||||
case 'build':
|
case 'build':
|
||||||
return getBuildTableFilters();
|
return getBuildTableFilters();
|
||||||
|
case 'builditems':
|
||||||
|
return getBuildItemTableFilters();
|
||||||
case 'location':
|
case 'location':
|
||||||
return getStockLocationFilters();
|
return getStockLocationFilters();
|
||||||
case 'parts':
|
case 'parts':
|
||||||
|
@ -247,7 +247,13 @@ function isNumeric(n) {
|
|||||||
* Reload a table which has already been made into a bootstrap table.
|
* Reload a table which has already been made into a bootstrap table.
|
||||||
* New filters can be optionally provided, to change the query params.
|
* New filters can be optionally provided, to change the query params.
|
||||||
*/
|
*/
|
||||||
function reloadTableFilters(table, filters) {
|
function reloadTableFilters(table, filters, options={}) {
|
||||||
|
|
||||||
|
// If a callback is specified, let's use that
|
||||||
|
if (options.callback) {
|
||||||
|
options.callback(table, filters, options);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Simply perform a refresh
|
// Simply perform a refresh
|
||||||
if (filters == null) {
|
if (filters == null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user