mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Display a list of filters for Stock table
- Delete a filter by pressing "X" button
This commit is contained in:
parent
5aa43a5a18
commit
5d141a0b98
@ -157,6 +157,62 @@
|
|||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dropdown {
|
||||||
|
padding-left: 1px;
|
||||||
|
margin-left: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Styles for table buttons and filtering */
|
||||||
|
.button-toolbar .btn {
|
||||||
|
margin-left: 1px;
|
||||||
|
margin-right: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filters {
|
||||||
|
display: inline-block;
|
||||||
|
*display: inline;
|
||||||
|
border: 1px solid #555;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 3px;
|
||||||
|
margin-bottom: 1px;
|
||||||
|
margin-top: 1px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-list {
|
||||||
|
margin: 1px;
|
||||||
|
padding: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-list .close {
|
||||||
|
cursor: pointer;
|
||||||
|
right: 0%;
|
||||||
|
padding-right: 2px;
|
||||||
|
padding-left: 2px;
|
||||||
|
transform: translate(0%, -25%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-list .close:hover {background: #bbb;}
|
||||||
|
|
||||||
|
.filter-list > li {
|
||||||
|
display: inline-block;
|
||||||
|
*display: inline;
|
||||||
|
zoom: 1;
|
||||||
|
padding-left: 3px;
|
||||||
|
padding-right: 3px;
|
||||||
|
padding-top: 2px;
|
||||||
|
padding-bottom: 2px;
|
||||||
|
border: 1px solid;
|
||||||
|
border-color: #aaa;
|
||||||
|
border-radius: 3px;
|
||||||
|
background: #eee;
|
||||||
|
margin: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-list > li:hover {
|
||||||
|
background: #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
/* Part image icons with full-display on mouse hover */
|
/* Part image icons with full-display on mouse hover */
|
||||||
|
|
||||||
.hover-img-thumb {
|
.hover-img-thumb {
|
||||||
|
@ -14,10 +14,33 @@ function getStockLocations(filters={}, options={}) {
|
|||||||
return inventreeGet('/api/stock/location/', filters, options)
|
return inventreeGet('/api/stock/location/', filters, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A map of available filters for the stock table
|
||||||
|
function getStockFilterOptions() {
|
||||||
|
return {
|
||||||
|
'cascade': {
|
||||||
|
'type': 'bool',
|
||||||
|
},
|
||||||
|
'status': {
|
||||||
|
'options': {
|
||||||
|
'OK': 10,
|
||||||
|
'ATTENTION': 50,
|
||||||
|
'DAMAGED': 55,
|
||||||
|
'DESTROYED': 60,
|
||||||
|
'LOST': 70
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function loadStockFilters() {
|
function loadStockFilters() {
|
||||||
// Load the stock table filters from session-storage
|
// Load the stock table filters from session-storage
|
||||||
var filterstring = inventreeLoad("stockfilters", "cascade=true&loc=1");
|
var filterstring = inventreeLoad("stockfilters", "cascade=true&loc=1");
|
||||||
|
|
||||||
|
if (filterstring.length == 0) {
|
||||||
|
filterstring = 'cascade=true&test=1&location=10&status=50';
|
||||||
|
}
|
||||||
|
|
||||||
var split = filterstring.split("&");
|
var split = filterstring.split("&");
|
||||||
|
|
||||||
var filters = {};
|
var filters = {};
|
||||||
@ -25,12 +48,15 @@ function loadStockFilters() {
|
|||||||
console.log("Loaded stock filters: " + filterstring);
|
console.log("Loaded stock filters: " + filterstring);
|
||||||
|
|
||||||
split.forEach(function(item, index) {
|
split.forEach(function(item, index) {
|
||||||
var f = item.split('=');
|
|
||||||
|
|
||||||
if (f.length == 2) {
|
if (item.length > 0) {
|
||||||
filters[f[0]] = f[1];
|
var f = item.split('=');
|
||||||
} else {
|
|
||||||
console.log("Improperly formatted filter: " + item);
|
if (f.length == 2) {
|
||||||
|
filters[f[0]] = f[1];
|
||||||
|
} else {
|
||||||
|
console.log("Improperly formatted filter: " + item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -54,6 +80,41 @@ function saveStockFilters(filters) {
|
|||||||
inventreeSave("stockfilters", filterstring);
|
inventreeSave("stockfilters", filterstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeStockFilter(key) {
|
||||||
|
|
||||||
|
var filters = loadStockFilters();
|
||||||
|
|
||||||
|
delete filters[key];
|
||||||
|
|
||||||
|
saveStockFilters(filters);
|
||||||
|
|
||||||
|
return filters;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function updateStockFilterList(filterListElement, filters, table, params) {
|
||||||
|
|
||||||
|
for (var key in filters) {
|
||||||
|
$(filterListElement).append(`<li>${key} = ${filters[key]}<span filter-tag='${key}' class='close'>x</span></li>` );
|
||||||
|
}
|
||||||
|
|
||||||
|
$(filterListElement).find(".close").click(function() {
|
||||||
|
var element = $(this);
|
||||||
|
|
||||||
|
var tag = element.attr('filter-tag');
|
||||||
|
|
||||||
|
// Clear out any existing elements
|
||||||
|
$(filterListElement).empty();
|
||||||
|
|
||||||
|
var filters = removeStockFilter(tag);
|
||||||
|
|
||||||
|
updateStockFilterList(filterListElement, filters);
|
||||||
|
|
||||||
|
// TODO - Reload data in table?
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("done");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Functions for interacting with stock management forms
|
/* Functions for interacting with stock management forms
|
||||||
@ -80,13 +141,18 @@ function loadStockTable(table, options) {
|
|||||||
* params - query params for augmenting stock data request
|
* params - query params for augmenting stock data request
|
||||||
* groupByField - Column for grouping stock items
|
* groupByField - Column for grouping stock items
|
||||||
* buttons - Which buttons to link to stock selection callbacks
|
* buttons - Which buttons to link to stock selection callbacks
|
||||||
|
* filterList - <ul> element where filters are displayed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// List of user-params which override the default filters
|
// List of user-params which override the default filters
|
||||||
var params = options.params || {};
|
var params = options.params || {};
|
||||||
|
|
||||||
|
var filterListElement = options.filterList || "#stock-filter-list";
|
||||||
|
|
||||||
var filters = loadStockFilters();
|
var filters = loadStockFilters();
|
||||||
|
|
||||||
|
updateStockFilterList(filterListElement, filters, table, params);
|
||||||
|
|
||||||
// Override the default values, or add new ones
|
// Override the default values, or add new ones
|
||||||
for (var key in params) {
|
for (var key in params) {
|
||||||
filters[key] = params[key];
|
filters[key] = params[key];
|
||||||
@ -293,6 +359,9 @@ function loadStockTable(table, options) {
|
|||||||
linkButtonsToSelection(table, options.buttons);
|
linkButtonsToSelection(table, options.buttons);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Display the filters
|
||||||
|
updateStockFilterList(filterListElement);
|
||||||
|
|
||||||
function stockAdjustment(action) {
|
function stockAdjustment(action) {
|
||||||
var items = $("#stock-table").bootstrapTable("getSelections");
|
var items = $("#stock-table").bootstrapTable("getSelections");
|
||||||
|
|
||||||
|
@ -2,22 +2,27 @@
|
|||||||
|
|
||||||
<div id='button-toolbar'>
|
<div id='button-toolbar'>
|
||||||
<div class='button-toolbar container-fluid' style='float: right;'>
|
<div class='button-toolbar container-fluid' style='float: right;'>
|
||||||
<button class='btn btn-default' id='stock-export' title='Export Stock Information'>{% trans "Export" %}</button>
|
{% if read_only %}
|
||||||
{% if read_only %}
|
{% else %}
|
||||||
{% else %}
|
<button class="btn btn-success" id='item-create'>{% trans "New Stock Item" %}</button>
|
||||||
<button class="btn btn-success" id='item-create'>{% trans "New Stock Item" %}</button>
|
<div class="btn dropdown">
|
||||||
<div class="dropdown" style='float: right;'>
|
<button id='stock-options' class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">{% trans "Options" %}<span class="caret"></span></button>
|
||||||
<button id='stock-options' class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">{% trans "Options" %}<span class="caret"></span></button>
|
<ul class="dropdown-menu">
|
||||||
<ul class="dropdown-menu">
|
<li><a href="#" id='multi-item-add' title='Add to selected stock items'>{% trans "Add stock" %}</a></li>
|
||||||
<li><a href="#" id='multi-item-add' title='Add to selected stock items'>{% trans "Add stock" %}</a></li>
|
<li><a href="#" id='multi-item-remove' title='Remove from selected stock items'>{% trans "Remove stock" %}</a></li>
|
||||||
<li><a href="#" id='multi-item-remove' title='Remove from selected stock items'>{% trans "Remove stock" %}</a></li>
|
<li><a href="#" id='multi-item-stocktake' title='Stocktake selected stock items'>{% trans "Count stock" %}</a></li>
|
||||||
<li><a href="#" id='multi-item-stocktake' title='Stocktake selected stock items'>{% trans "Count stock" %}</a></li>
|
|
||||||
<li><a href='#' id='multi-item-move' title='Move selected stock items'>{% trans "Move stock" %}</a></li>
|
<li><a href='#' id='multi-item-move' title='Move selected stock items'>{% trans "Move stock" %}</a></li>
|
||||||
<li><a href='#' id='multi-item-order' title='Order selected items'>{% trans "Order stock" %}</a></li>
|
<li><a href='#' id='multi-item-order' title='Order selected items'>{% trans "Order stock" %}</a></li>
|
||||||
<li><a href='#' id='multi-item-delete' title='Delete selected items'>{% trans "Delete Stock" %}</a></li>
|
<li><a href='#' id='multi-item-delete' title='Delete selected items'>{% trans "Delete Stock" %}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<button class='btn btn-default' id='stock-export' title='Export Stock Information'>{% trans "Export" %}</button>
|
||||||
|
<div class='filters'>
|
||||||
|
<ul class='filter-list' id='stock-filter-list'>
|
||||||
|
<!-- This is an empty list which will be populated with the stock table filters -->
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user