partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit d3ecfc6213069ef42ef8708a185dc89abf81e5af
parent 474b483b0487e24961226dd272f5e53c991e3119
Author: Timo A. Hummel <felicitus@felicitus.org>
Date:   Sat, 28 Apr 2018 18:12:36 +0200

Added filter function to easily filter by part parameters

Diffstat:
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Editor/EditorGrid.js | 4++--
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsGrid.js | 85++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/PagingToolbar.js | 18++++++++++++------
3 files changed, 96 insertions(+), 11 deletions(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Editor/EditorGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Editor/EditorGrid.js @@ -224,9 +224,9 @@ Ext.define('PartKeepr.EditorGrid', { var filters = this.getStore().getFilters(); if (filters.length > 0) { - this.bottomToolbar.down("#filter").show(); + this.bottomToolbar.down("#resetFilter").show(); } else { - this.bottomToolbar.down("#filter").hide(); + this.bottomToolbar.down("#resetFilter").hide(); } this.appliedFiltersToolbar.updateFilters(filters); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsGrid.js @@ -115,11 +115,24 @@ Ext.define('PartKeepr.PartsGrid', { this.bottomToolbar.add({ xtype: 'button', - tooltip: i18n("Collapse all Groups"), - iconCls: this.collapseRowButtonIconCls, + tooltip: i18n("Expand all Groups"), + iconCls: this.expandRowButtonIconCls, listeners: { scope: this.groupingFeature, - click: this.groupingFeature.collapseAll + click: this.groupingFeature.expandAll + } + + }); + + var insertPosition = this.bottomToolbar.items.indexOf(this.bottomToolbar.down("#addFilter")); + + this.bottomToolbar.insert(insertPosition, { + xtype: 'button', + tooltip: i18n("Filter by Part Parameter"), + iconCls: "fugue-icon table--plus", + listeners: { + scope: this, + click: this.addParameterFilter } }); @@ -371,6 +384,72 @@ Ext.define('PartKeepr.PartsGrid', { break; } }, + addParameterFilter: function () { + this.addFilterWindow = Ext.create("PartKeepr.Components.Widgets.PartParameterSearchWindow", { + + sourceModel: this.getStore().getModel(), + listeners: { + "apply": this.onAddParameterFilter, + scope: this + } + }); + + this.addFilterWindow.show(); + }, + /** + * @todo Refactor this function as well as the one in DataApplicator to a single central function + * + * Note that this function takes the input and multiplies it by the si prefix + * @param value + * @param siPrefix + * @returns {*} + */ + applySiPrefix: function (value, siPrefix) + { + if (siPrefix instanceof PartKeepr.SiPrefixBundle.Entity.SiPrefix) { + return Ext.util.Format.round(value * Math.pow(siPrefix.get("base"), siPrefix.get("exponent")), 3); + } else { + return value; + } + }, + onAddParameterFilter: function (rec) { + var subFilters = []; + + + subFilters.push( Ext.create("PartKeepr.util.Filter", { + property: "parameters.name", + operator: "=", + value: rec.get("partParameterName") + })); + + var value; + + if (rec.get("valueType") === "numeric") { + value = this.applySiPrefix(rec.get("value"), rec.getSiPrefix()); + + subFilters.push( Ext.create("PartKeepr.util.Filter", { + property: "parameters.normalizedValue", + operator: rec.get("operator"), + value: value + })); + } else { + value = rec.get("stringValue"); + + subFilters.push( Ext.create("PartKeepr.util.Filter", { + property: "parameters.stringValue", + operator: rec.get("operator"), + value: value + })); + } + + + var filter = Ext.create("PartKeepr.util.Filter", { + type: "AND", + subfilters: subFilters + }); + this.getStore().addFilter(filter); + }, + /** * Handles the editing of the stock level field. Checks if the user has opted in to skip the * online stock edit confirm window, and runs the changes afterwards. diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/PagingToolbar.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/PagingToolbar.js @@ -7,6 +7,8 @@ Ext.define("PartKeepr.PagingToolbar", { { var items = this.callParent(arguments); + items.push({ xtype: 'tbseparator' }); + items.push(Ext.create("PartKeepr.Exporter.GridExporterButton", { itemId: 'export', tooltip: i18n("Export"), @@ -23,6 +25,8 @@ Ext.define("PartKeepr.PagingToolbar", { disabled: this.store.isLoading() })); + items.push({ xtype: 'tbseparator' }); + items.push({ itemId: 'addFilter', xtype: 'button', @@ -34,14 +38,10 @@ Ext.define("PartKeepr.PagingToolbar", { scope: this }); - items.push(Ext.create("PartKeepr.Components.Grid.GridPresetButton", { - grid: this.grid - })); - items.push(Ext.create({ - itemId: 'filter', + itemId: 'resetFilter', xtype: 'button', - iconCls: 'fugue-icon funnel', + iconCls: 'fugue-icon funnel--minus', tooltip: i18n("Reset Filter"), hidden: true, handler: function () { @@ -53,6 +53,12 @@ Ext.define("PartKeepr.PagingToolbar", { scope: this })); + items.push({ xtype: 'tbseparator' }); + + items.push(Ext.create("PartKeepr.Components.Grid.GridPresetButton", { + grid: this.grid + })); + return items; }, onAddFilterClick: function ()