From ffae2a37db0a28159e28525a1f9108e95f388f5e Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 23 Sep 2016 12:07:40 +0500 Subject: Implement attributes aliases --- web/app/view/StateController.js | 71 ++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 11 deletions(-) (limited to 'web/app/view/StateController.js') diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js index d92201b9..4bd43de6 100644 --- a/web/app/view/StateController.js +++ b/web/app/view/StateController.js @@ -28,8 +28,9 @@ Ext.define('Traccar.view.StateController', { listen: { controller: { '*': { - selectDevice: 'selectDevice', - selectReport: 'selectReport' + selectdevice: 'selectDevice', + selectreport: 'selectReport', + updatealiases: 'updateAliases' } }, store: { @@ -39,6 +40,10 @@ Ext.define('Traccar.view.StateController', { }, '#Positions': { clear: 'clearReport' + }, + '#AllAttributesAliases': { + add: 'updateAliases', + update: 'updateAliases' } } } @@ -66,7 +71,8 @@ Ext.define('Traccar.view.StateController', { } for (i = 0; i < data.length; i++) { if (this.deviceId === data[i].get('deviceId')) { - this.updatePosition(data[i]); + this.position = data[i]; + this.updatePosition(); } } }, @@ -79,30 +85,41 @@ Ext.define('Traccar.view.StateController', { } }, - updatePosition: function (position) { - var attributes, store, key; + updatePosition: function () { + var attributes, store, key, aliasesStore, attributeAlias, alias; store = Ext.getStore('Attributes'); store.removeAll(); - for (key in position.data) { - if (position.data.hasOwnProperty(key) && this.keys[key] !== undefined) { + for (key in this.position.data) { + if (this.position.data.hasOwnProperty(key) && this.keys[key] !== undefined) { store.add(Ext.create('Traccar.model.Attribute', { priority: this.keys[key].priority, name: this.keys[key].name, - value: Traccar.AttributeFormatter.getFormatter(key)(position.get(key)) + value: Traccar.AttributeFormatter.getFormatter(key)(this.position.get(key)) })); } } - attributes = position.get('attributes'); + aliasesStore = Ext.getStore('AllAttributesAliases'); + aliasesStore.filter('deviceId', this.position.get('deviceId')); + + attributes = this.position.get('attributes'); if (attributes instanceof Object) { for (key in attributes) { if (attributes.hasOwnProperty(key)) { + attributeAlias = aliasesStore.findRecord('attribute', key, 0, false, true, true); + if (attributeAlias !== null) { + alias = attributeAlias.get('alias'); + } else { + alias = ''; + } store.add(Ext.create('Traccar.model.Attribute', { priority: 1024, name: key.replace(/^./, function (match) { return match.toUpperCase(); }), + attribute: key, + alias: alias, value: Traccar.AttributeFormatter.getFormatter(key)(attributes[key]) })); } @@ -115,18 +132,50 @@ Ext.define('Traccar.view.StateController', { this.deviceId = device.get('id'); position = Ext.getStore('LatestPositions').findRecord('deviceId', this.deviceId, 0, false, false, true); if (position) { - this.updatePosition(position); + this.position = position; + this.updatePosition(); } else { + this.position = null; Ext.getStore('Attributes').removeAll(); } }, selectReport: function (position) { this.deviceId = null; - this.updatePosition(position); + this.position = position; + this.updatePosition(); }, clearReport: function (store) { + this.position = null; Ext.getStore('Attributes').removeAll(); + }, + + onSelectionChange: function (selected, records) { + var enabled = selected.getCount() > 0 && records[0].get('attribute') !== ''; + this.lookupReference('aliasEditButton').setDisabled(!enabled); + }, + + onAliasEditClick: function () { + var attribute, aliasesStore, attributeAlias, dialog; + attribute = this.getView().getSelectionModel().getSelection()[0]; + aliasesStore = Ext.getStore('AllAttributesAliases'); + attributeAlias = aliasesStore.findRecord('attribute', attribute.get('attribute'), 0, false, true, true); + if (attributeAlias === null) { + attributeAlias = Ext.create('Traccar.model.AttributeAlias', { + deviceId: this.position.get('deviceId'), + attribute: attribute.get('attribute') + }); + attributeAlias.store = aliasesStore; + } + dialog = Ext.create('Traccar.view.AttributeAliasDialog'); + dialog.down('form').loadRecord(attributeAlias); + dialog.show(); + }, + + updateAliases: function () { + if (this.position !== null) { + this.updatePosition(); + } } }); -- cgit v1.2.3 From d3ecb6ae2d178b50adb2310053a5aa2a6659e74f Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 23 Sep 2016 12:28:03 +0500 Subject: Fixed import --- web/app/view/StateController.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'web/app/view/StateController.js') diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js index 4bd43de6..c070ca2b 100644 --- a/web/app/view/StateController.js +++ b/web/app/view/StateController.js @@ -21,7 +21,10 @@ Ext.define('Traccar.view.StateController', { requires: [ 'Traccar.AttributeFormatter', - 'Traccar.model.Attribute' + 'Traccar.model.Attribute', + 'Traccar.model.AttributeAlias', + 'Traccar.view.AttributeAliasDialog' + ], config: { -- cgit v1.2.3 From 5ed0dc673f073078542aee35c21ac6e041545423 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 23 Sep 2016 12:36:46 +0500 Subject: Remove trailing whitespaces --- web/app/view/StateController.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'web/app/view/StateController.js') diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js index c070ca2b..b7df1e2e 100644 --- a/web/app/view/StateController.js +++ b/web/app/view/StateController.js @@ -21,10 +21,10 @@ Ext.define('Traccar.view.StateController', { requires: [ 'Traccar.AttributeFormatter', - 'Traccar.model.Attribute', + 'Traccar.model.Attribute', 'Traccar.model.AttributeAlias', 'Traccar.view.AttributeAliasDialog' - + ], config: { -- cgit v1.2.3 From 6a1a261466fae6a6718cd3c0cb43b6061ec86fba Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 26 Sep 2016 12:47:53 +0500 Subject: - Renamed stores - Removed 'alias' field from attribute model - Some optimizations - Fixed alarm colorizing --- web/app/Application.js | 4 ++-- web/app/controller/Root.js | 2 +- web/app/model/Attribute.js | 3 --- web/app/store/AllAttributeAliases.js | 30 +++++++++++++++++++++++++ web/app/store/AllAttributesAliases.js | 30 ------------------------- web/app/store/AttributeAliases.js | 30 +++++++++++++++++++++++++ web/app/store/AttributesAliases.js | 30 ------------------------- web/app/view/AttributesAliases.js | 5 ++--- web/app/view/AttributesAliasesController.js | 6 ----- web/app/view/State.js | 8 ++----- web/app/view/StateController.js | 34 +++++++++++++++++++---------- 11 files changed, 90 insertions(+), 92 deletions(-) create mode 100644 web/app/store/AllAttributeAliases.js delete mode 100644 web/app/store/AllAttributesAliases.js create mode 100644 web/app/store/AttributeAliases.js delete mode 100644 web/app/store/AttributesAliases.js (limited to 'web/app/view/StateController.js') diff --git a/web/app/Application.js b/web/app/Application.js index 73b9e838..8262e2e6 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -61,8 +61,8 @@ Ext.define('Traccar.Application', { 'Notifications', 'AllNotifications', 'GeofenceTypes', - 'AttributesAliases', - 'AllAttributesAliases', + 'AttributeAliases', + 'AllAttributeAliases', 'ReportRoute', 'ReportEvents', 'ReportTrips', diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index 5e3c39da..0784aeaf 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -78,13 +78,13 @@ Ext.define('Traccar.controller.Root', { var attribution; Ext.getStore('Groups').load(); Ext.getStore('Geofences').load(); + Ext.getStore('AllAttributeAliases').load(); Ext.getStore('Devices').load({ scope: this, callback: function () { this.asyncUpdate(true); } }); - Ext.getStore('AllAttributesAliases').load(); attribution = Ext.get('attribution'); if (attribution) { attribution.remove(); diff --git a/web/app/model/Attribute.js b/web/app/model/Attribute.js index 7bf5beb5..b82fecfb 100644 --- a/web/app/model/Attribute.js +++ b/web/app/model/Attribute.js @@ -30,8 +30,5 @@ Ext.define('Traccar.model.Attribute', { }, { name: 'attribute', type: 'string' - }, { - name: 'alias', - type: 'string' }] }); diff --git a/web/app/store/AllAttributeAliases.js b/web/app/store/AllAttributeAliases.js new file mode 100644 index 00000000..c351d0d7 --- /dev/null +++ b/web/app/store/AllAttributeAliases.js @@ -0,0 +1,30 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +Ext.define('Traccar.store.AllAttributeAliases', { + extend: 'Ext.data.Store', + model: 'Traccar.model.AttributeAlias', + + proxy: { + type: 'rest', + url: 'api/attributes/aliases', + writer: { + writeAllFields: true + } + } +}); diff --git a/web/app/store/AllAttributesAliases.js b/web/app/store/AllAttributesAliases.js deleted file mode 100644 index 7eb6c0c1..00000000 --- a/web/app/store/AllAttributesAliases.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) - * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -Ext.define('Traccar.store.AllAttributesAliases', { - extend: 'Ext.data.Store', - model: 'Traccar.model.AttributeAlias', - - proxy: { - type: 'rest', - url: 'api/devices/aliases', - writer: { - writeAllFields: true - } - } -}); diff --git a/web/app/store/AttributeAliases.js b/web/app/store/AttributeAliases.js new file mode 100644 index 00000000..ebec8c87 --- /dev/null +++ b/web/app/store/AttributeAliases.js @@ -0,0 +1,30 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +Ext.define('Traccar.store.AttributeAliases', { + extend: 'Ext.data.Store', + model: 'Traccar.model.AttributeAlias', + + proxy: { + type: 'rest', + url: 'api/attributes/aliases', + writer: { + writeAllFields: true + } + } +}); diff --git a/web/app/store/AttributesAliases.js b/web/app/store/AttributesAliases.js deleted file mode 100644 index 1f8d11de..00000000 --- a/web/app/store/AttributesAliases.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) - * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -Ext.define('Traccar.store.AttributesAliases', { - extend: 'Ext.data.Store', - model: 'Traccar.model.AttributeAlias', - - proxy: { - type: 'rest', - url: 'api/devices/aliases', - writer: { - writeAllFields: true - } - } -}); diff --git a/web/app/view/AttributesAliases.js b/web/app/view/AttributesAliases.js index b1390e45..717991dd 100644 --- a/web/app/view/AttributesAliases.js +++ b/web/app/view/AttributesAliases.js @@ -26,7 +26,7 @@ Ext.define('Traccar.view.AttributesAliases', { ], controller: 'attributesAliases', - store: 'AttributesAliases', + store: 'AttributeAliases', selType: 'rowmodel', @@ -46,8 +46,7 @@ Ext.define('Traccar.view.AttributesAliases', { }, listeners: { - selectionchange: 'onSelectionChange', - destroy: 'onClose' + selectionchange: 'onSelectionChange' }, columns: [{ diff --git a/web/app/view/AttributesAliasesController.js b/web/app/view/AttributesAliasesController.js index e848c489..cda3e338 100644 --- a/web/app/view/AttributesAliasesController.js +++ b/web/app/view/AttributesAliasesController.js @@ -90,11 +90,5 @@ Ext.define('Traccar.view.AttributesAliasesController', { } else { this.getView().getStore().loadData([], false); } - }, - - onClose: function () { - Ext.getStore('AllAttributesAliases').load(); - this.fireEvent('updatealiases'); } - }); diff --git a/web/app/view/State.js b/web/app/view/State.js index ddb9c0ea..7e9e235c 100644 --- a/web/app/view/State.js +++ b/web/app/view/State.js @@ -49,17 +49,13 @@ Ext.define('Traccar.view.State', { columns: [{ text: Strings.stateName, dataIndex: 'name', - flex: 1, - renderer: function (value, metaData, record) { - var alias = record.get('alias'); - return alias !== '' ? alias : value; - } + flex: 1 }, { text: Strings.stateValue, dataIndex: 'value', flex: 1, renderer: function (value, metaData, record) { - if (record.get('name') === 'Alarm') { + if (record.get('attribute') === 'alarm') { metaData.tdCls = 'view-color-red'; } return value; diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js index b7df1e2e..7462fcc8 100644 --- a/web/app/view/StateController.js +++ b/web/app/view/StateController.js @@ -44,9 +44,13 @@ Ext.define('Traccar.view.StateController', { '#Positions': { clear: 'clearReport' }, - '#AllAttributesAliases': { + '#AllAttributeAliases': { add: 'updateAliases', update: 'updateAliases' + }, + '#AttributeAliases': { + add: 'updateAliasesRemote', + update: 'updateAliasesRemote' } } } @@ -89,7 +93,7 @@ Ext.define('Traccar.view.StateController', { }, updatePosition: function () { - var attributes, store, key, aliasesStore, attributeAlias, alias; + var attributes, store, key, aliasesStore, attributeAlias, name; store = Ext.getStore('Attributes'); store.removeAll(); @@ -103,7 +107,7 @@ Ext.define('Traccar.view.StateController', { } } - aliasesStore = Ext.getStore('AllAttributesAliases'); + aliasesStore = Ext.getStore('AllAttributeAliases'); aliasesStore.filter('deviceId', this.position.get('deviceId')); attributes = this.position.get('attributes'); @@ -112,17 +116,16 @@ Ext.define('Traccar.view.StateController', { if (attributes.hasOwnProperty(key)) { attributeAlias = aliasesStore.findRecord('attribute', key, 0, false, true, true); if (attributeAlias !== null) { - alias = attributeAlias.get('alias'); + name = attributeAlias.get('alias'); } else { - alias = ''; + name = key.replace(/^./, function (match) { + return match.toUpperCase(); + }); } store.add(Ext.create('Traccar.model.Attribute', { priority: 1024, - name: key.replace(/^./, function (match) { - return match.toUpperCase(); - }), + name: name, attribute: key, - alias: alias, value: Traccar.AttributeFormatter.getFormatter(key)(attributes[key]) })); } @@ -155,14 +158,14 @@ Ext.define('Traccar.view.StateController', { }, onSelectionChange: function (selected, records) { - var enabled = selected.getCount() > 0 && records[0].get('attribute') !== ''; + var enabled = selected.getCount() > 0 && records[0].get('priority') === 1024; this.lookupReference('aliasEditButton').setDisabled(!enabled); }, onAliasEditClick: function () { var attribute, aliasesStore, attributeAlias, dialog; attribute = this.getView().getSelectionModel().getSelection()[0]; - aliasesStore = Ext.getStore('AllAttributesAliases'); + aliasesStore = Ext.getStore('AllAttributeAliases'); attributeAlias = aliasesStore.findRecord('attribute', attribute.get('attribute'), 0, false, true, true); if (attributeAlias === null) { attributeAlias = Ext.create('Traccar.model.AttributeAlias', { @@ -180,5 +183,14 @@ Ext.define('Traccar.view.StateController', { if (this.position !== null) { this.updatePosition(); } + }, + + updateAliasesRemote: function () { + Ext.getStore('AllAttributeAliases').load({ + scope: this, + callback: function () { + this.updateAliases(); + } + }); } }); -- cgit v1.2.3 From ac4f0adf3b196b1a9af40be64b3e4e0fac91c1d6 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 27 Sep 2016 09:52:42 +0500 Subject: Remove second store --- web/app/Application.js | 1 - web/app/store/AttributeAliases.js | 30 ----------------------------- web/app/view/AttributesAliases.js | 2 +- web/app/view/AttributesAliasesController.js | 12 ++++++++---- web/app/view/StateController.js | 13 ------------- 5 files changed, 9 insertions(+), 49 deletions(-) delete mode 100644 web/app/store/AttributeAliases.js (limited to 'web/app/view/StateController.js') diff --git a/web/app/Application.js b/web/app/Application.js index 8262e2e6..0d6430d9 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -61,7 +61,6 @@ Ext.define('Traccar.Application', { 'Notifications', 'AllNotifications', 'GeofenceTypes', - 'AttributeAliases', 'AllAttributeAliases', 'ReportRoute', 'ReportEvents', diff --git a/web/app/store/AttributeAliases.js b/web/app/store/AttributeAliases.js deleted file mode 100644 index ebec8c87..00000000 --- a/web/app/store/AttributeAliases.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) - * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -Ext.define('Traccar.store.AttributeAliases', { - extend: 'Ext.data.Store', - model: 'Traccar.model.AttributeAlias', - - proxy: { - type: 'rest', - url: 'api/attributes/aliases', - writer: { - writeAllFields: true - } - } -}); diff --git a/web/app/view/AttributesAliases.js b/web/app/view/AttributesAliases.js index 717991dd..8fcf10bb 100644 --- a/web/app/view/AttributesAliases.js +++ b/web/app/view/AttributesAliases.js @@ -26,7 +26,7 @@ Ext.define('Traccar.view.AttributesAliases', { ], controller: 'attributesAliases', - store: 'AttributeAliases', + store: 'AllAttributeAliases', selType: 'rowmodel', diff --git a/web/app/view/AttributesAliasesController.js b/web/app/view/AttributesAliasesController.js index cda3e338..8f406c42 100644 --- a/web/app/view/AttributesAliasesController.js +++ b/web/app/view/AttributesAliasesController.js @@ -31,7 +31,7 @@ Ext.define('Traccar.view.AttributesAliasesController', { this.lookupReference('toolbarAddButton').setDisabled(true); this.lookupReference('toolbarEditButton').setDisabled(true); this.lookupReference('toolbarRemoveButton').setDisabled(true); - this.getView().getStore().loadData([], false); + this.getView().getStore().filter('deviceId', 0); }, onAddClick: function () { @@ -83,12 +83,16 @@ Ext.define('Traccar.view.AttributesAliasesController', { }, onDeviceChange: function (combobox, newValue, oldValue) { + var admin = Traccar.app.getUser().get('admin'); this.onSelectionChange(''); if (newValue !== null) { - this.getView().getStore().getProxy().setExtraParam('deviceId', newValue); - this.getView().getStore().load(); + this.getView().getStore().filter('deviceId', newValue); + if (admin && this.getView().getStore().getCount() === 0) { + this.getView().getStore().getProxy().setExtraParam('deviceId', newValue); + this.getView().getStore().load(); + } } else { - this.getView().getStore().loadData([], false); + this.getView().getStore().filter('deviceId', 0); } } }); diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js index 7462fcc8..c0f5b9a1 100644 --- a/web/app/view/StateController.js +++ b/web/app/view/StateController.js @@ -47,10 +47,6 @@ Ext.define('Traccar.view.StateController', { '#AllAttributeAliases': { add: 'updateAliases', update: 'updateAliases' - }, - '#AttributeAliases': { - add: 'updateAliasesRemote', - update: 'updateAliasesRemote' } } } @@ -183,14 +179,5 @@ Ext.define('Traccar.view.StateController', { if (this.position !== null) { this.updatePosition(); } - }, - - updateAliasesRemote: function () { - Ext.getStore('AllAttributeAliases').load({ - scope: this, - callback: function () { - this.updateAliases(); - } - }); } }); -- cgit v1.2.3 From b1715a760cde09ec69a6756d7067a8c077d0fe2b Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 27 Sep 2016 15:27:09 +0500 Subject: -Remove plural of attribute -Use ChainedStore in right way -Use findBy instead of filter in StateController --- web/app/Application.js | 2 +- web/app/controller/Root.js | 2 +- web/app/store/AllAttributeAliases.js | 30 -------- web/app/store/AttributeAliases.js | 30 ++++++++ web/app/view/AttributeAliases.js | 60 ++++++++++++++++ web/app/view/AttributeAliasesController.js | 105 ++++++++++++++++++++++++++++ web/app/view/AttributesAliases.js | 61 ---------------- web/app/view/AttributesAliasesController.js | 98 -------------------------- web/app/view/SettingsMenu.js | 6 +- web/app/view/SettingsMenuController.js | 10 +-- web/app/view/StateController.js | 34 +++++---- web/l10n/en.json | 2 +- 12 files changed, 227 insertions(+), 213 deletions(-) delete mode 100644 web/app/store/AllAttributeAliases.js create mode 100644 web/app/store/AttributeAliases.js create mode 100644 web/app/view/AttributeAliases.js create mode 100644 web/app/view/AttributeAliasesController.js delete mode 100644 web/app/view/AttributesAliases.js delete mode 100644 web/app/view/AttributesAliasesController.js (limited to 'web/app/view/StateController.js') diff --git a/web/app/Application.js b/web/app/Application.js index 0d6430d9..aab9bc8a 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -61,7 +61,7 @@ Ext.define('Traccar.Application', { 'Notifications', 'AllNotifications', 'GeofenceTypes', - 'AllAttributeAliases', + 'AttributeAliases', 'ReportRoute', 'ReportEvents', 'ReportTrips', diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index 0784aeaf..2807cab9 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -78,7 +78,7 @@ Ext.define('Traccar.controller.Root', { var attribution; Ext.getStore('Groups').load(); Ext.getStore('Geofences').load(); - Ext.getStore('AllAttributeAliases').load(); + Ext.getStore('AttributeAliases').load(); Ext.getStore('Devices').load({ scope: this, callback: function () { diff --git a/web/app/store/AllAttributeAliases.js b/web/app/store/AllAttributeAliases.js deleted file mode 100644 index c351d0d7..00000000 --- a/web/app/store/AllAttributeAliases.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) - * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -Ext.define('Traccar.store.AllAttributeAliases', { - extend: 'Ext.data.Store', - model: 'Traccar.model.AttributeAlias', - - proxy: { - type: 'rest', - url: 'api/attributes/aliases', - writer: { - writeAllFields: true - } - } -}); diff --git a/web/app/store/AttributeAliases.js b/web/app/store/AttributeAliases.js new file mode 100644 index 00000000..ebec8c87 --- /dev/null +++ b/web/app/store/AttributeAliases.js @@ -0,0 +1,30 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +Ext.define('Traccar.store.AttributeAliases', { + extend: 'Ext.data.Store', + model: 'Traccar.model.AttributeAlias', + + proxy: { + type: 'rest', + url: 'api/attributes/aliases', + writer: { + writeAllFields: true + } + } +}); diff --git a/web/app/view/AttributeAliases.js b/web/app/view/AttributeAliases.js new file mode 100644 index 00000000..182a9cdd --- /dev/null +++ b/web/app/view/AttributeAliases.js @@ -0,0 +1,60 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +Ext.define('Traccar.view.AttributeAliases', { + extend: 'Ext.grid.Panel', + xtype: 'attributeAliasesView', + + requires: [ + 'Traccar.view.AttributeAliasesController', + 'Traccar.view.EditToolbar' + ], + + controller: 'attributeAliases', + + selType: 'rowmodel', + + tbar: { + xtype: 'editToolbar', + items: ['-', { + xtype: 'combobox', + reference: 'deviceField', + store: 'Devices', + displayField: 'name', + valueField: 'id', + typeAhead: true, + listeners: { + change: 'onDeviceChange' + } + }] + }, + + listeners: { + selectionchange: 'onSelectionChange' + }, + + columns: [{ + text: Strings.sharedAttribute, + dataIndex: 'attribute', + flex: 1 + }, { + text: Strings.sharedAlias, + dataIndex: 'alias', + flex: 1 + }] +}); diff --git a/web/app/view/AttributeAliasesController.js b/web/app/view/AttributeAliasesController.js new file mode 100644 index 00000000..6135994e --- /dev/null +++ b/web/app/view/AttributeAliasesController.js @@ -0,0 +1,105 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +Ext.define('Traccar.view.AttributeAliasesController', { + extend: 'Ext.app.ViewController', + alias: 'controller.attributeAliases', + + requires: [ + 'Traccar.view.AttributeAliasDialog', + 'Traccar.model.AttributeAlias' + ], + + init: function () { + var admin = Traccar.app.getUser().get('admin'); + this.lookupReference('deviceField').setStore(admin ? 'AllDevices' : 'Devices'); + this.lookupReference('toolbarAddButton').setDisabled(true); + this.lookupReference('toolbarEditButton').setDisabled(true); + this.lookupReference('toolbarRemoveButton').setDisabled(true); + this.getView().setStore(Ext.create('Ext.data.ChainedStore', { + storeId: 'EditorAttributeAliases', + source: 'AttributeAliases' + })); + this.getView().getStore().filter('deviceId', 0); + }, + + onAddClick: function () { + var attributeAlias, dialog, deviceId; + attributeAlias = Ext.create('Traccar.model.AttributeAlias'); + attributeAlias.store = Ext.getStore('AttributeAliases'); + deviceId = this.lookupReference('deviceField').getValue(); + attributeAlias.set('deviceId', deviceId); + dialog = Ext.create('Traccar.view.AttributeAliasDialog'); + dialog.down('form').loadRecord(attributeAlias); + dialog.show(); + }, + + onEditClick: function () { + var attributeAlias, dialog; + attributeAlias = this.getView().getSelectionModel().getSelection()[0]; + attributeAlias.store = Ext.getStore('AttributeAliases'); + dialog = Ext.create('Traccar.view.AttributeAliasDialog'); + dialog.down('form').loadRecord(attributeAlias); + dialog.show(); + }, + + onRemoveClick: function () { + var attributeAlias = this.getView().getSelectionModel().getSelection()[0]; + Ext.Msg.show({ + title: Strings.sharedAttributeAlias, + message: Strings.sharedRemoveConfirm, + buttons: Ext.Msg.YESNO, + buttonText: { + yes: Strings.sharedRemove, + no: Strings.sharedCancel + }, + scope: this, + fn: function (btn) { + var store = Ext.getStore('AttributeAliases'); + if (btn === 'yes') { + store.remove(attributeAlias); + store.sync(); + } + } + }); + }, + + onSelectionChange: function (selected) { + var disabled = !this.lookupReference('deviceField').getValue(); + this.lookupReference('toolbarAddButton').setDisabled(disabled); + disabled = selected.length === 0 || !this.lookupReference('deviceField').getValue(); + this.lookupReference('toolbarEditButton').setDisabled(disabled); + this.lookupReference('toolbarRemoveButton').setDisabled(disabled); + }, + + onDeviceChange: function (combobox, newValue, oldValue) { + var admin = Traccar.app.getUser().get('admin'); + this.onSelectionChange(''); + if (newValue !== null) { + this.getView().getStore().filter('deviceId', newValue); + if (admin && this.getView().getStore().getCount() === 0) { + Ext.getStore('AttributeAliases').getProxy().setExtraParam('deviceId', newValue); + Ext.getStore('AttributeAliases').load({ + addRecords: true + }); + } + } else { + this.getView().getStore().filter('deviceId', 0); + } + } +}); diff --git a/web/app/view/AttributesAliases.js b/web/app/view/AttributesAliases.js deleted file mode 100644 index 8fcf10bb..00000000 --- a/web/app/view/AttributesAliases.js +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) - * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -Ext.define('Traccar.view.AttributesAliases', { - extend: 'Ext.grid.Panel', - xtype: 'attributesAliasesView', - - requires: [ - 'Traccar.view.AttributesAliasesController', - 'Traccar.view.EditToolbar' - ], - - controller: 'attributesAliases', - store: 'AllAttributeAliases', - - selType: 'rowmodel', - - tbar: { - xtype: 'editToolbar', - items: ['-', { - xtype: 'combobox', - reference: 'deviceField', - store: 'Devices', - displayField: 'name', - valueField: 'id', - typeAhead: true, - listeners: { - change: 'onDeviceChange' - } - }] - }, - - listeners: { - selectionchange: 'onSelectionChange' - }, - - columns: [{ - text: Strings.sharedAttribute, - dataIndex: 'attribute', - flex: 1 - }, { - text: Strings.sharedAlias, - dataIndex: 'alias', - flex: 1 - }] -}); diff --git a/web/app/view/AttributesAliasesController.js b/web/app/view/AttributesAliasesController.js deleted file mode 100644 index 8f406c42..00000000 --- a/web/app/view/AttributesAliasesController.js +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) - * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -Ext.define('Traccar.view.AttributesAliasesController', { - extend: 'Ext.app.ViewController', - alias: 'controller.attributesAliases', - - requires: [ - 'Traccar.view.AttributeAliasDialog', - 'Traccar.model.AttributeAlias' - ], - - init: function () { - var admin = Traccar.app.getUser().get('admin'); - this.lookupReference('deviceField').setStore(admin ? 'AllDevices' : 'Devices'); - this.lookupReference('toolbarAddButton').setDisabled(true); - this.lookupReference('toolbarEditButton').setDisabled(true); - this.lookupReference('toolbarRemoveButton').setDisabled(true); - this.getView().getStore().filter('deviceId', 0); - }, - - onAddClick: function () { - var attributeAlias, dialog, deviceId; - attributeAlias = Ext.create('Traccar.model.AttributeAlias'); - attributeAlias.store = this.getView().getStore(); - deviceId = this.lookupReference('deviceField').getValue(); - attributeAlias.set('deviceId', deviceId); - dialog = Ext.create('Traccar.view.AttributeAliasDialog'); - dialog.down('form').loadRecord(attributeAlias); - dialog.show(); - }, - - onEditClick: function () { - var attributeAlias, dialog; - attributeAlias = this.getView().getSelectionModel().getSelection()[0]; - dialog = Ext.create('Traccar.view.AttributeAliasDialog'); - dialog.down('form').loadRecord(attributeAlias); - dialog.show(); - }, - - onRemoveClick: function () { - var attributeAlias = this.getView().getSelectionModel().getSelection()[0]; - Ext.Msg.show({ - title: Strings.sharedAttributeAlias, - message: Strings.sharedRemoveConfirm, - buttons: Ext.Msg.YESNO, - buttonText: { - yes: Strings.sharedRemove, - no: Strings.sharedCancel - }, - scope: this, - fn: function (btn) { - var store = this.getView().getStore(); - if (btn === 'yes') { - store.remove(attributeAlias); - store.sync(); - } - } - }); - }, - - onSelectionChange: function (selected) { - var disabled = !this.lookupReference('deviceField').getValue(); - this.lookupReference('toolbarAddButton').setDisabled(disabled); - disabled = selected.length === 0 || !this.lookupReference('deviceField').getValue(); - this.lookupReference('toolbarEditButton').setDisabled(disabled); - this.lookupReference('toolbarRemoveButton').setDisabled(disabled); - }, - - onDeviceChange: function (combobox, newValue, oldValue) { - var admin = Traccar.app.getUser().get('admin'); - this.onSelectionChange(''); - if (newValue !== null) { - this.getView().getStore().filter('deviceId', newValue); - if (admin && this.getView().getStore().getCount() === 0) { - this.getView().getStore().getProxy().setExtraParam('deviceId', newValue); - this.getView().getStore().load(); - } - } else { - this.getView().getStore().filter('deviceId', 0); - } - } -}); diff --git a/web/app/view/SettingsMenu.js b/web/app/view/SettingsMenu.js index 691bf65b..391db56f 100644 --- a/web/app/view/SettingsMenu.js +++ b/web/app/view/SettingsMenu.js @@ -59,9 +59,9 @@ Ext.define('Traccar.view.SettingsMenu', { reference: 'settingsNotificationsButton' }, { hidden: true, - text: Strings.sharedAttributesAliases, - handler: 'onAttributesAliasesClick', - reference: 'settingsAttributesAliasesButton' + text: Strings.sharedAttributeAliases, + handler: 'onAttributeAliasesClick', + reference: 'settingsAttributeAliasesButton' }, { text: Strings.loginLogout, handler: 'onLogoutClick' diff --git a/web/app/view/SettingsMenuController.js b/web/app/view/SettingsMenuController.js index b01e4f81..ceef8aba 100644 --- a/web/app/view/SettingsMenuController.js +++ b/web/app/view/SettingsMenuController.js @@ -27,7 +27,7 @@ Ext.define('Traccar.view.SettingsMenuController', { 'Traccar.view.Groups', 'Traccar.view.Geofences', 'Traccar.view.Notifications', - 'Traccar.view.AttributesAliases', + 'Traccar.view.AttributeAliases', 'Traccar.view.BaseWindow' ], @@ -43,7 +43,7 @@ Ext.define('Traccar.view.SettingsMenuController', { this.lookupReference('settingsGroupsButton').setHidden(false); this.lookupReference('settingsGeofencesButton').setHidden(false); this.lookupReference('settingsNotificationsButton').setHidden(false); - this.lookupReference('settingsAttributesAliasesButton').setHidden(false); + this.lookupReference('settingsAttributeAliasesButton').setHidden(false); } }, @@ -101,12 +101,12 @@ Ext.define('Traccar.view.SettingsMenuController', { }).show(); }, - onAttributesAliasesClick: function () { + onAttributeAliasesClick: function () { Ext.create('Traccar.view.BaseWindow', { - title: Strings.sharedAttributesAliases, + title: Strings.sharedAttributeAliases, modal: false, items: { - xtype: 'attributesAliasesView' + xtype: 'attributeAliasesView' } }).show(); }, diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js index c0f5b9a1..8a194940 100644 --- a/web/app/view/StateController.js +++ b/web/app/view/StateController.js @@ -44,7 +44,7 @@ Ext.define('Traccar.view.StateController', { '#Positions': { clear: 'clearReport' }, - '#AllAttributeAliases': { + '#AttributeAliases': { add: 'updateAliases', update: 'updateAliases' } @@ -52,6 +52,10 @@ Ext.define('Traccar.view.StateController', { } }, + init: function () { + this.aliasesStore = Ext.getStore('AttributeAliases'); + }, + keys: (function () { var i, list, result; result = {}; @@ -88,8 +92,12 @@ Ext.define('Traccar.view.StateController', { } }, + findAttribute: function (record) { + return record.get('deviceId') === this.position.get('deviceId') && record.get('attribute') === this.lookupAttribute; + }, + updatePosition: function () { - var attributes, store, key, aliasesStore, attributeAlias, name; + var attributes, store, key, aliasIndex, name; store = Ext.getStore('Attributes'); store.removeAll(); @@ -103,16 +111,14 @@ Ext.define('Traccar.view.StateController', { } } - aliasesStore = Ext.getStore('AllAttributeAliases'); - aliasesStore.filter('deviceId', this.position.get('deviceId')); - attributes = this.position.get('attributes'); if (attributes instanceof Object) { for (key in attributes) { if (attributes.hasOwnProperty(key)) { - attributeAlias = aliasesStore.findRecord('attribute', key, 0, false, true, true); - if (attributeAlias !== null) { - name = attributeAlias.get('alias'); + this.lookupAttribute = key; + aliasIndex = this.aliasesStore.findBy(this.findAttribute, this); + if (aliasIndex !== -1) { + name = this.aliasesStore.getAt(aliasIndex).get('alias'); } else { name = key.replace(/^./, function (match) { return match.toUpperCase(); @@ -159,16 +165,18 @@ Ext.define('Traccar.view.StateController', { }, onAliasEditClick: function () { - var attribute, aliasesStore, attributeAlias, dialog; + var attribute, aliasIndex, attributeAlias, dialog; attribute = this.getView().getSelectionModel().getSelection()[0]; - aliasesStore = Ext.getStore('AllAttributeAliases'); - attributeAlias = aliasesStore.findRecord('attribute', attribute.get('attribute'), 0, false, true, true); - if (attributeAlias === null) { + this.lookupAttribute = attribute.get('attribute'); + aliasIndex = this.aliasesStore.findBy(this.findAttribute, this); + if (aliasIndex !== -1) { + attributeAlias = this.aliasesStore.getAt(aliasIndex); + } else { attributeAlias = Ext.create('Traccar.model.AttributeAlias', { deviceId: this.position.get('deviceId'), attribute: attribute.get('attribute') }); - attributeAlias.store = aliasesStore; + attributeAlias.store = this.aliasesStore; } dialog = Ext.create('Traccar.view.AttributeAliasDialog'); dialog.down('form').loadRecord(attributeAlias); diff --git a/web/l10n/en.json b/web/l10n/en.json index 1bf53b39..11b2e835 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -30,7 +30,7 @@ "sharedMinuteAbbreviation": "m", "sharedGetMapState": "Get Map State", "sharedAttributeAlias": "Attribute Alias", - "sharedAttributesAliases": "Attributes Aliases", + "sharedAttributeAliases": "Attribute Aliases", "sharedAlias": "Alias", "errorTitle": "Error", "errorUnknown": "Unknown error", -- cgit v1.2.3