partkeepr

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

commit 0ec2a3ce920dec720099e84e827f64a682edb59a
parent 3e819c6f293a73e081ee27405186d9a54a834161
Author: Felicitus <felicitus@felicitus.org>
Date:   Mon, 21 Sep 2015 17:46:00 +0200

Merge branch 'sf2migration' of github.com:partkeepr/PartKeepr into sf2migration

Diffstat:
MREADME.md | 2+-
Mapp/config/config.yml | 3++-
Dsrc/PartKeepr/CoreBundle/DoctrineMigrations/Version20150801133623.php | 36------------------------------------
Msrc/PartKeepr/DoctrineReflectionBundle/Exception/ExceptionWrapperHandler.php | 17++++++-----------
Msrc/PartKeepr/DoctrineReflectionBundle/Resources/config/services.xml | 3+++
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartDisplay.js | 16+++-------------
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsGrid.js | 7+++++--
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsManager.js | 25++-----------------------
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Session/SessionManager.js | 3++-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/StockReport/AbstractStockHistoryGrid.js | 30++++++++++++------------------
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraModel.js | 7++++---
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraProxy.js | 6+++++-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Util/ServiceCall.js | 40++--------------------------------------
13 files changed, 47 insertions(+), 148 deletions(-)

diff --git a/README.md b/README.md @@ -1,4 +1,4 @@ -[![PartKeepr](https://partkeepr.org/partkeepr-banner.png)](https://www.partkeepr.org) +[![PartKeepr](https://partkeepr.org/images/partkeepr-banner.png)](https://www.partkeepr.org) [![JSON-LD enabled](http://json-ld.org/images/json-ld-button-88.png)](http://json-ld.org) [![Build Status](https://travis-ci.org/partkeepr/PartKeepr.svg?branch=sf2migration)](https://travis-ci.org/partkeepr/PartKeepr) diff --git a/app/config/config.yml b/app/config/config.yml @@ -7,12 +7,13 @@ fos_rest: body_listener: true format_listener: true param_fetcher_listener: force + service: + exception_handler: "partkeepr.exceptionwrapper" format_listener: rules: - priorities: [json, xml] - fallback_format: json view: - exception_wrapper_handler: PartKeepr\DoctrineReflectionBundle\Exception\ExceptionWrapperHandler default_engine: php formats: json: true diff --git a/src/PartKeepr/CoreBundle/DoctrineMigrations/Version20150801133623.php b/src/PartKeepr/CoreBundle/DoctrineMigrations/Version20150801133623.php @@ -1,36 +0,0 @@ -<?php - -namespace PartKeepr\CoreBundle\DoctrineMigrations; - -use Doctrine\DBAL\Migrations\AbstractMigration; -use Doctrine\DBAL\Schema\Schema; - -/** - * Auto-generated Migration: Please modify to your needs! - */ -class Version20150801133623 extends AbstractMigration -{ - /** - * @param Schema $schema - */ - public function up(Schema $schema) - { - $sSQL = "UPDATE PartKeeprUser SET username_canonical = username"; - $this->addSql($sSQL); - - $sSQL = "UPDATE PartKeeprUser SET email_canonical = username"; - $this->addSql($sSQL); - - $sSQL = "UPDATE PartKeeprUser SET roles = 'a:0:{}'"; - $this->addSql($sSQL); - } - - /** - * @param Schema $schema - */ - public function down(Schema $schema) - { - // this down() migration is auto-generated, please modify it to your needs - - } -} diff --git a/src/PartKeepr/DoctrineReflectionBundle/Exception/ExceptionWrapperHandler.php b/src/PartKeepr/DoctrineReflectionBundle/Exception/ExceptionWrapperHandler.php @@ -2,7 +2,6 @@ namespace PartKeepr\DoctrineReflectionBundle\Exception; use FOS\RestBundle\View\ExceptionWrapperHandlerInterface; -use Symfony\Component\Debug\Exception\FlattenException; class ExceptionWrapperHandler implements ExceptionWrapperHandlerInterface { @@ -13,16 +12,12 @@ class ExceptionWrapperHandler implements ExceptionWrapperHandlerInterface */ public function wrap($data) { - // we get the original exception - /** @var $exception FlattenException */ - $exception = $data['exception']; + $data = [ + '@type' => 'Error', + 'hydra:title' => isset($context['title']) ? $context['title'] : 'An error occurred', + 'hydra:description' => $data["message"], + ]; - // return the array - return array( - 'success' => false, - 'exception' => array( - "message" => $exception->getMessage() - ) - ); + return $data; } } \ No newline at end of file diff --git a/src/PartKeepr/DoctrineReflectionBundle/Resources/config/services.xml b/src/PartKeepr/DoctrineReflectionBundle/Resources/config/services.xml @@ -18,5 +18,8 @@ <argument type="service" id="request_stack" /> </service> + <service id="partkeepr.exceptionwrapper" class="PartKeepr\DoctrineReflectionBundle\Exception\ExceptionWrapperHandler"> + </service> + </services> </container> diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartDisplay.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartDisplay.js @@ -84,7 +84,7 @@ Ext.define('PartKeepr.PartDisplay', { iconCls: 'web-icon brick_edit', handler: Ext.bind(function () { - this.fireEvent("editPart", this.record.getId()); + this.fireEvent("editPart", this.record); }, this) }); @@ -207,7 +207,7 @@ Ext.define('PartKeepr.PartDisplay', { quantity: quantity, price: price, comment: comment - }, Ext.bind(this.reloadPart, this)); + }, null, true); }, /** * Prompts the user for the stock level to decrease for the item. @@ -224,17 +224,7 @@ Ext.define('PartKeepr.PartDisplay', { { this.record.callAction("removeStock", { quantity: quantity, - }, Ext.bind(this.reloadPart, this)); - }, - /** - * Reloads the current part - */ - reloadPart: function () - { - this.record.load({ - scope: this, - success: this.onPartLoaded - }); + }, null, true); }, /** * Load the part from the database. diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsGrid.js @@ -219,7 +219,7 @@ Ext.define('PartKeepr.PartsGrid', { onDoubleClick: function (view, record) { if (record) { - this.fireEvent("editPart", record.getId()); + this.fireEvent("editPart", record); } }, /** @@ -390,7 +390,9 @@ Ext.define('PartKeepr.PartsGrid', { { switch (e.field) { case "stockLevel": - this.handleStockFieldEdit(e); + if (e.value !== e.originalValue.toString()) { + this.handleStockFieldEdit(e); + } break; default: break; @@ -497,6 +499,7 @@ Ext.define('PartKeepr.PartsGrid', { { if (buttonId == "cancel") { opts.originalOnEdit.record.set("stockLevel", opts.originalOnEdit.originalValue); + return; } this.handleStockChange(opts.originalOnEdit); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsManager.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsManager.js @@ -80,12 +80,6 @@ Ext.define('PartKeepr.PartManager', { this.grid.on("duplicateItemWithAllData", this.onDuplicateItemWithAllData, this); this.tree.on("syncCategory", this.onSyncCategory, this); - // Listen on the partChanged event, which is fired when the users edits the part - this.detail.on("partChanged", function () - { - this.grid.getStore().load(); - }, this); - // Create the stock level panel this.stockLevel = Ext.create("PartKeepr.PartStockHistory", {title: "Stock History"}); @@ -341,30 +335,15 @@ Ext.define('PartKeepr.PartManager', { /** * Called when a part was edited. Refreshes the grid. */ - onEditPart: function (id) - { - this.loadPart(id, Ext.bind(this.onPartLoaded, this)); - }, - /** - * Called when a part was loaded. Displays the part in the editor window. - */ - onPartLoaded: function (f, g) + onEditPart: function (part) { var j = Ext.create("PartKeepr.PartEditorWindow"); j.editor.on("partSaved", this.onPartSaved, this); - j.editor.editItem(f); + j.editor.editItem(part); j.show(); }, onPartSaved: function (record) { - - var idx = this.grid.store.find("id", record.getId()); - - // Only reload the grid if the edited record is contained - if (idx !== -1) { - this.grid.store.load(); - } - this.detail.setValues(record); }, /** diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Session/SessionManager.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Session/SessionManager.js @@ -82,6 +82,7 @@ Ext.define("PartKeepr.SessionManager", { this.secret = CryptoJS.enc.Base64.stringify(CryptoJS.SHA512(this.password + "{" + this.salt + "}")); + this.loginDialog.destroy(); this.fireEvent("login"); }, getWSSE: function () { @@ -137,6 +138,7 @@ Ext.define("PartKeepr.SessionManager", { k.setHandler(Ext.bind(this.onSaltRetrieved, this)); k.doCall(); + }, /** * Callback when the service call is complete. @@ -145,7 +147,6 @@ Ext.define("PartKeepr.SessionManager", { */ onAfterLogin: function (response) { - console.log(response); this.setSession(response.sessionId); this.loginDialog.destroy(); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StockReport/AbstractStockHistoryGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StockReport/AbstractStockHistoryGrid.js @@ -6,20 +6,18 @@ Ext.define('PartKeepr.AbstractStockHistoryGrid', { pageSize: 25, - defineColumns: function () - { + defineColumns: function () { this.columns = [ { header: "", xtype: 'actioncolumn', - dataIndex: 'direction', - renderer: function (val) - { - if (val == "out") { - return '<img title="' + i18n( - "Parts removed") + '" src="resources/silkicons/brick_delete.png"/>'; + renderer: function (val, p, rec) { + if (rec.get("stockLevel") < 0) { + return '<span title="' + i18n( + "Parts removed") + '" style="vertical-align: top;" class="web-icon brick_delete">ad</span>'; } else { - return '<img title="' + i18n("Parts added") + '" src="resources/silkicons/brick_add.png"/>'; + return '<span title="' + i18n( + "Parts added") + '" style="vertical-align: top;" class="web-icon brick_add"></span>'; } }, width: 20 @@ -29,8 +27,7 @@ Ext.define('PartKeepr.AbstractStockHistoryGrid', { header: i18n("User"), flex: 1, minWidth: 80, - renderer: function (val, p, rec) - { + renderer: function (val, p, rec) { if (rec.getUser() !== null) { return rec.getUser().get("username"); } @@ -55,8 +52,7 @@ Ext.define('PartKeepr.AbstractStockHistoryGrid', { }, dataIndex: 'price', width: 60, - renderer: function (val, p, rec) - { + renderer: function (val, p, rec) { if (rec.get("dir") == "out") { return "-"; } else { @@ -79,8 +75,7 @@ Ext.define('PartKeepr.AbstractStockHistoryGrid', { /** * Initializes the stock history grid. */ - initComponent: function () - { + initComponent: function () { this.defineColumns(); @@ -115,7 +110,7 @@ Ext.define('PartKeepr.AbstractStockHistoryGrid', { }); - this.dockedItems = new Array(); + this.dockedItems = []; this.dockedItems.push(this.bottomToolbar); this.editing.on("beforeedit", this.onBeforeEdit, this); @@ -128,8 +123,7 @@ Ext.define('PartKeepr.AbstractStockHistoryGrid', { * @param e Passed from ExtJS * @returns {Boolean} */ - onBeforeEdit: function (e) - { + onBeforeEdit: function (e) { // Checks if the usernames match var sameUser = e.record.get("username") == PartKeepr.getApplication().getUsername(); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraModel.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraModel.js @@ -10,13 +10,14 @@ Ext.define("PartKeepr.data.HydraModel", { * * @param {String} action The action name * @param {Object} parameters (optional) The parameters as JS object - * @param {Function} callback (optional) A callback function + * @param {Function} callback (optional) A callback function, or null if not required + * @param {boolean} reload (optional) Triggers a reload of the model after executing the action */ - callAction: function (action, parameters, callback) + callAction: function (action, parameters, callback, reload) { var proxy = this.getProxy(); - proxy.callAction(this, action, parameters, callback); + proxy.callAction(this, action, parameters, callback, reload); }, getData: function (options) { diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraProxy.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraProxy.js @@ -77,7 +77,7 @@ Ext.define("PartKeepr.data.HydraProxy", { * * */ - callAction: function (record, action, parameters, callback) + callAction: function (record, action, parameters, callback, reload) { var url = record.getId() + "/" + action; var request = Ext.create("Ext.data.Request"); @@ -94,6 +94,10 @@ Ext.define("PartKeepr.data.HydraProxy", { { this.processCallActionResponse(options, success, response); + if (reload) { + record.load(); + } + if (Ext.isFunction(callback)) { callback(options, success, response); } diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Util/ServiceCall.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Util/ServiceCall.js @@ -87,18 +87,8 @@ Ext.define('PartKeepr.ServiceCall', { try { var response = Ext.decode(responseObj.responseText); } catch (ex) { - var exception = { - message: i18n("Critical Error"), - detail: i18n("The server returned a response which we were not able to interpret.") - }; - - var request = { - response: responseObj.responseText, - request: Ext.encode(options) - }; - - PartKeepr.ExceptionWindow.showException(exception, request); + PartKeepr.ExceptionWindow.showException(responseObj); return; } @@ -142,33 +132,7 @@ Ext.define('PartKeepr.ServiceCall', { { var request; - try { - var data = Ext.decode(response.responseText); - - request = { - response: response.responseText, - request: Ext.encode(options) - }; - - PartKeepr.ExceptionWindow.showException(data, request); - } catch (ex) { - - var exception = { - message: i18n("Critical Error"), - detail: i18n("The server returned a response which we were not able to interpret."), - backtrace: response.responseText - }; - - request = { - response: response.responseText, - request: Ext.encode(options) - }; - - PartKeepr.ExceptionWindow.showException(exception, request); - - - } - + PartKeepr.ExceptionWindow.showException(response); PartKeepr.getApplication().getStatusbar().endLoad(); }, displayError: function (obj)