partkeepr

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

commit 40fd438a306d7f0d69cff948549ae667db641302
parent 24fb374ba11f229f8e9e637f87eeb0b77f68add3
Author: Felicitus <felicitus@felicitus.org>
Date:   Wed, 24 Jun 2015 16:44:59 +0200

Added implementation for editing Part Measurement Units

Diffstat:
Mapp/AppKernel.php | 4++--
Mapp/config/config.yml | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Mcomposer.lock | 8++++----
Msrc/PartKeepr/DoctrineReflectionBundle/Resources/views/model.js.twig | 4++--
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Editor/EditorComponent.js | 1-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/MenuBar.js | 2+-
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Components/PartMeasurementUnit/PartMeasurementUnitEditor.js | 14++++++++++++++
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Components/PartMeasurementUnit/PartMeasurementUnitEditorComponent.js | 21+++++++++++++++++++++
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Components/PartMeasurementUnit/PartMeasurementUnitGrid.js | 46++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/PartKeepr/FrontendBundle/Resources/public/js/Components/PartUnit/PartUnitEditor.js | 14--------------
Dsrc/PartKeepr/FrontendBundle/Resources/public/js/Components/PartUnit/PartUnitEditorComponent.js | 22----------------------
Dsrc/PartKeepr/FrontendBundle/Resources/public/js/Components/PartUnit/PartUnitGrid.js | 53-----------------------------------------------------
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraModel.js | 21+++++++++++++++++++++
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraProxy.js | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/PartKeepr/FrontendBundle/Resources/public/js/Data/RestProxy.js | 87-------------------------------------------------------------------------------
Msrc/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js | 40+++++++++++++++++++++++++++++++++++++---
Msrc/PartKeepr/FrontendBundle/Resources/views/index.html.twig | 9+++++----
Dsrc/PartKeepr/PartBundle/Controller/DefaultController.php | 19-------------------
Asrc/PartKeepr/PartBundle/Controller/PartMeasurementUnitController.php | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/PartBundle/Entity/PartMeasurementUnit.php | 135+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/PartBundle/Resources/translations/validators.en.yml | 3+++
Dsrc/PartKeepr/PartBundle/Tests/Controller/DefaultControllerTest.php | 13-------------
Msrc/backend/PartKeepr/Part/Part.php | 18+++++++++++-------
Dsrc/backend/PartKeepr/Part/PartUnit.php | 139-------------------------------------------------------------------------------
Msrc/backend/PartKeepr/PartKeepr.php | 2+-
Dsrc/backend/PartKeepr/PartUnit/PartUnitManager.php | 107-------------------------------------------------------------------------------
Dsrc/backend/PartKeepr/PartUnit/PartUnitService.php | 73-------------------------------------------------------------------------
Msrc/backend/PartKeepr/Setup/PartUnitSetup.php | 8++++----
Msrc/backend/PartKeepr/Statistic/StatisticService.php | 6+++---
Msrc/backend/PartKeepr/Statistic/StatisticSnapshotManager.php | 14++++++--------
Msrc/backend/PartKeepr/Statistic/StatisticSnapshotUnit.php | 16++++++++--------
Dsrc/backend/PartKeepr/Unit/UnitManager.php | 100-------------------------------------------------------------------------------
Dsrc/backend/PartKeepr/Unit/UnitService.php | 69---------------------------------------------------------------------
33 files changed, 531 insertions(+), 758 deletions(-)

