partkeepr

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

commit 74f2a741ecc4e16fcc60bcbfcac29de96ed38cd1
parent 29dacff1725edb8541fd4b3f727b7302ee418c9c
Author: Felicitus <felicitus@felicitus.org>
Date:   Fri, 19 Jun 2015 17:47:59 +0200

Initial ExtJS hydra implementation. Create/Update/Delete is implemented, relations support is still missing.

Diffstat:
Mapp/config/config.yml | 10+++++++++-
Msrc/PartKeepr/DoctrineReflectionBundle/Resources/views/model.js.twig | 2+-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Editor/Editor.js | 2+-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Editor/EditorComponent.js | 6++++--
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Unit/UnitEditor.js | 4+++-
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraReader.js | 18++++++++++++++++++
Dsrc/PartKeepr/FrontendBundle/Resources/public/js/Data/JsonReader.js | 0
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Data/RestProxy.js | 45+++++++++++++++++++++++++++++++++++++++++----
Msrc/PartKeepr/FrontendBundle/Resources/views/index.html.twig | 1+
9 files changed, 78 insertions(+), 10 deletions(-)

diff --git a/app/config/config.yml b/app/config/config.yml @@ -106,11 +106,19 @@ services: parent: "api.resource" arguments: [ "PartKeepr\UnitBundle\Entity\Unit" ] tags: [ { name: "api.resource" } ] - + calls: + - method: "initFilters" + arguments: [ [ "@resource.unit.order_filter" ] ] + resource.unit.order_filter: + parent: "api.doctrine.orm.order_filter" + arguments: [ ~ ] # This line can also be omitted resource.siprefix: parent: "api.resource" arguments: [ "PartKeepr\SiPrefixBundle\Entity\SiPrefix" ] tags: [ { name: "api.resource" } ] + calls: + - method: "initFilters" + arguments: [ [ "@resource.unit.order_filter" ] ] api.name_converter: class: Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter \ No newline at end of file diff --git a/src/PartKeepr/DoctrineReflectionBundle/Resources/views/model.js.twig b/src/PartKeepr/DoctrineReflectionBundle/Resources/views/model.js.twig @@ -15,7 +15,7 @@ Ext.define('{{ className }}', { {{ association.name }}: { type: '{{ association.target }}', role: '{{ association.name }}', - field: 'id', + field: '@id', right: true } {% if not loop.last %},{% endif %} {% endfor %} diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Editor/Editor.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Editor/Editor.js @@ -93,7 +93,7 @@ Ext.define('PartKeepr.Editor', { }, getRecordId: function () { if (this.record) { - return this.record.get("id"); + return this.record.getId(); } else { return null; } 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,6 +91,7 @@ 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. @@ -113,6 +114,7 @@ Ext.define('PartKeepr.EditorComponent', { this.editorTabPanel.add(editor).show(); }, failure: function(record, operation) { + console.log(record); console.log(operation); } }); @@ -162,8 +164,8 @@ Ext.define('PartKeepr.EditorComponent', { },this); }, deleteRecord: function (r) { - var editor = this.findEditor(r.get("id")); - + var editor = this.findEditor(r.getId()("id")); + if (editor !== null) { this.editorTabPanel.remove(editor); } diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Unit/UnitEditor.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Unit/UnitEditor.js @@ -42,13 +42,15 @@ Ext.define('PartKeepr.UnitEditor', { this.on("itemSave", this.onItemSave, this); }, onStartEdit: function () { + console.log(this.record.prefixes()); var records = this.record.prefixes().getRange(); var toSelect = []; var pfxStore = PartKeepr.getApplication().getSiPrefixStore(); for (var i=0;i<records.length;i++) { - toSelect.push(pfxStore.getAt(pfxStore.find("id", records[i].get("id")))); + console.log(pfxStore.getById(records[i].getId())); + //toSelect.push(pfxStore.getById(records[i].getId())); } this.gridPanel.getSelectionModel().select(toSelect); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraReader.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraReader.js @@ -0,0 +1,17 @@ +Ext.define("PartKeepr.data.HydraReader", { + extend: 'Ext.data.reader.Json', + alias: 'reader.hydra', + + totalProperty: 'hydra:totalItems', + + getResponseData: function (response) { + var data = this.callParent([response]); + + if (data["@type"] == "hydra:PagedCollection") { + this.setRootProperty("hydra:member"); + } else { + this.setRootProperty(""); + } + return data; + } +});+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Data/JsonReader.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Data/JsonReader.js diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Data/RestProxy.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Data/RestProxy.js @@ -3,14 +3,14 @@ Ext.define("PartKeepr.data.RestProxy", { alias: 'proxy.PartKeeprREST', reader: { - type: 'json', - rootProperty: 'data', - totalProperty: '_totalCount' + type: 'hydra', }, writer: { type: 'jsonwithassociations' }, - appendId: true, + appendId: false, + limitParam: "itemsPerPage", + sortParam: "", constructor: function (config) { config.url = PartKeepr.getBasePath() + config.url; @@ -52,4 +52,41 @@ Ext.define("PartKeepr.data.RestProxy", { } } }, + 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(); + } + + 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/views/index.html.twig b/src/PartKeepr/FrontendBundle/Resources/views/index.html.twig @@ -53,6 +53,7 @@ '@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/HydraReader.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Statusbar.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Auth/LoginDialog.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Part/PartImageDisplay.js'