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 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