diff --git a/app/AppKernel.php b/app/AppKernel.php @@ -59,8 +59,6 @@ class AppKernel extends Kernel new PartKeepr\DoctrineReflectionBundle\PartKeeprDoctrineReflectionBundle(), new PartKeepr\RESTBundle\PartKeeprRESTBundle(), new PartKeepr\ApiDocBundle\PartKeeprApiDocBundle(), - new PartKeepr\UnitBundle\PartKeeprUnitBundle(), - new PartKeepr\PartBundle\PartKeeprPartBundle(), new Dunglas\ApiBundle\DunglasApiBundle(), ); @@ -77,6 +75,8 @@ class AppKernel extends Kernel $bundles[] = new PartKeepr\SiPrefixBundle\PartKeeprSiPrefixBundle(); $bundles[] = new PartKeepr\AuthBundle\PartKeeprAuthBundle(); $bundles[] = new PartKeepr\FootprintBundle\PartKeeprFootprintBundle(); + $bundles[] = new PartKeepr\UnitBundle\PartKeeprUnitBundle(); + $bundles[] = new PartKeepr\PartBundle\PartKeeprPartBundle(); return $bundles; } diff --git a/app/config/config.yml b/app/config/config.yml @@ -84,8 +84,8 @@ twig: exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction' dunglas_api: - title: "Your API name" # The title of the API. - description: "The full description of your API" # The description of the API. + title: "PartKeepr" + description: "The PartKeepr REST API" collection: pagination: items_per_page: @@ -102,31 +102,74 @@ nelmio_api_doc: json: "application/json" services: - resource.unit: + resource.order_filter: + parent: "api.doctrine.orm.order_filter" + arguments: [ ~ ] # This line can also be omitted + + resource.partmeasurementunit.item_operation.custom_put: + class: "Dunglas\ApiBundle\Api\Operation\Operation" + public: false + factory: [ "@api.operation_factory", "createItemOperation" ] + arguments: + - "@resource.partmeasurementunit" # Resource + - [ "PUT" ] # Methods + - "/part_measurement_units/{id}/setDefault" # Path + - "PartKeeprPartBundle:PartMeasurementUnit:setDefault" # Controller + - "my_custom_route" # Route name + - # Context (will be present in Hydra documentation) + "@type": "hydra:Operation" + "hydra:title": "A custom operation" + "returns": "xmls:string" + resource.partmeasurementunit.item_operation.get: + class: "Dunglas\ApiBundle\Api\Operation\Operation" + public: false + factory: [ "@api.operation_factory", "createItemOperation" ] + arguments: [ "@resource.partmeasurementunit", "GET" ] + + resource.partmeasurementunit.item_operation.put: + class: "Dunglas\ApiBundle\Api\Operation\Operation" + public: false + factory: [ "@api.operation_factory", "createItemOperation" ] + arguments: [ "@resource.partmeasurementunit", "PUT" ] + + resource.partmeasurementunit: parent: "api.resource" - arguments: [ "PartKeepr\UnitBundle\Entity\Unit" ] + arguments: [ "PartKeepr\\PartBundle\\Entity\\PartMeasurementUnit" ] tags: [ { name: "api.resource" } ] calls: + - method: "initItemOperations" + arguments: [ [ "@resource.partmeasurementunit.item_operation.custom_put", "@resource.partmeasurementunit.item_operation.get", "@resource.partmeasurementunit.item_operation.put" ] ] - method: "initFilters" - arguments: [ [ "@resource.unit.order_filter" ] ] + arguments: [ [ "@resource.order_filter" ] ] - method: "initNormalizationContext" arguments: [ { groups: [ "default" ] } ] - method: "initDenormalizationContext" arguments: - { groups: [ "default" ] } - resource.unit.order_filter: - parent: "api.doctrine.orm.order_filter" - arguments: [ ~ ] # This line can also be omitted - resource.siprefix: + + + resource.unit: parent: "api.resource" - arguments: [ "PartKeepr\SiPrefixBundle\Entity\SiPrefix" ] + arguments: [ "PartKeepr\\UnitBundle\Entity\Unit" ] tags: [ { name: "api.resource" } ] calls: - method: "initFilters" - arguments: [ [ "@resource.unit.order_filter" ] ] + arguments: [ [ "@resource.order_filter" ] ] + - method: "initNormalizationContext" + arguments: [ { groups: [ "default" ] } ] - method: "initDenormalizationContext" arguments: - { groups: [ "default" ] } - api.name_converter: - class: Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter- \ No newline at end of file + resource.siprefix: + parent: "api.resource" + arguments: [ "PartKeepr\\SiPrefixBundle\\Entity\\SiPrefix" ] + tags: [ { name: "api.resource" } ] + calls: + - method: "initFilters" + arguments: [ [ "@resource.order_filter" ] ] + - method: "initNormalizationContext" + arguments: [ { groups: [ "default" ] } ] + - method: "initDenormalizationContext" + arguments: + - { groups: [ "default" ] }+ \ No newline at end of file diff --git a/composer.lock b/composer.lock @@ -1036,12 +1036,12 @@ "source": { "type": "git", "url": "https://github.com/dunglas/DunglasApiBundle.git", - "reference": "ed716bcb2717187b6ac91bc2bf89cb5cd1b8ec1f" + "reference": "2e8bed5b85931cfedd57d6887d4267ad3da6d36c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dunglas/DunglasApiBundle/zipball/ed716bcb2717187b6ac91bc2bf89cb5cd1b8ec1f", - "reference": "ed716bcb2717187b6ac91bc2bf89cb5cd1b8ec1f", + "url": "https://api.github.com/repos/dunglas/DunglasApiBundle/zipball/2e8bed5b85931cfedd57d6887d4267ad3da6d36c", + "reference": "2e8bed5b85931cfedd57d6887d4267ad3da6d36c", "shasum": "" }, "require": { @@ -1102,7 +1102,7 @@ "json", "rest" ], - "time": "2015-06-22 14:15:43" + "time": "2015-06-23 09:28:39" }, { "name": "dunglas/php-property-info", diff --git a/src/PartKeepr/DoctrineReflectionBundle/Resources/views/model.js.twig b/src/PartKeepr/DoctrineReflectionBundle/Resources/views/model.js.twig @@ -1,5 +1,5 @@ Ext.define('{{ className }}', { - extend: 'Ext.data.Model', + extend: 'PartKeepr.data.HydraModel', alias: 'schema.{{ className }}', idProperty: "@id", @@ -23,7 +23,7 @@ Ext.define('{{ className }}', { {% endif %} proxy: { - type: "PartKeeprREST", + type: "Hydra", url: '{% if uri == "" %}undefined:{{ className }}{% else %}{{ uri|raw }}{% endif %}' } }); \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Editor/EditorComponent.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Editor/EditorComponent.js @@ -91,7 +91,6 @@ Ext.define('PartKeepr.EditorComponent', { * @param {Record} record The record to edit */ startEdit: function (id) { - console.log(id); /* Search for an open editor for the current record. If we * already have an editor, show the editor instead of loading * a new record. diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/MenuBar.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/MenuBar.js @@ -238,7 +238,7 @@ Ext.define('PartKeepr.MenuBar', { j.show(); }, editPartUnits: function () { - var j = Ext.create("PartKeepr.PartUnitEditorComponent", { + var j = Ext.create("PartKeepr.PartMeasurementUnitEditorComponent", { title: i18n("Part Measurement Units"), iconCls: 'icon-ruler', closable: true diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/PartMeasurementUnit/PartMeasurementUnitEditor.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/PartMeasurementUnit/PartMeasurementUnitEditor.js @@ -0,0 +1,14 @@ +Ext.define('PartKeepr.PartMeasurementUnitEditor', { + extend: 'PartKeepr.Editor', + alias: 'widget.PartMeasurementUnitEditor', + items: [{ + xtype: 'textfield', + name: 'name', + fieldLabel: i18n("Measurement Unit Name") + },{ + xtype: 'textfield', + name: 'shortName', + fieldLabel: i18n("Short Name") + }], + saveText: i18n("Save Part Measurement Unit") +}); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/PartMeasurementUnit/PartMeasurementUnitEditorComponent.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/PartMeasurementUnit/PartMeasurementUnitEditorComponent.js @@ -0,0 +1,20 @@ +Ext.define('PartKeepr.PartMeasurementUnitEditorComponent', { + extend: 'PartKeepr.EditorComponent', + alias: 'widget.PartMeasurementUnitEditorComponent', + navigationClass: 'PartKeepr.PartMeasurementUnitGrid', + editorClass: 'PartKeepr.PartMeasurementUnitEditor', + newItemText: i18n("New Part Measurement Unit"), + deleteMessage: i18n("Do you really wish to delete the part measurement unit'%s'?"), + deleteTitle: i18n("Delete Part Measurement Unit"), + model: 'PartKeepr.PartBundle.Entity.PartMeasurementUnit', + initComponent: function () { + this.createStore({ + sorters: [{ + property: 'name', + direction:'ASC' + }] + }); + + this.callParent(); + } +});+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/PartMeasurementUnit/PartMeasurementUnitGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/PartMeasurementUnit/PartMeasurementUnitGrid.js @@ -0,0 +1,45 @@ +Ext.define('PartKeepr.PartMeasurementUnitGrid', { + extend: 'PartKeepr.EditorGrid', + alias: 'widget.PartMeasurementUnitGrid', + columns: [ + {header: i18n("Part Measurement Unit"), dataIndex: 'name', flex: 1}, + {header: i18n("Default"), dataIndex: 'isDefault', width: 60, renderer: function (val) { if (val === true) { return "✓"; } else { return ""; }}} + ], + addButtonText: i18n("Add Part Measurement Unit"), + addButtonIcon: "resources/fugue-icons/icons/ruler--plus.png", + deleteButtonText: i18n("Delete Part Measurement Unit"), + deleteButtonIcon: "resources/fugue-icons/icons/ruler--minus.png", + defaultButtonIcon: "resources/fugue-icons/icons/ruler--pencil.png", + automaticPageSize: true, + initComponent: function () { + this.callParent(); + + this.defaultButton = Ext.create("Ext.button.Button", { + icon: this.defaultButtonIcon, + tooltip: i18n('Mark Part Measurement Unit as Default'), + disabled: true, + handler: this.onDefaultClick, + scope: this + }); + + this.getSelectionModel().on("deselect", + Ext.bind(function (rsm, r, i) { + this.defaultButton.disable(); + }, this)); + + this.getSelectionModel().on("select", + Ext.bind(function (rsm, r, i) { + this.defaultButton.enable(); + }, this)); + this.topToolbar.insert(2, {xtype: 'tbseparator'}); + this.topToolbar.insert(3, this.defaultButton); + }, + onDefaultClick: function () { + var r = this.getSelectionModel().getLastSelected(); + + r.callAction("setDefault", {}, this.onDefaultHandler.bind(this)); + }, + onDefaultHandler: function () { + this.store.load(); + } +});+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/PartUnit/PartUnitEditor.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/PartUnit/PartUnitEditor.js @@ -1,14 +0,0 @@ -Ext.define('PartKeepr.PartUnitEditor', { - extend: 'PartKeepr.Editor', - alias: 'widget.PartUnitEditor', - items: [{ - xtype: 'textfield', - name: 'name', - fieldLabel: i18n("Measurement Unit Name") - },{ - xtype: 'textfield', - name: 'shortName', - fieldLabel: i18n("Short Name") - }], - saveText: i18n("Save Part Measurement Unit") -}); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/PartUnit/PartUnitEditorComponent.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/PartUnit/PartUnitEditorComponent.js @@ -1,21 +0,0 @@ -Ext.define('PartKeepr.PartUnitEditorComponent', { - extend: 'PartKeepr.EditorComponent', - alias: 'widget.PartUnitEditorComponent', - navigationClass: 'PartKeepr.PartUnitGrid', - editorClass: 'PartKeepr.PartUnitEditor', - newItemText: i18n("New Part Measurement Unit"), - deleteMessage: i18n("Do you really wish to delete the part measurement unit'%s'?"), - deleteTitle: i18n("Delete Part Measurement Unit"), - model: 'PartKeepr.Part.PartUnit', - initComponent: function () { - this.createStore({ - sorters: [{ - proxy: PartKeepr.getRESTProxy("PartUnit"), - property: 'name', - direction:'ASC' - }] - }); - - this.callParent(); - } -});- \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/PartUnit/PartUnitGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/PartUnit/PartUnitGrid.js @@ -1,52 +0,0 @@ -Ext.define('PartKeepr.PartUnitGrid', { - extend: 'PartKeepr.EditorGrid', - alias: 'widget.PartUnitGrid', - columns: [ - {header: i18n("Part Measurement Unit"), dataIndex: 'name', flex: 1}, - {header: i18n("Default"), dataIndex: 'default', width: 60, renderer: function (val) { if (val === true) { return "✓"; } else { return ""; }}} - ], - addButtonText: i18n("Add Part Measurement Unit"), - addButtonIcon: "resources/fugue-icons/icons/ruler--plus.png", - deleteButtonText: i18n("Delete Part Measurement Unit"), - deleteButtonIcon: "resources/fugue-icons/icons/ruler--minus.png", - defaultButtonIcon: "resources/fugue-icons/icons/ruler--pencil.png", - automaticPageSize: true, - initComponent: function () { - this.callParent(); - - this.defaultButton = Ext.create("Ext.button.Button", { - icon: this.defaultButtonIcon, - tooltip: i18n('Mark Part Measurement Unit as Default'), - disabled: true, - handler: this.onDefaultClick, - scope: this - }); - - this.getSelectionModel().on("deselect", - Ext.bind(function (rsm, r, i) { - this.defaultButton.disable(); - }, this)); - - this.getSelectionModel().on("select", - Ext.bind(function (rsm, r, i) { - this.defaultButton.enable(); - }, this)); - this.topToolbar.insert(2, {xtype: 'tbseparator'}); - this.topToolbar.insert(3, this.defaultButton); - }, - onDefaultClick: function () { - var r = this.getSelectionModel().getLastSelected(); - - var call = new PartKeepr.ServiceCall( - "PartUnit", - "setDefault"); - - call.setParameter("id", r.get("id")); - - call.setHandler(Ext.bind(this.onDefaultHandler, this)); - call.doCall(); - }, - onDefaultHandler: function () { - this.store.load(); - } -});- \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraModel.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraModel.js @@ -0,0 +1,20 @@ +Ext.define("PartKeepr.data.HydraModel", { + extend: 'Ext.data.Model', + + /** + * Calls an action relative to the entity. + * + * For example, if the entity has a method called "setDefault" and your ID is + * "/PartKeepr/web/app_dev.php/api/part_measurement_units/1", callAction would call + * "/PartKeepr/web/app_dev.php/api/part_measurement_units/1/setDefault" as a result. + * + * @param {String} action The action name + * @param {Object} parameters (optional) The parameters as JS object + * @param {Function} callback (optional) A callback function + */ + callAction: function (action, parameters, callback) { + var proxy = this.getProxy(); + + proxy.callAction(this, action, parameters, callback); + } +});+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraProxy.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraProxy.js @@ -0,0 +1,100 @@ +Ext.define("PartKeepr.data.HydraProxy", { + extend: 'Ext.data.proxy.Rest', + alias: 'proxy.Hydra', + + reader: { + type: 'hydra' + }, + writer: { + type: 'jsonwithassociations' + }, + appendId: false, + limitParam: "itemsPerPage", + sortParam: "", + + constructor: function (config) { + config.url = PartKeepr.getBasePath() + config.url; + this.callParent(arguments); + }, + listeners: { + exception: function (reader, response, operation, eOpts) { + var request = operation.getRequest(); + + var requestParams = { + method: response.request.options.method, + request: response.request.options.jsonData, + response: response.responseText + }; + try { + var data = Ext.decode(response.responseText); + + PartKeepr.ExceptionWindow.showException(data.exception, response); + } catch (ex) { + var exception = { + message: i18n("Critical Error"), + detail: i18n("The server returned a response which we were not able to interpret.") + }; + + PartKeepr.ExceptionWindow.showException(exception, response); + } + } + }, + buildUrl: function (request) { + var operation = request.getOperation(); + + // Set the URI to the ID, as JSON-LD operates on IRIs. + if (request.getAction() == "read") { + if (operation.getId()) { + request.setUrl(operation.getId()); + } + } + + if (request.getAction() == "update") { + if (request.getRecords().length != 1) { + throw "The amount of records updating must be exactly one"; + } + this.api.update = request.getRecords()[0].getId(); + } + + if (request.getAction() == "destroy") { + if (request.getRecords().length != 1) { + throw "The amount of records updating must be exactly one"; + } + this.api.destroy = request.getRecords()[0].getId(); + } + + return this.callParent([request]); + }, + getParams: function (operation) { + if (!operation.isReadOperation) { + return {}; + } + + var params = this.callParent(arguments); + var out = [], + i, + sorters = operation.getSorters(); + + if (sorters) { + for (i = 0; i < operation.getSorters().length; i++) { + params["order[" + sorters[i].getProperty() + "]"] = sorters[i].getDirection(); + } + } + + return params; + }, + callAction: function (record, action, parameters, callback) { + var url = record.getId() + "/" + action; + var request = Ext.create("Ext.data.Request"); + + request.setMethod("PUT"); + request.setUrl(url); + if (typeof parameters == "object") { + request.setParams(parameters); + } + + request.setCallback(callback); + + this.sendRequest(request); + } +});+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Data/RestProxy.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Data/RestProxy.js @@ -1,86 +0,0 @@ -Ext.define("PartKeepr.data.RestProxy", { - extend: 'Ext.data.proxy.Rest', - alias: 'proxy.PartKeeprREST', - - reader: { - type: 'hydra' - }, - writer: { - type: 'jsonwithassociations' - }, - appendId: false, - limitParam: "itemsPerPage", - sortParam: "", - - constructor: function (config) { - config.url = PartKeepr.getBasePath() + config.url; - this.callParent(arguments); - }, - listeners: { - exception: function (reader, response, operation, eOpts) { - var request = operation.getRequest(); - - var requestParams = { - method: response.request.options.method, - request: response.request.options.jsonData, - response: response.responseText - }; - try { - var data = Ext.decode(response.responseText); - - PartKeepr.ExceptionWindow.showException(data.exception, response); - } catch (ex) { - var exception = { - message: i18n("Critical Error"), - detail: i18n("The server returned a response which we were not able to interpret.") - }; - - PartKeepr.ExceptionWindow.showException(exception, response); - } - } - }, - buildUrl: function (request) { - var operation = request.getOperation(); - - // Set the URI to the ID, as JSON-LD operates on IRIs. - if (request.getAction() == "read") { - if (operation.getId()) { - request.setUrl(operation.getId()); - } - } - - if (request.getAction() == "update") { - if (request.getRecords().length != 1) { - throw "The amount of records updating must be exactly one"; - } - this.api.update = request.getRecords()[0].getId(); - } - - if (request.getAction() == "destroy") { - if (request.getRecords().length != 1) { - throw "The amount of records updating must be exactly one"; - } - this.api.destroy = request.getRecords()[0].getId(); - } - - return this.callParent([request]); - }, - getParams: function (operation) { - if (!operation.isReadOperation) { - return {}; - } - - var params = this.callParent(arguments); - var out = [], - i, - sorters = operation.getSorters(); - - if (sorters) { - for (i = 0; i < operation.getSorters().length; i++) { - params["order[" + sorters[i].getProperty() + "]"] = sorters[i].getDirection(); - } - } - - return params; - } -});- \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js b/src/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js @@ -51,13 +51,47 @@ Ext.application({ * enables the menu bar and creates the stores+loads them. */ onLogin: function () { - var j = new Ext.create("PartKeepr.FootprintEditorComponent"); + var session = new Ext.data.Session(); + this.siPrefixStore = Ext.create("Ext.data.Store", + { + storeId: 'myStore', + model: 'PartKeepr.SiPrefixBundle.Entity.SiPrefix', + pageSize: 999, + autoLoad: true + }); + + this.fooStore = Ext.create("Ext.data.Store", + { + session: session, + model: 'PartKeepr.UnitBundle.Entity.Unit', + pageSize: 30, + autoLoad: false + }); + + this.fooStore2 = Ext.create("Ext.data.Store", + { + session: session, + model: 'PartKeepr.UnitBundle.Entity.Unit', + pageSize: 20, + autoLoad: false + }); + + + this.fooStore.load(); + this.fooStore2.load(); + + console.log(this.fooStore); + console.log(this.fooStore2); + + /*var j = new Ext.create("PartKeepr.FootprintEditorComponent"); var k = new Ext.create("Ext.Window", { + height: 400, items: j }); - k.show(); + k.show();*/ + this.menuBar.enable(); return; this.createGlobalStores(); @@ -263,7 +297,7 @@ Ext.application({ this.partUnitStore = Ext.create("Ext.data.Store", { - model: 'PartKeepr.Part.PartUnit', + model: 'PartKeepr.Part.PartMeasurementUnit', pageSize: -1, autoLoad: false }); diff --git a/src/PartKeepr/FrontendBundle/Resources/views/index.html.twig b/src/PartKeepr/FrontendBundle/Resources/views/index.html.twig @@ -52,7 +52,8 @@ '@PartKeeprFrontendBundle/Resources/public/js/Dialogs/ExceptionWindow.js' '@PartKeeprFrontendBundle/Resources/public/js/Dialogs/FileUploadDialog.js' '@PartKeeprFrontendBundle/Resources/public/js/Dialogs/RememberChoiceMessageBox.js' - '@PartKeeprFrontendBundle/Resources/public/js/Data/RestProxy.js' + '@PartKeeprFrontendBundle/Resources/public/js/Data/HydraProxy.js' + '@PartKeeprFrontendBundle/Resources/public/js/Data/HydraModel.js' '@PartKeeprFrontendBundle/Resources/public/js/Data/HydraReader.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Statusbar.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Auth/LoginDialog.js' @@ -79,7 +80,7 @@ '@PartKeeprFrontendBundle/Resources/public/js/Components/Distributor/DistributorGrid.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Part/PartsGrid.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerGrid.js' - '@PartKeeprFrontendBundle/Resources/public/js/Components/PartUnit/PartUnitGrid.js' + '@PartKeeprFrontendBundle/Resources/public/js/Components/PartMeasurementUnit/PartMeasurementUnitGrid.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Unit/UnitGrid.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/User/UserGrid.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/SystemNotice/SystemNoticeGrid.js' @@ -122,7 +123,7 @@ '@PartKeeprFrontendBundle/Resources/public/js/Components/Distributor/DistributorEditor.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Part/Editor/PartEditor.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerEditor.js' - '@PartKeeprFrontendBundle/Resources/public/js/Components/PartUnit/PartUnitEditor.js' + '@PartKeeprFrontendBundle/Resources/public/js/Components/PartMeasurementUnit/PartMeasurementUnitEditor.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Unit/UnitEditor.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Footprint/FootprintEditor.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/User/UserEditor.js' @@ -132,7 +133,7 @@ '@PartKeeprFrontendBundle/Resources/public/js/Components/Editor/EditorComponent.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Distributor/DistributorEditorComponent.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerEditorComponent.js' - '@PartKeeprFrontendBundle/Resources/public/js/Components/PartUnit/PartUnitEditorComponent.js' + '@PartKeeprFrontendBundle/Resources/public/js/Components/PartMeasurementUnit/PartMeasurementUnitEditorComponent.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Unit/UnitEditorComponent.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Footprint/FootprintEditorComponent.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/User/UserEditorComponent.js' diff --git a/src/PartKeepr/PartBundle/Controller/DefaultController.php b/src/PartKeepr/PartBundle/Controller/DefaultController.php @@ -1,19 +0,0 @@ -<?php - -namespace PartKeepr\PartBundle\Controller; - -use Symfony\Bundle\FrameworkBundle\Controller\Controller; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; - -class DefaultController extends Controller -{ - /** - * @Route("/hello/{name}") - * @Template() - */ - public function indexAction($name) - { - return array('name' => $name); - } -} diff --git a/src/PartKeepr/PartBundle/Controller/PartMeasurementUnitController.php b/src/PartKeepr/PartBundle/Controller/PartMeasurementUnitController.php @@ -0,0 +1,48 @@ +<?php +namespace PartKeepr\PartBundle\Controller; + +use Doctrine\ORM\EntityManager; +use Dunglas\ApiBundle\Controller\ResourceController; +use Dunglas\ApiBundle\JsonLd\Response; +use Symfony\Component\HttpFoundation\Request; + +class PartMeasurementUnitController extends ResourceController +{ + public function setDefaultAction(Request $request, $id) + { + /** + * @var $em EntityManager + */ + $em = $this->get("doctrine")->getEntityManager(); + + $em->beginTransaction(); + + $resource = $this->getResource($request); + $this->findOrThrowNotFound($resource, $id); + + + + $dql = 'UPDATE PartKeepr\PartBundle\Entity\PartMeasurementUnit pu SET pu.isDefault = :default WHERE pu.id = :id'; + + $em->createQuery($dql) + ->setParameter("id", $id) + ->setParameter( + "default", + true, + \PDO::PARAM_BOOL + )->execute(); + + $dql = 'UPDATE PartKeepr\PartBundle\Entity\PartMeasurementUnit pu SET pu.isDefault = :default WHERE pu.id != :id'; + + $em->createQuery($dql) + ->setParameter("id", $id) + ->setParameter( + "default", + false, + \PDO::PARAM_BOOL + )->execute(); + + $em->commit(); + return new Response(); + } +}+ \ No newline at end of file diff --git a/src/PartKeepr/PartBundle/Entity/PartMeasurementUnit.php b/src/PartKeepr/PartBundle/Entity/PartMeasurementUnit.php @@ -0,0 +1,134 @@ +<?php +namespace PartKeepr\PartBundle\Entity; + +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\Mapping as ORM; +use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService; +use PartKeepr\Util\BaseEntity; +use Symfony\Component\Serializer\Annotation\Groups; +use Symfony\Component\Validator\Constraints as Assert; + +/** + * This entity represents a part measurement unit. Typical measurement units are pieces, centimeters etc. + * + * @ORM\Entity + * @ORM\Table(name="PartUnit") + * @TargetService(uri="/api/part_measurement_units") + **/ +class PartMeasurementUnit extends BaseEntity { + /** + * Defines the name of the unit + * + * @ORM\Column(type="string") + * @Groups({"default"}) + * + * @Assert\Type(type="string") + * @Assert\NotBlank(message="partMeasurementUnit.name.not_blank") + * + * @var string + */ + private $name; + + /** + * Defines the short name of the unit + * + * @ORM\Column(type="string") + * @Groups({"default"}) + * + * @Assert\Type(type="string") + * @Assert\NotBlank(message="partMeasurementUnit.shortName.not_blank") + * + * @var string + */ + private $shortName; + + /** + * Defines if the unit is default or not. Note that this property may not be set directly. + * + * @ORM\Column(type="boolean", name="is_default") + * @Groups({"default"}) + * + * @var boolean + */ + private $isDefault; + + /** + * The parts used by this PartMeasurementUnit + * + * @ORM\OneToMany(targetEntity="PartKeepr\Part\Part",mappedBy="partUnit") + */ + private $parts; + + + /** + * Creates a new part unit. + * + * Sets the default to false. + */ + public function __construct () { + $this->parts = new ArrayCollection(); + $this->setIsDefault(false); + } + + /** + * Sets the name for this unit + * @param string $name The name for this unit + */ + public function setName ($name) { + $this->name = $name; + } + + /** + * Returns the name for this unit + * @param none + * @return string The name for this unit + */ + public function getName () { + return $this->name; + } + + /** + * Sets the short name for this unit. + * + * Short names are used for list views (e.g. if your unit name is "metres", your short name could be "m") + * @param string $shortName The short name + */ + public function setShortName ($shortName) { + $this->shortName = $shortName; + } + + /** + * Returns the short name for this unit + * @param none + * @return string The short name for this unit + */ + public function getShortName () { + return $this->shortName; + } + + /** + * Defines if the unit is default or not. + * @param boolean $default True if the unit is default, false otherwise + */ + public function setIsDefault ($default) { + $this->isDefault = (bool)$default; + } + + /** + * Returns if the unit is default or not + * @param none + * @return boolean True if the unit is default, false for not + */ + public function getIsDefault () { + return $this->isDefault; + } + + /** + * Returns the parts for this PartUnit + * @return ArrayCollection + */ + public function getParts () { + return $this->parts; + } +} + + \ No newline at end of file diff --git a/src/PartKeepr/PartBundle/Resources/translations/validators.en.yml b/src/PartKeepr/PartBundle/Resources/translations/validators.en.yml @@ -0,0 +1,2 @@ +partMeasurementUnit.name.not_blank: The name may not be blank. +partMeasurementUnit.shortName.not_blank: The short name may not be blank.+ \ No newline at end of file diff --git a/src/PartKeepr/PartBundle/Tests/Controller/DefaultControllerTest.php b/src/PartKeepr/PartBundle/Tests/Controller/DefaultControllerTest.php @@ -1,13 +0,0 @@ -<?php - -namespace PartKeepr\PartBundle\Tests\Controller; - -use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; - -class DefaultControllerTest extends WebTestCase -{ - public function testIndex() - { - - } -} diff --git a/src/backend/PartKeepr/Part/Part.php b/src/backend/PartKeepr/Part/Part.php @@ -1,6 +1,7 @@ <?php namespace PartKeepr\Part; +use PartKeepr\PartBundle\Entity\PartMeasurementUnit; use PartKeepr\StorageLocation\StorageLocation, \PartKeepr\FootprintBundle\Entity\Footprint, \PartKeepr\PartBundle\Entity\PartCategoryManager, @@ -54,8 +55,9 @@ class Part extends BaseEntity implements Serializable, Deserializable { /** * The unit in which the part's "amount" is calculated. This is necessary to count parts * in "pieces", "meters" or "grams". - * @ORM\ManyToOne(targetEntity="PartKeepr\Part\PartUnit", inversedBy="parts") - * @var PartUnit + * @ORM\ManyToOne(targetEntity="PartKeepr\PartBundle\Entity\PartMeasurementUnit", inversedBy="parts") + * + * @var PartMeasurementUnit */ private $partUnit; @@ -241,10 +243,11 @@ class Part extends BaseEntity implements Serializable, Deserializable { /** * Sets the part unit * - * @param PartUnit $partUnit The part unit object to set - * @return nothing + * @param PartMeasurementUnit $partUnit The part unit object to set + * +*@return nothing */ - public function setPartUnit (PartUnit $partUnit) { + public function setPartUnit(PartMeasurementUnit $partUnit) { $this->partUnit = $partUnit; } @@ -252,7 +255,8 @@ class Part extends BaseEntity implements Serializable, Deserializable { * Returns the part unit * * @param none - * @return PartUnit The part unit object + * +*@return PartMeasurementUnit The part unit object */ public function getPartUnit () { return $this->partUnit; @@ -567,7 +571,7 @@ class Part extends BaseEntity implements Serializable, Deserializable { $this->setMinStockLevel($value); break; case "partUnit": - $partUnit = PartUnit::loadById($value); + $partUnit = PartMeasurementUnit::loadById($value); $this->setPartUnit($partUnit); break; case "category": diff --git a/src/backend/PartKeepr/Part/PartUnit.php b/src/backend/PartKeepr/Part/PartUnit.php @@ -1,138 +0,0 @@ -<?php -namespace PartKeepr\Part; - -use PartKeepr\Util\Deserializable, - PartKeepr\Util\Serializable, - PartKeepr\Util\BaseEntity, - PartKeepr\PartKeepr, - PartKeepr\Util\Exceptions\OutOfRangeException, - Doctrine\ORM\Mapping as ORM; - - -/** @ORM\Entity **/ -class PartUnit extends BaseEntity implements Serializable, Deserializable { - /** - * Defines the name of the unit - * @ORM\Column - * @var string - */ - private $name; - - /** - * Defines the short name of the unit - * @ORM\Column - * @var string - */ - private $shortName; - - /** - * Defines if the unit is default or not. - * - * @ORM\Column(type="boolean") - * @var boolean - */ - private $is_default; - - /** - * @ORM\OneToMany(targetEntity="PartKeepr\Part\Part",mappedBy="partUnit") - */ - private $parts; - - - /** - * Creates a new part unit. - * - * Sets the default to false. - */ - public function __construct () { - $this->setDefault(false); - } - - /** - * Sets the name for this unit - * @param string $name The name for this unit - * @return nothing - */ - public function setName ($name) { - $this->name = $name; - } - - /** - * Returns the name for this unit - * @param none - * @return string The name for this unit - */ - public function getName () { - return $this->name; - } - - /** - * Sets the short name for this unit. - * - * Short names are used for list views (e.g. if your unit name is "metres", your short name could be "m") - * @param string $shortName The short name - * @return nothing - */ - public function setShortName ($shortName) { - $this->shortName = $shortName; - } - - /** - * Returns the short name for this unit - * @param none - * @return string The short name for this unit - */ - public function getShortName () { - return $this->shortName; - } - - /** - * Defines if the unit is default or not. - * @param boolean $default True if the unit is default, false otherwise - */ - public function setDefault ($default) { - $this->is_default = (bool)$default; - } - - /** - * Returns if the unit is default or not - * @param none - * @return boolean True if the unit is default, false for not - */ - public function getDefault () { - return $this->is_default; - } - - /** - * Serializes the object and returns it as array, suitable - * to process via json_encode. - * @param none - * @return array An array containing the object information - */ - public function serialize () { - return array( - "id" => $this->getId(), - "name" => $this->getName(), - "shortName" => $this->getShortName(), - "default" => $this->getDefault() - ); - } - - /** - * Deserializes the manufacturer - * @param array $parameters The array with the parameters to set - */ - public function deserialize (array $parameters) { - foreach ($parameters as $key => $value) { - switch ($key) { - case "name": - $this->setName($value); - break; - case "shortName": - $this->setShortName($value); - break; - } - } - } -} - - \ No newline at end of file diff --git a/src/backend/PartKeepr/PartKeepr.php b/src/backend/PartKeepr/PartKeepr.php @@ -160,7 +160,7 @@ class PartKeepr { 'PartKeepr\FootprintBundle\Entity\FootprintCategory', 'PartKeepr\Part\Part', - 'PartKeepr\Part\PartUnit', + 'PartKeepr\PartBundle\Entity\PartUnit', 'PartKeepr\Part\PartManufacturer', 'PartKeepr\Part\PartDistributor', 'PartKeepr\Part\PartImage', diff --git a/src/backend/PartKeepr/PartUnit/PartUnitManager.php b/src/backend/PartKeepr/PartUnit/PartUnitManager.php @@ -1,106 +0,0 @@ -<?php -namespace PartKeepr\PartUnit; - -use PartKeepr\Util\Singleton, - PartKeepr\Part\PartUnit, - PartKeepr\PartKeepr, - PartKeepr\Category\CategoryManager, - PartKeepr\PartUnit\Exceptions\PartUnitNotFoundException; - -class PartUnitManager extends Singleton { - public function getPartUnits ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { - - $qb = PartKeepr::getEM()->createQueryBuilder(); - $qb->select("st.id, st.name, st.shortName, st.is_default AS default")->from("PartKeepr\Part\PartUnit","st"); - - if ($filter != "") { - $qb = $qb->where("LOWER(st.name) LIKE :filter"); - $qb->setParameter("filter", "%".strtolower($filter)."%"); - } - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $qb->orderBy("st.".$sort, $dir); - - $query = $qb->getQuery(); - - $result = $query->getResult(); - - foreach ($result as $key => $row) { - foreach ($row as $rowkey => $column) { - if ($rowkey == "default") { - if ($column == 0) { - $result[$key][$rowkey] = false; - } else { - $result[$key][$rowkey] = true; - } - } - } - } - - $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); - $totalQueryBuilder->select("COUNT(st.id)")->from("PartKeepr\Part\PartUnit","st"); - - - - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("LOWER(st.name) LIKE :filter"); - $totalQueryBuilder->setParameter("filter", "%".strtolower($filter)."%"); - } - - $totalQuery = $totalQueryBuilder->getQuery(); - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - public function getPartUnit ($id) { - $partUnit = PartKeepr::getEM()->find("PartKeepr\Part\PartUnit", $id); - - if ($partUnit) { - return $partUnit; - } else { - throw new PartUnitNotFoundException(); - } - } - - public function deletePartUnit ($id) { - $partUnit = $this->getPartUnit($id); - - PartKeepr::getEM()->remove($partUnit); - PartKeepr::getEM()->flush(); - } - - /** - * Returns the default part unit for this system - * - * @param none - * @return PartUnit The default part unit for this system - */ - public function getDefaultPartUnit () { - $dql = 'SELECT pu FROM PartKeepr\Part\PartUnit pu WHERE pu.is_default = :default'; - return PartKeepr::getEM()->createQuery($dql)->setParameter("default", true)->getSingleResult(); - } - - public function setDefaultPartUnit ($id) { - PartKeepr::getEM()->beginTransaction(); - - $dql = 'UPDATE PartKeepr\Part\PartUnit pu SET pu.is_default = :default WHERE pu.id = :id'; - PartKeepr::getEM()->createQuery($dql)->setParameter("id", $id)->setParameter("default", true, \PDO::PARAM_BOOL)->execute(); - - $dql = 'UPDATE PartKeepr\Part\PartUnit pu SET pu.is_default = :default WHERE pu.id != :id'; - PartKeepr::getEM()->createQuery($dql)->setParameter("id", $id)->setParameter("default", false, \PDO::PARAM_BOOL)->execute(); - - PartKeepr::getEM()->commit(); - } - - public function getUnitCounts () { - $dql = 'SELECT SUM(p.stockLevel) AS stockLevel, pu.id AS puid FROM PartKeepr\Part\PartUnit pu LEFT JOIN pu.parts p GROUP BY pu.id'; - - $result = PartKeepr::getEM()->createQuery($dql)->getResult(); - - return $result; - } -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/PartUnit/PartUnitService.php b/src/backend/PartKeepr/PartUnit/PartUnitService.php @@ -1,72 +0,0 @@ -<?php -namespace PartKeepr\PartUnit; -use PartKeepr\Service\RestfulService; - -use PartKeepr\Service\Service, - PartKeepr\PartKeepr, - PartKeepr\Part\PartUnit, - PartKeepr\Session\SessionManager; - -class PartUnitService extends Service implements RestfulService { - public function get () { - if ($this->hasParameter("id")) { - return array("data" => PartUnitManager::getInstance()->getPartUnit($this->getParameter("id"))->serialize()); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "name", - "direction" => "ASC"); - } - return PartUnitManager::getInstance()->getPartUnits( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $this->getParameter("query", "")); - } - } - - public function create () { - $this->requireParameter("name"); - - $partUnit = new PartUnit; - $partUnit->deserialize($this->getParameters()); - - PartKeepr::getEM()->persist($partUnit); - PartKeepr::getEM()->flush(); - - return array("data" => $partUnit->serialize()); - } - - public function update () { - $this->requireParameter("id"); - $this->requireParameter("name"); - - $partUnit = PartUnitManager::getInstance()->getPartUnit($this->getParameter("id")); - $partUnit->deserialize($this->getParameters()); - PartKeepr::getEM()->flush(); - - return array("data" => $partUnit->serialize()); - - } - - public function destroy () { - $this->requireParameter("id"); - - PartUnitManager::getInstance()->deletePartUnit($this->getParameter("id")); - - return array("data" => null); - } - - public function setDefault () { - $this->requireParameter("id"); - - $partUnit = PartUnitManager::getInstance()->setDefaultPartUnit($this->getParameter("id")); - - return array("data" => null); - } -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/Setup/PartUnitSetup.php b/src/backend/PartKeepr/Setup/PartUnitSetup.php @@ -2,7 +2,7 @@ namespace PartKeepr\Setup; use PartKeepr\PartKeepr, - PartKeepr\Part\PartUnit; + PartKeepr\PartBundle\Entity\PartMeasurementUnit; class PartUnitSetup extends AbstractSetup { /** @@ -15,15 +15,15 @@ class PartUnitSetup extends AbstractSetup { * Sets up the default part unit if none exists */ public function run () { - $dql = "SELECT COUNT(p) FROM PartKeepr\Part\PartUnit p WHERE p.is_default = :default"; + $dql = "SELECT COUNT(p) FROM PartKeepr\PartBundle\Entity\PartMeasurementUnit p WHERE p.is_default = :default"; $query = $this->entityManager->createQuery($dql); $query->setParameter("default", true); if ($query->getSingleScalarResult() == 0) { - $partUnit = new PartUnit(); + $partUnit = new PartMeasurementUnit(); $partUnit->setName(PartKeepr::i18n("Pieces")); $partUnit->setShortName(PartKeepr::i18n("pcs")); - $partUnit->setDefault(true); + $partUnit->setIsDefault(true); $this->entityManager->persist($partUnit); $this->entityManager->flush(); diff --git a/src/backend/PartKeepr/Statistic/StatisticService.php b/src/backend/PartKeepr/Statistic/StatisticService.php @@ -1,7 +1,7 @@ <?php namespace PartKeepr\Statistic; -use PartKeepr\Part\PartUnit, +use PartKeepr\PartBundle\Entity\PartMeasurementUnit, PartKeepr\Service\Service, PartKeepr\PartKeepr, PartKeepr\Part\PartManager, @@ -25,7 +25,7 @@ class StatisticService extends Service { foreach ($result as $row) { $aUnits[] = array( - "name" => PartUnit::loadById($row["puid"])->getName(), + "name" => PartMeasurementUnit::loadById($row["puid"])->getName(), "stockLevel" => $row["stockLevel"]); } @@ -84,7 +84,7 @@ class StatisticService extends Service { $queryEndTime = clone $start; $queryEndTime->add(new \DateInterval("PT".$intervalSize."S")); - $partUnitQuery = "SELECT pu FROM PartKeepr\Part\PartUnit pu"; + $partUnitQuery = "SELECT pu FROM PartKeepr\PartBundle\Entity\PartUnit pu"; $query = PartKeepr::getEM()->createQuery($partUnitQuery); $aPartUnits = $query->getResult(); diff --git a/src/backend/PartKeepr/Statistic/StatisticSnapshotManager.php b/src/backend/PartKeepr/Statistic/StatisticSnapshotManager.php @@ -1,13 +1,11 @@ <?php namespace PartKeepr\Statistic; -use PartKeepr\Util\Singleton, - PartKeepr\Part\PartUnit, - PartKeepr\Part\PartManager, - PartKeepr\PartUnit\PartUnitManager, - PartKeepr\PartKeepr, - \PartKeepr\PartBundle\Entity\PartCategoryManager, - PartKeepr\PartUnit\Exceptions\PartUnitNotFoundException; +use PartKeepr\Part\PartManager; +use PartKeepr\PartBundle\Entity\PartCategoryManager; +use PartKeepr\PartBundle\Entity\PartMeasurementUnit; +use PartKeepr\PartKeepr; +use PartKeepr\Util\Singleton; class StatisticSnapshotManager extends Singleton { public function createSnapshot () { @@ -20,7 +18,7 @@ class StatisticSnapshotManager extends Singleton { foreach ($result as $row) { $snapshotUnit = new StatisticSnapshotUnit(); - $snapshotUnit->setPartUnit(PartUnit::loadById($row["puid"])); + $snapshotUnit->setPartUnit(PartMeasurementUnit::loadById($row["puid"])); $snapshotUnit->setStatisticSnapshot($snapshot); if ($row["stockLevel"] !== null) { diff --git a/src/backend/PartKeepr/Statistic/StatisticSnapshotUnit.php b/src/backend/PartKeepr/Statistic/StatisticSnapshotUnit.php @@ -1,10 +1,8 @@ <?php namespace PartKeepr\Statistic; -use PartKeepr\Statistic\StatisticSnapshot, - PartKeepr\Part\PartUnit, - PartKeepr\PartKeepr, - Doctrine\ORM\Mapping as ORM; +use Doctrine\ORM\Mapping as ORM; +use PartKeepr\PartBundle\Entity\PartMeasurementUnit; /** @ORM\Entity **/ @@ -24,7 +22,7 @@ class StatisticSnapshotUnit { private $statisticSnapshot; /** - * @ORM\ManyToOne(targetEntity="PartKeepr\Part\PartUnit") + * @ORM\ManyToOne(targetEntity="PartKeepr\PartBundle\Entity\PartMeasurementUnit") * The statistic snapshot this entity belongs to * @var StatisticSnapshot */ @@ -56,15 +54,17 @@ class StatisticSnapshotUnit { /** * * Sets the part unit for this entity - * @param PartUnit $unit The part unit + * +*@param PartMeasurementUnit $unit The part unit */ - public function setPartUnit (PartUnit $unit) { + public function setPartUnit(PartMeasurementUnit $unit) { $this->partUnit = $unit; } /** * Returns the part unit for this entity - * @return PartUnit The part unit + * +*@return PartMeasurementUnit The part unit */ public function getPartUnit () { return $this->partUnit; diff --git a/src/backend/PartKeepr/Unit/UnitManager.php b/src/backend/PartKeepr/Unit/UnitManager.php @@ -1,99 +0,0 @@ -<?php -namespace PartKeepr\Unit; - -use PartKeepr\Util\Singleton, - PartKeepr\PartKeepr, - PartKeepr\Unit\Exceptions\UnitNotFoundException; - -class UnitManager extends Singleton { - public function getUnits ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { - - $qb = PartKeepr::getEM()->createQueryBuilder(); - $qb->select("u.id, u.name, u.symbol")->from("PartKeepr\Unit\Unit","u"); - - if ($filter != "") { - $qb = $qb->where("LOWER(u.name) LIKE :filter"); - $qb->setParameter("filter", "%".strtolower($filter)."%"); - } - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $qb->orderBy("u.".$sort, $dir); - - $query = $qb->getQuery(); - - $result = $query->getResult(); - - $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); - $totalQueryBuilder->select("COUNT(u.id)")->from("PartKeepr\Unit\Unit","u"); - - - - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("LOWER(u.name) LIKE :filter"); - $totalQueryBuilder->setParameter("filter", "%".strtolower($filter)."%"); - } - - $totalQuery = $totalQueryBuilder->getQuery(); - - foreach ($result as $key => $value) { - $result[$key]["prefixes"] = $this->getSiPrefixes($value["id"]); - } - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - public function getSiPrefixes ($id) { - $unit = UnitManager::getInstance()->getUnit($id); - - $aData = array(); - - foreach ($unit->getPrefixes() as $prefix) { - $aData[] = $prefix->serialize(); - } - - return array("response" => array("totalCount" => count($aData), "data" => $aData)); - } - - public function getUnitByName ($name) { - $dql = "SELECT u FROM PartKeepr\Unit\Unit u WHERE u.name = :name"; - $query = PartKeepr::getEM()->createQuery($dql); - $query->setParameter("name", $name); - - return $query->getSingleResult(); - } - - public function unitExists ($name) { - $dql = "SELECT COUNT(u) FROM PartKeepr\Unit\Unit u WHERE u.name = :name"; - $query = PartKeepr::getEM()->createQuery($dql); - $query->setParameter("name", $name); - - if ($query->getSingleScalarResult() == 0) { - return false; - } else { - return true; - } - } - - public function getUnit ($id) { - $unit = PartKeepr::getEM()->find("PartKeepr\Unit\Unit", $id); - - if ($unit) { - return $unit; - } else { - throw new UnitNotFoundException(); - } - } - - public function deleteUnit ($id) { - $unit = $this->getUnit($id); - - PartKeepr::getEM()->remove($unit); - PartKeepr::getEM()->flush(); - } - - -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/Unit/UnitService.php b/src/backend/PartKeepr/Unit/UnitService.php @@ -1,68 +0,0 @@ -<?php -namespace PartKeepr\Unit; - -use PartKeepr\Service\RestfulService, - PartKeepr\Service\Service, - PartKeepr\PartKeepr, - PartKeepr\Part\PartUnit, - PartKeepr\SiPrefixBundle\Entity\SiPrefix, - PartKeepr\Session\SessionManager; -use PartKeepr\UnitBundle\Entity\Unit; - -class UnitService extends Service implements RestfulService { - public function get () { - if ($this->hasParameter("id")) { - return array("data" => UnitManager::getInstance()->getUnit($this->getParameter("id"))->serialize()); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "name", - "direction" => "ASC"); - } - return UnitManager::getInstance()->getUnits( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $this->getParameter("query", "")); - } - } - - public function create () { - $this->requireParameter("name"); - - $unit = new Unit; - $unit->deserialize($this->getParameters()); - - PartKeepr::getEM()->persist($unit); - PartKeepr::getEM()->flush(); - - return array("data" => $unit->serialize()); - } - - public function update () { - $this->requireParameter("id"); - $this->requireParameter("name"); - - $unit = UnitManager::getInstance()->getUnit($this->getParameter("id")); - $unit->deserialize($this->getParameters()); - - PartKeepr::getEM()->flush(); - - return array("data" => $unit->serialize()); - - } - - public function destroy () { - $this->requireParameter("id"); - - UnitManager::getInstance()->deleteUnit($this->getParameter("id")); - - return array("data" => null); - } - -}- \ No newline at end of file