partkeepr

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

commit 31bbc065fdfb13cb7a9c22fb30d2836389d75208
parent 8b9439a5e5cba85329748a0bb201da5b56de905d
Author: Felicia Hummel <felicitus@felicitus.org>
Date:   Fri,  6 Jan 2017 21:19:40 +0100

Merge pull request #766 from partkeepr/PartKeepr-54

Display part parameters in the side panel
Diffstat:
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartDisplay.js | 20+++++++++++++++++++-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsManager.js | 145+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
2 files changed, 135 insertions(+), 30 deletions(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartDisplay.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartDisplay.js @@ -148,8 +148,24 @@ Ext.define('PartKeepr.PartDisplay', { sourceConfig: this.fieldConfigs }); + this.partParameterGrid = Ext.create("Ext.grid.Panel", { + title: i18n("Part Parameters"), + emptyText: i18n("No Parameters"), + columns: [{ + header: i18n("Parameter"), + dataIndex: "name", + flex: 1 + }, { + header: i18n("Value"), + renderer: function (v,m,rec) { + return PartKeepr.PartManager.formatParameter(rec); + }, + flex: 1 + }] + }); + this.items = [ - this.infoGrid, { + this.infoGrid, this.partParameterGrid,{ xtype: 'panel', title: i18n("Attachments"), items: this.attachmentDisplay @@ -161,6 +177,7 @@ Ext.define('PartKeepr.PartDisplay', { { this.attachmentDisplay.bindStore(null); this.imageDisplay.setStore(null); + this.partParameterGrid.setStore(null); }, /** @@ -185,6 +202,7 @@ Ext.define('PartKeepr.PartDisplay', { } this.attachmentDisplay.bindStore(this.record.attachments()); + this.partParameterGrid.bindStore(this.record.parameters()); this.infoGrid.setSource(values); this.infoGrid.setTitle( "<div>" + this.record.get("name") + "</div><small>" + this.record.get("description") + "</small>"); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsManager.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsManager.js @@ -25,7 +25,8 @@ Ext.define('PartKeepr.PartManager', { selectedCategory: null, - initComponent: function () { + initComponent: function () + { /** * Create the store with the default sorter "name ASC" @@ -151,7 +152,8 @@ Ext.define('PartKeepr.PartManager', { } }); - this.thumbnailView.on("selectionchange", function (selModel, selection) { + this.thumbnailView.on("selectionchange", function (selModel, selection) + { var parts = []; for (var i = 0; i < selection.length; i++) { @@ -161,13 +163,15 @@ Ext.define('PartKeepr.PartManager', { this.grid.getSelectionModel().select(parts); }, this); - this.grid.store.on("update", function (store, record) { + this.grid.store.on("update", function (store, record) + { if (this.detail.record !== null && this.detail.record.getId() == record.getId()) { this.detail.setValues(record); } }, this); - this.grid.store.on("load", function () { + this.grid.store.on("load", function () + { this.thumbnailView.getStore().removeAll(); var data = this.grid.store.getData(), @@ -199,10 +203,11 @@ Ext.define('PartKeepr.PartManager', { enableOverflow: true, dock: 'bottom', displayInfo: false, - items: [{xtype: 'tbfill'}, { - xtype: 'tbtext', - itemId: "thumbnailViewStatusMessage" - } + items: [ + {xtype: 'tbfill'}, { + xtype: 'tbtext', + itemId: "thumbnailViewStatusMessage" + } ] }); @@ -218,7 +223,8 @@ Ext.define('PartKeepr.PartManager', { items: [this.grid, this.thumbnailPanel] }); - this.thumbnailView.on("render", function () { + this.thumbnailView.on("render", function () + { this.loadMask = Ext.create("Ext.LoadMask", { store: this.grid.store, target: this.thumbnailPanel @@ -270,7 +276,8 @@ Ext.define('PartKeepr.PartManager', { * @param {Ext.tree.View} tree The tree view * @param {Ext.data.Model} record the selected record */ - onCategoryClick: function (tree, record) { + onCategoryClick: function (tree, record) + { this.selectedCategory = record; var filter = Ext.create("PartKeepr.util.Filter", { @@ -289,7 +296,8 @@ Ext.define('PartKeepr.PartManager', { this.store.addFilter(filter); } }, - getSelectedCategory: function () { + getSelectedCategory: function () + { return this.selectedCategory; }, /** @@ -298,7 +306,8 @@ Ext.define('PartKeepr.PartManager', { * @param {Ext.data.Model} node The node * @return Array */ - getChildrenIds: function (node) { + getChildrenIds: function (node) + { var childNodes = [node]; if (node.hasChildNodes()) { @@ -314,7 +323,8 @@ Ext.define('PartKeepr.PartManager', { * of the selected part for a short time. We can't select the category * as this would affect the parts grid. */ - onSyncCategory: function () { + onSyncCategory: function () + { var r = this.grid.getSelectionModel().getSelection(); if (r.length != 1) { @@ -336,7 +346,8 @@ Ext.define('PartKeepr.PartManager', { * * Prompts the user if he really wishes to delete the part. If yes, it calls deletePart. */ - onItemDelete: function () { + onItemDelete: function () + { var r = this.grid.getSelectionModel().getLastSelected(); Ext.Msg.confirm(i18n("Delete Part"), sprintf(i18n("Do you really wish to delete the part %s?"), r.get("name")), @@ -346,7 +357,8 @@ Ext.define('PartKeepr.PartManager', { * Creates a duplicate with the basic data only from the selected item. Loads the selected part and calls * createPartDuplicate after the part was loaded. */ - onDuplicateItemWithBasicData: function () { + onDuplicateItemWithBasicData: function () + { var r = this.grid.getSelectionModel().getLastSelected(); this.loadPart(r.getId(), Ext.bind(this.createPartDuplicate, this)); @@ -355,7 +367,8 @@ Ext.define('PartKeepr.PartManager', { * Creates a full duplicate from the selected item. Loads the selected part and calls createPartDuplicate * after the part was loaded. */ - onDuplicateItemWithAllData: function () { + onDuplicateItemWithAllData: function () + { var r = this.grid.getSelectionModel().getLastSelected(); this.loadPart(r.getId(), Ext.bind(this.createFullPartDuplicate, this)); @@ -364,7 +377,8 @@ Ext.define('PartKeepr.PartManager', { * Creates a part duplicate from the given record and opens the editor window. * @param rec The record to duplicate */ - createPartDuplicate: function (rec) { + createPartDuplicate: function (rec) + { var data = rec.getData(); var associationData = rec.getAssociationData(); @@ -389,7 +403,8 @@ Ext.define('PartKeepr.PartManager', { * Creates a part duplicate from the given record and opens the editor window. * @param rec The record to duplicate */ - createFullPartDuplicate: function (rec) { + createFullPartDuplicate: function (rec) + { var data = rec.getData(); var newItem = Ext.create("PartKeepr.PartBundle.Entity.Part"); @@ -411,7 +426,8 @@ Ext.define('PartKeepr.PartManager', { * @todo We use the current selection of the grid. If for some reason the selection changes during the user is prompted, * we delete the wrong part. Fix that to pass the selected item to the onItemDelete then to this function. */ - deletePart: function (btn) { + deletePart: function (btn) + { var r = this.grid.getSelectionModel().getLastSelected(); if (btn == "yes") { @@ -423,7 +439,8 @@ Ext.define('PartKeepr.PartManager', { /** * Creates a new, empty part editor window */ - onItemAdd: function (defaults) { + onItemAdd: function (defaults) + { var j = Ext.create("PartKeepr.PartEditorWindow", { partMode: 'create' }); @@ -451,22 +468,26 @@ Ext.define('PartKeepr.PartManager', { /** * Called when a part was edited. Refreshes the grid. */ - onEditPart: function (part) { + onEditPart: function (part) + { var j = Ext.create("PartKeepr.PartEditorWindow"); j.editor.on("partSaved", this.onPartSaved, this); j.editor.editItem(part); j.show(); }, - onNewPartSaved: function () { + onNewPartSaved: function () + { this.grid.getStore().reload(); }, - onPartSaved: function (record) { + onPartSaved: function (record) + { this.detail.setValues(record); }, /** * Called when a part was selected in the grid. Displays the details for this part. */ - onItemSelect: function () { + onItemSelect: function () + { if (this.grid.getSelection().length > 1) { this.detailPanel.collapse(); this.tree.syncButton.disable(); @@ -493,7 +514,8 @@ Ext.define('PartKeepr.PartManager', { * @param {Integer} id The ID of the part to load * @param {Function} handler The callback to call when the part was loaded */ - loadPart: function (id, handler) { + loadPart: function (id, handler) + { // @todo we have this method duplicated in PartEditor PartKeepr.PartBundle.Entity.Part.load(id, { @@ -504,7 +526,8 @@ Ext.define('PartKeepr.PartManager', { /** * Creates the store */ - createStore: function (config) { + createStore: function (config) + { Ext.Object.merge(config, { autoLoad: true, autoSync: false, // Do not change. If true, new (empty) records would be immediately commited to the database. @@ -516,10 +539,12 @@ Ext.define('PartKeepr.PartManager', { this.store = Ext.create('Ext.data.Store', config); // Workaround for bug http://www.sencha.com/forum/showthread.php?133767-Store.sync()-does-not-update-dirty-flag&p=607093#post607093 - this.store.on('write', function (store, operation) { + this.store.on('write', function (store, operation) + { var success = operation.wasSuccessful(); if (success) { - Ext.each(operation.records, function (record) { + Ext.each(operation.records, function (record) + { if (record.dirty) { record.commit(); } @@ -530,7 +555,69 @@ Ext.define('PartKeepr.PartManager', { /** * Returns the store */ - getStore: function () { + getStore: function () + { return this.store; + }, + statics: { + formatParameter: function (partParameter) + { + var minSiPrefix = "", siPrefix = "", maxSiPrefix = "", unit = "", minValue = "", maxValue = "", value = "", + minMaxCombined = ""; + + if (partParameter.get("valueType") === "string") { + return ""; + } + + if (partParameter.getUnit() instanceof PartKeepr.UnitBundle.Entity.Unit) { + unit = partParameter.getUnit().get("symbol"); + } + + if (partParameter.getMinSiPrefix() instanceof PartKeepr.SiPrefixBundle.Entity.SiPrefix) { + minSiPrefix = partParameter.getMinSiPrefix().get("symbol"); + } + + if (partParameter.getSiPrefix() instanceof PartKeepr.SiPrefixBundle.Entity.SiPrefix) { + siPrefix = partParameter.getSiPrefix().get("symbol"); + } + + if (partParameter.getMaxSiPrefix() instanceof PartKeepr.SiPrefixBundle.Entity.SiPrefix) { + maxSiPrefix = partParameter.getMaxSiPrefix().get("symbol"); + } + + if (partParameter.get("value") !== null && partParameter.get("value") !== "") { + value = partParameter.get("value"); + } + + if (partParameter.get("minValue") !== null && partParameter.get("minValue") !== "") { + minValue = partParameter.get("minValue"); + } + + if (partParameter.get("maxValue") !== null && partParameter.get("maxValue") !== "") { + maxValue = partParameter.get("maxValue"); + } + + if (minValue !== "" && maxValue !== "") { + minMaxCombined = minValue + minSiPrefix + "…" + maxValue + maxSiPrefix + unit; + } else { + if (minValue !== "") { + minMaxCombined = i18n("Min.") + minValue + minSiPrefix + unit; + } + + if (maxValue !== "") { + minMaxCombined = i18n("Max.") + maxValue + maxSiPrefix + unit; + } + } + + if (value !== "") { + if (minMaxCombined !== "") { + return value + siPrefix + unit + " (" + minMaxCombined + ")"; + } else { + return value + siPrefix + unit; + } + } else { + return minMaxCombined; + } + } } });