partkeepr

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

commit 329c564f8031b9101f39a2e5ffa3641dd09d4233
parent 7ef0c66c1cdf7f94c674060f0bd04fcf8e2db37f
Author: Felicia Hummel <felicia@partkeepr.com>
Date:   Fri,  2 Jun 2017 21:53:30 +0200

Added buttons to move to next and previous meta part

Diffstat:
Asrc/PartKeepr/FrontendBundle/Resources/public/images/icons/bricks_down.png | 0
Asrc/PartKeepr/FrontendBundle/Resources/public/images/icons/bricks_up.png | 0
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Project/ProjectReport.js | 276+------------------------------------------------------------------------------
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Project/ProjectReportResultGrid.js | 342+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 344 insertions(+), 274 deletions(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/images/icons/bricks_down.png b/src/PartKeepr/FrontendBundle/Resources/public/images/icons/bricks_down.png Binary files differ. diff --git a/src/PartKeepr/FrontendBundle/Resources/public/images/icons/bricks_up.png b/src/PartKeepr/FrontendBundle/Resources/public/images/icons/bricks_up.png Binary files differ. diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Project/ProjectReport.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Project/ProjectReport.js @@ -1,4 +1,3 @@ - /** * Represents the project report view */ @@ -33,71 +32,9 @@ Ext.define('PartKeepr.ProjectReportView', { width: 500 }); - this.editing = Ext.create('Ext.grid.plugin.CellEditing', { - clicksToEdit: 1, - listeners: { - beforeedit: this.onBeforeEdit, - edit: this.onEdit, - scope: this - } - }); - - this.subGrid = { - xtype: 'gridfoo', - bind: { - store: '{record.subParts}', - parentRecord: '{record}' - } - }; - - var gridPresetButton = Ext.create("PartKeepr.Components.Grid.GridPresetButton"); - - this.autoFillButton = Ext.create('Ext.button.Button', { - text: i18n("Autofill Distributors"), - iconCls: 'fugue-icon notification-counter-02', - listeners: { - click: this.onAutoFillClick, - scope: this - } - }); - - this.removeStockButton = Ext.create('Ext.button.Button', { - text: i18n("Remove parts from stock"), - iconCls: 'fugue-icon notification-counter-03', - listeners: { - click: this.onStockRemovalClick, - scope: this - } - - }); - - this.rowExpander = new PartKeepr.Components.ProjectReport.MetaPartRowExpander({ - widget: this.subGrid - }); - this.reportResult = Ext.create("PartKeepr.Components.Project.ProjectReportResultGrid", { - flex: 1, - - plugins: [ - this.rowExpander, this.editing - ], - - store: this.projectReportStore, - bbar: [ - this.autoFillButton, - this.removeStockButton, - {xtype: 'tbspacer'}, - Ext.create("PartKeepr.Exporter.GridExporterButton", { - itemId: 'export', - genericExporter: false, - tooltip: i18n("Export"), - iconCls: "fugue-icon application-export", - disabled: this.reportList.getStore().isLoading() - }), - gridPresetButton - ] - } - ); + store: this.projectReportStore + }); this.items = [ @@ -113,215 +50,6 @@ Ext.define('PartKeepr.ProjectReportView', { this.callParent(); this.down("#createReportButton").on("click", this.onCreateReportClick, this); - - gridPresetButton.setGrid(this.reportResult); - }, - - /** - * Called when the distributor field is about to be edited. - * - * Filters the distributor list and show only distributors which are assigned to the particular item. - * @param e - * @param context - */ - onBeforeEdit: function (e, context) - { - if (context.field !== "distributor") - { - return; - } - - var distributors = context.record.getPart().distributors(); - - var filterIds = []; - for (var i = 0; i < distributors.count(); i++) - { - if (distributors.getAt(i).getDistributor().get("enabledForReports") === false) { - continue; - } - - if (distributors.getAt(i).get("ignoreForReports")) { - continue; - } - - filterIds.push(distributors.getAt(i).getDistributor().getId()); - } - - var filter = Ext.create("PartKeepr.util.Filter", { - property: "@id", - operator: 'in', - value: filterIds - }); - - context.column.getEditor().store.clearFilter(); - context.column.getEditor().store.addFilter(filter); - }, - /** - * Removes all parts in the project view. - */ - onStockRemovalClick: function () - { - Ext.Msg.confirm(i18n("Remove parts from stock"), - i18n("Do you really want to remove the parts in the project report from the stock?"), - this.removeStocks, this); - }, - removeStocks: function (btn) - { - if (btn === "yes") - { - - var store = this.reportResult.getStore(); - var removals = []; - - for (var i = 0; i < store.count(); i++) - { - var item = store.getAt(i); - - - removals.push({ - part: item.getPart().getId(), - amount: item.get("quantity"), - comment: item.get("projectNames"), - lotNumber: item.get("lotNumber"), - projects: item.get("projects") - }); - } - - PartKeepr.PartBundle.Entity.Part.callPostCollectionAction("massRemoveStock", - {"removals": Ext.encode(removals), "projects": Ext.encode(this.reportedProjects)}); - } - }, - onEdit: function (editor, context) - { - if (context.field === "distributor" && context.record.getDistributor() !== null) - { - var partDistributors = context.record.getPart().distributors(); - - for (var i = 0; i < partDistributors.count(); i++) - { - if (partDistributors.getAt(i).getDistributor().getId() === context.record.getDistributor().getId()) - { - context.record.set("price", partDistributors.getAt(i).get("price")); - context.record.set("distributor_order_number", partDistributors.getAt(i).get("orderNumber")); - context.record.set("sum_order", context.record.get("missing") * context.record.get("price")); - context.record.set("sum", context.record.get("quantity") * context.record.get("price")); - } - } - } - - }, - onAutoFillClick: function () - { - var partCount = this.reportResult.store.count(); - var activeRecord; - - this.projectPartStack = []; - - - for (var i = 0; i < partCount; i++) - { - - activeRecord = this.reportResult.store.getAt(i); - - this.projectPartStack.push(activeRecord); - } - - this.processCheapestDistributorStack(this.projectPartStack.length); - - if (this.waitMessage instanceof Ext.window.MessageBox) - { - this.waitMessage.hide(); - } - }, - processCheapestDistributorStack: function (totalCount) - { - if (this.projectPartStack.length === 0) - { - if (this.waitMessage instanceof Ext.window.MessageBox) - { - this.waitMessage.hide(); - } - return; - } - this.displayWaitWindow( - i18n("Processing distributors…"), - (totalCount - this.projectPartStack.length) + " / " + totalCount, - 1 / totalCount * (totalCount - this.projectPartStack.length)); - this.processCheapestDistributorForProjectPart(this.projectPartStack.shift()); - - Ext.defer(this.processCheapestDistributorStack, 1, this, [totalCount]); - }, - processCheapestDistributorForProjectPart: function (projectPart) - { - var cheapestDistributor = this.getCheapestDistributor(projectPart.getPart()); - - if (cheapestDistributor !== null) - { - projectPart.setDistributor(cheapestDistributor.getDistributor()); - projectPart.set("distributor_order_number", cheapestDistributor.get("orderNumber")); - projectPart.set("price", cheapestDistributor.get("price")); - projectPart.set("sum_order", projectPart.get("missing") * projectPart.get("price")); - projectPart.set("sum", projectPart.get("quantity") * projectPart.get("price")); - } - }, - getCheapestDistributor: function (part) - { - var cheapestDistributor = null; - var currentPrice; - var activeDistributor; - var lowestPrice; - var firstPositive; - - firstPositive = true; - lowestPrice = 0; - - for (var j = 0; j < part.distributors().count(); j++) - { - activeDistributor = part.distributors().getAt(j); - - if (activeDistributor.getDistributor().get("enabledForReports") === false) { - continue; - } - - if (activeDistributor.get("ignoreForReports") === true) { - continue; - } - - currentPrice = parseFloat(activeDistributor.get("price")); - - if (currentPrice !== 0) - { - if (firstPositive) - { - lowestPrice = currentPrice; - cheapestDistributor = activeDistributor; - firstPositive = false; - } - else - { - if (currentPrice < lowestPrice) - { - lowestPrice = currentPrice; - cheapestDistributor = activeDistributor; - } - } - } - } - - return cheapestDistributor; - }, - displayWaitWindow: function (text, description, value) - { - this.waitMessage = Ext.MessageBox.show({ - msg: text, - title: i18n("Applying distributors…"), - progressText: description, - progress: true, - width: 300 - }); - - this.waitMessage.updateProgress(value); - }, /** * diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Project/ProjectReportResultGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Project/ProjectReportResultGrid.js @@ -9,6 +9,15 @@ Ext.define("PartKeepr.Components.Project.ProjectReportResultGrid", { initComponent: function () { + + this.subGrid = { + xtype: 'gridfoo', + bind: { + store: '{record.subParts}', + parentRecord: '{record}' + } + }; + this.columns = [ { header: i18n("Qty"), dataIndex: 'quantity', @@ -98,6 +107,339 @@ Ext.define("PartKeepr.Components.Project.ProjectReportResultGrid", { } ]; + this.nextMetaPart = Ext.create("Ext.button.Button", { + text: i18n("Next Meta-Part"), + iconCls: 'partkeepr-icon bricks_down', + listeners: { + click: this.jumpToNextMetaPart, + scope: this + } + }); + + this.previousMetaPart = Ext.create("Ext.button.Button", { + text: i18n("Previous Meta-Part"), + iconCls: 'partkeepr-icon bricks_up', + listeners: { + click: this.jumpToPreviousMetaPart, + scope: this + } + }); + + this.removeStockButton = Ext.create('Ext.button.Button', { + text: i18n("Remove parts from stock"), + iconCls: 'fugue-icon notification-counter-03', + listeners: { + click: this.onStockRemovalClick, + scope: this + } + }); + + this.autoFillButton = Ext.create('Ext.button.Button', { + text: i18n("Auto-Fill Distributors"), + iconCls: 'fugue-icon notification-counter-02', + listeners: { + click: this.onAutoFillClick, + scope: this + } + }); + + this.rowExpander = new PartKeepr.Components.ProjectReport.MetaPartRowExpander({ + widget: this.subGrid + }); + + this.editing = Ext.create('Ext.grid.plugin.CellEditing', { + clicksToEdit: 1, + listeners: { + beforeedit: this.onBeforeEdit, + edit: this.onEdit, + scope: this + } + }); + + this.plugins = [ + this.rowExpander, this.editing + ]; + + this.bbar = [ + this.autoFillButton, + this.removeStockButton, + {xtype: 'tbseparator'}, + this.nextMetaPart, + this.previousMetaPart, + {xtype: 'tbseparator'}, + Ext.create("PartKeepr.Exporter.GridExporterButton", { + itemId: 'export', + genericExporter: false, + tooltip: i18n("Export"), + iconCls: "fugue-icon application-export" + }), + Ext.create("PartKeepr.Components.Grid.GridPresetButton", { + grid: this + }) + + ]; + + this.callParent(arguments); + + }, + /** + * Called when the distributor field is about to be edited. + * + * Filters the distributor list and show only distributors which are assigned to the particular item. + * @param e + * @param context + */ + onBeforeEdit: function (e, context) + { + if (context.field !== "distributor") + { + return; + } + + var distributors = context.record.getPart().distributors(); + + var filterIds = []; + for (var i = 0; i < distributors.count(); i++) + { + if (distributors.getAt(i).getDistributor().get("enabledForReports") === false) + { + continue; + } + + if (distributors.getAt(i).get("ignoreForReports")) + { + continue; + } + + filterIds.push(distributors.getAt(i).getDistributor().getId()); + } + + var filter = Ext.create("PartKeepr.util.Filter", { + property: "@id", + operator: 'in', + value: filterIds + }); + + context.column.getEditor().store.clearFilter(); + context.column.getEditor().store.addFilter(filter); + }, + /** + * Removes all parts in the project view. + */ + onStockRemovalClick: function () + { + Ext.Msg.confirm(i18n("Remove parts from stock"), + i18n("Do you really want to remove the parts in the project report from the stock?"), + this.removeStocks, this); + }, + jumpToPreviousMetaPart: function () + { + var i; + + for (i = this.getSelectedMetaPartStartIndex() - 1; i >= 0; i--) + { + if (this.selectMetaPart(i)) + { + break; + } + } + }, + jumpToNextMetaPart: function () + { + var i; + + for (i = this.getSelectedMetaPartStartIndex() + 1; i < this.getStore().getCount(); i++) + { + if (this.selectMetaPart(i)) + { + break; + } + } + }, + selectMetaPart: function (index) + { + var record = this.getStore().getAt(index); + + if (record.get("metaPart")) + { + this.ensureVisible(record); + this.getSelectionModel().select(record); + return true; + } + + return false; + }, + getSelectedMetaPartStartIndex: function () + { + var selection = this.getSelection(); + + if (selection.length === 1) + { + return this.getStore().indexOf(selection[0]); + } else + { + return 0; + } + }, + removeStocks: function (btn) + { + if (btn === "yes") + { + + var store = this.getStore(); + var removals = []; + + for (var i = 0; i < store.count(); i++) + { + var item = store.getAt(i); + + + removals.push({ + part: item.getPart().getId(), + amount: item.get("quantity"), + comment: item.get("projectNames"), + lotNumber: item.get("lotNumber"), + projects: item.get("projects") + }); + } + + PartKeepr.PartBundle.Entity.Part.callPostCollectionAction("massRemoveStock", + {"removals": Ext.encode(removals), "projects": Ext.encode(this.reportedProjects)}); + } + }, + onEdit: function (editor, context) + { + if (context.field === "distributor" && context.record.getDistributor() !== null) + { + var partDistributors = context.record.getPart().distributors(); + + for (var i = 0; i < partDistributors.count(); i++) + { + if (partDistributors.getAt(i).getDistributor().getId() === context.record.getDistributor().getId()) + { + context.record.set("price", partDistributors.getAt(i).get("price")); + context.record.set("distributor_order_number", partDistributors.getAt(i).get("orderNumber")); + context.record.set("sum_order", context.record.get("missing") * context.record.get("price")); + context.record.set("sum", context.record.get("quantity") * context.record.get("price")); + } + } + } + + }, + onAutoFillClick: function () + { + var partCount = this.getStore().getCount(); + var activeRecord; + + this.projectPartStack = []; + + + for (var i = 0; i < partCount; i++) + { + + activeRecord = this.getStore().getAt(i); + + this.projectPartStack.push(activeRecord); + } + + this.processCheapestDistributorStack(this.projectPartStack.length); + + if (this.waitMessage instanceof Ext.window.MessageBox) + { + this.waitMessage.hide(); + } + }, + processCheapestDistributorStack: function (totalCount) + { + if (this.projectPartStack.length === 0) + { + if (this.waitMessage instanceof Ext.window.MessageBox) + { + this.waitMessage.hide(); + } + return; + } + this.displayWaitWindow( + i18n("Processing distributors…"), + (totalCount - this.projectPartStack.length) + " / " + totalCount, + 1 / totalCount * (totalCount - this.projectPartStack.length)); + this.processCheapestDistributorForProjectPart(this.projectPartStack.shift()); + + Ext.defer(this.processCheapestDistributorStack, 1, this, [totalCount]); + }, + processCheapestDistributorForProjectPart: function (projectPart) + { + var cheapestDistributor = this.getCheapestDistributor(projectPart.getPart()); + + if (cheapestDistributor !== null) + { + projectPart.setDistributor(cheapestDistributor.getDistributor()); + projectPart.set("distributor_order_number", cheapestDistributor.get("orderNumber")); + projectPart.set("price", cheapestDistributor.get("price")); + projectPart.set("sum_order", projectPart.get("missing") * projectPart.get("price")); + projectPart.set("sum", projectPart.get("quantity") * projectPart.get("price")); + } + }, + getCheapestDistributor: function (part) + { + var cheapestDistributor = null; + var currentPrice; + var activeDistributor; + var lowestPrice; + var firstPositive; + + firstPositive = true; + lowestPrice = 0; + + for (var j = 0; j < part.distributors().count(); j++) + { + activeDistributor = part.distributors().getAt(j); + + if (activeDistributor.getDistributor().get("enabledForReports") === false) + { + continue; + } + + if (activeDistributor.get("ignoreForReports") === true) + { + continue; + } + + currentPrice = parseFloat(activeDistributor.get("price")); + + if (currentPrice !== 0) + { + if (firstPositive) + { + lowestPrice = currentPrice; + cheapestDistributor = activeDistributor; + firstPositive = false; + } + else + { + if (currentPrice < lowestPrice) + { + lowestPrice = currentPrice; + cheapestDistributor = activeDistributor; + } + } + } + } + + return cheapestDistributor; + }, + displayWaitWindow: function (text, description, value) + { + this.waitMessage = Ext.MessageBox.show({ + msg: text, + title: i18n("Applying distributors…"), + progressText: description, + progress: true, + width: 300 + }); + + this.waitMessage.updateProgress(value); + } });