diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-05-19 16:56:08 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-19 16:56:08 +1200 |
commit | f5d4d3bf8a4d12f4739407f8f25bba3c572df649 (patch) | |
tree | 71c3807a69c69b9e8659d873ee4400cd835b699c /web/app/view | |
parent | 31187bc2a3ae41ab553a6472b7592895e3641fe8 (diff) | |
parent | 8caf621e9adbeb99093076335679813a8a6e8ffe (diff) | |
download | trackermap-web-f5d4d3bf8a4d12f4739407f8f25bba3c572df649.tar.gz trackermap-web-f5d4d3bf8a4d12f4739407f8f25bba3c572df649.tar.bz2 trackermap-web-f5d4d3bf8a4d12f4739407f8f25bba3c572df649.zip |
Merge pull request #490 from Abyss777/position_attributes
Implement known position attributes
Diffstat (limited to 'web/app/view')
-rw-r--r-- | web/app/view/CustomNumberField.js | 4 | ||||
-rw-r--r-- | web/app/view/StateController.js | 6 | ||||
-rw-r--r-- | web/app/view/dialog/AttributeController.js | 12 | ||||
-rw-r--r-- | web/app/view/dialog/ComputedAttribute.js | 22 | ||||
-rw-r--r-- | web/app/view/dialog/ComputedAttributeController.js | 32 | ||||
-rw-r--r-- | web/app/view/dialog/DeviceDistance.js | 2 | ||||
-rw-r--r-- | web/app/view/edit/Attributes.js | 4 | ||||
-rw-r--r-- | web/app/view/edit/ComputedAttributes.js | 15 | ||||
-rw-r--r-- | web/app/view/permissions/DeviceAttributes.js | 5 | ||||
-rw-r--r-- | web/app/view/permissions/GroupAttributes.js | 5 | ||||
-rw-r--r-- | web/app/view/permissions/UserAttributes.js | 5 |
11 files changed, 88 insertions, 24 deletions
diff --git a/web/app/view/CustomNumberField.js b/web/app/view/CustomNumberField.js index 7e2b88e9..e116e934 100644 --- a/web/app/view/CustomNumberField.js +++ b/web/app/view/CustomNumberField.js @@ -24,7 +24,7 @@ Ext.define('Traccar.view.CustomNumberField', { constructor: function (config) { var unit; - if (config.convert === 'speed') { + if (config.dataType === 'speed') { unit = Traccar.app.getPreference('speedUnit', 'kn'); config.beforeSubTpl = this.beforeEl; config.afterSubTpl = this.unitEl + Ext.getStore('SpeedUnits').findRecord('key', unit).get('name') + '</div></div>'; @@ -34,7 +34,7 @@ Ext.define('Traccar.view.CustomNumberField', { config.valueToRaw = function (value) { return Ext.getStore('SpeedUnits').convertValue(value, Traccar.app.getPreference('speedUnit', 'kn')); }; - } else if (config.convert === 'distance') { + } else if (config.dataType === 'distance') { config.beforeSubTpl = this.beforeEl; unit = Traccar.app.getPreference('distanceUnit', 'km'); config.afterSubTpl = this.unitEl + Ext.getStore('DistanceUnits').findRecord('key', unit).get('name') + '</div></div>'; diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js index f0370f96..0723dc13 100644 --- a/web/app/view/StateController.js +++ b/web/app/view/StateController.js @@ -124,15 +124,13 @@ Ext.define('Traccar.view.StateController', { if (aliasIndex !== -1) { name = this.aliasesStore.getAt(aliasIndex).get('alias'); } else { - name = key.replace(/^./, function (match) { - return match.toUpperCase(); - }); + name = Ext.getStore('PositionAttributes').getAttributeName(key, true); } store.add(Ext.create('Traccar.model.Attribute', { priority: 1024, name: name, attribute: key, - value: Traccar.AttributeFormatter.getFormatter(key)(attributes[key]) + value: Traccar.AttributeFormatter.getAttributeFormatter(key)(attributes[key]) })); } } diff --git a/web/app/view/dialog/AttributeController.js b/web/app/view/dialog/AttributeController.js index afa970ad..12e31e8e 100644 --- a/web/app/view/dialog/AttributeController.js +++ b/web/app/view/dialog/AttributeController.js @@ -53,26 +53,26 @@ Ext.define('Traccar.view.dialog.AttributeController', { }, onNameChange: function (combobox, newValue) { - var type, config, attribute, valueField = this.lookupReference('valueField'); + var valueType, config, attribute, valueField = this.lookupReference('valueField'); attribute = combobox.getStore().getById(newValue); if (attribute) { - type = attribute.get('type'); + valueType = attribute.get('valueType'); config = Ext.clone(this.defaultFieldConfig); - if (type === 'number') { + if (valueType === 'number') { config.xtype = 'customNumberField'; if (attribute.get('allowDecimals') !== undefined) { config.allowDecimals = attribute.get('allowDecimals'); } else { config.allowDecimals = true; } - config.convert = attribute.get('convert'); + config.dataType = attribute.get('dataType'); config.maxValue = attribute.get('maxValue'); config.minValue = attribute.get('minValue'); - } else if (type === 'boolean') { + } else if (valueType === 'boolean') { config.xtype = 'checkboxfield'; config.inputValue = true; config.uncheckedValue = false; - } else if (type === 'color') { + } else if (valueType === 'color') { config.xtype = 'customcolorpicker'; } else { config.xtype = 'textfield'; diff --git a/web/app/view/dialog/ComputedAttribute.js b/web/app/view/dialog/ComputedAttribute.js index df074919..90234b57 100644 --- a/web/app/view/dialog/ComputedAttribute.js +++ b/web/app/view/dialog/ComputedAttribute.js @@ -19,6 +19,11 @@ Ext.define('Traccar.view.dialog.ComputedAttribute', { extend: 'Traccar.view.dialog.BaseEdit', + requires: [ + 'Traccar.view.dialog.ComputedAttributeController' + ], + + controller: 'computedAttribute', title: Strings.sharedComputedAttribute, items: { @@ -28,20 +33,29 @@ Ext.define('Traccar.view.dialog.ComputedAttribute', { name: 'description', fieldLabel: Strings.sharedDescription }, { - xtype: 'textfield', + xtype: 'combobox', name: 'attribute', fieldLabel: Strings.sharedAttribute, - allowBlank: false + store: 'PositionAttributes', + displayField: 'name', + valueField: 'key', + listeners: { + change: 'onAttributeChange' + } }, { xtype: 'textareafield', name: 'expression', fieldLabel: Strings.sharedExpression, allowBlank: false }, { - xtype: 'textfield', + xtype: 'combobox', name: 'type', + reference: 'typeComboField', + store: 'AttributeValueTypes', fieldLabel: Strings.sharedType, - allowBlank: false + displayField: 'name', + valueField: 'id', + editable: false }] }, diff --git a/web/app/view/dialog/ComputedAttributeController.js b/web/app/view/dialog/ComputedAttributeController.js new file mode 100644 index 00000000..807653a6 --- /dev/null +++ b/web/app/view/dialog/ComputedAttributeController.js @@ -0,0 +1,32 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org) + * + * 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 <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.ComputedAttributeController', { + extend: 'Traccar.view.dialog.BaseEditController', + alias: 'controller.computedAttribute', + + onAttributeChange: function (combobox, newValue) { + var attribute = Ext.getStore('PositionAttributes').getById(newValue); + if (attribute) { + this.getView().lookupReference('typeComboField').setValue(attribute.get('valueType')); + this.getView().lookupReference('typeComboField').setReadOnly(true); + } else { + this.getView().lookupReference('typeComboField').setReadOnly(false); + } + } +}); diff --git a/web/app/view/dialog/DeviceDistance.js b/web/app/view/dialog/DeviceDistance.js index f908e45e..c6ac9f20 100644 --- a/web/app/view/dialog/DeviceDistance.js +++ b/web/app/view/dialog/DeviceDistance.js @@ -39,7 +39,7 @@ Ext.define('Traccar.view.dialog.DeviceDistance', { } }, { xtype: 'customNumberField', - convert: 'distance', + dataType: 'distance', reference: 'totalDistance', fieldLabel: Strings.deviceTotalDistance }], diff --git a/web/app/view/edit/Attributes.js b/web/app/view/edit/Attributes.js index 7788d8c8..b080e569 100644 --- a/web/app/view/edit/Attributes.js +++ b/web/app/view/edit/Attributes.js @@ -57,9 +57,9 @@ Ext.define('Traccar.view.edit.Attributes', { if (this.attributesStore) { attribute = Ext.getStore(this.attributesStore).getById(record.get('name')); } - if (attribute && attribute.get('convert') === 'speed') { + if (attribute && attribute.get('dataType') === 'speed') { return Ext.getStore('SpeedUnits').formatValue(value, Traccar.app.getPreference('speedUnit', 'kn')); - } else if (attribute && attribute.get('convert') === 'distance') { + } else if (attribute && attribute.get('dataType') === 'distance') { return Ext.getStore('DistanceUnits').formatValue(value, Traccar.app.getPreference('distanceUnit', 'km')); } else { return value; diff --git a/web/app/view/edit/ComputedAttributes.js b/web/app/view/edit/ComputedAttributes.js index 87d3b8da..b4699e84 100644 --- a/web/app/view/edit/ComputedAttributes.js +++ b/web/app/view/edit/ComputedAttributes.js @@ -46,13 +46,24 @@ Ext.define('Traccar.view.edit.ComputedAttributes', { dataIndex: 'description' }, { text: Strings.sharedAttribute, - dataIndex: 'attribute' + dataIndex: 'attribute', + renderer: function (value) { + return Ext.getStore('PositionAttributes').getAttributeName(value); + } }, { text: Strings.sharedExpression, dataIndex: 'expression' }, { text: Strings.sharedType, - dataIndex: 'type' + dataIndex: 'type', + renderer: function (value) { + var type = Ext.getStore('AttributeValueTypes').getById(value); + if (type) { + return type.get('name'); + } else { + return value; + } + } }] } }); diff --git a/web/app/view/permissions/DeviceAttributes.js b/web/app/view/permissions/DeviceAttributes.js index 2f837c42..2ce07633 100644 --- a/web/app/view/permissions/DeviceAttributes.js +++ b/web/app/view/permissions/DeviceAttributes.js @@ -30,7 +30,10 @@ Ext.define('Traccar.view.permissions.DeviceAttributes', { text: Strings.sharedAttribute, dataIndex: 'attribute', flex: 1, - minWidth: Traccar.Style.columnWidthNormal + minWidth: Traccar.Style.columnWidthNormal, + renderer: function (value) { + return Ext.getStore('PositionAttributes').getAttributeName(value); + } }] } }); diff --git a/web/app/view/permissions/GroupAttributes.js b/web/app/view/permissions/GroupAttributes.js index a08eb78e..44089daf 100644 --- a/web/app/view/permissions/GroupAttributes.js +++ b/web/app/view/permissions/GroupAttributes.js @@ -30,7 +30,10 @@ Ext.define('Traccar.view.permissions.GroupAttributes', { text: Strings.sharedAttribute, dataIndex: 'attribute', flex: 1, - minWidth: Traccar.Style.columnWidthNormal + minWidth: Traccar.Style.columnWidthNormal, + renderer: function (value) { + return Ext.getStore('PositionAttributes').getAttributeName(value); + } }] } }); diff --git a/web/app/view/permissions/UserAttributes.js b/web/app/view/permissions/UserAttributes.js index 056c4634..7bca6223 100644 --- a/web/app/view/permissions/UserAttributes.js +++ b/web/app/view/permissions/UserAttributes.js @@ -30,7 +30,10 @@ Ext.define('Traccar.view.permissions.UserAttributes', { text: Strings.sharedAttribute, dataIndex: 'attribute', flex: 1, - minWidth: Traccar.Style.columnWidthNormal + minWidth: Traccar.Style.columnWidthNormal, + renderer: function (value) { + return Ext.getStore('PositionAttributes').getAttributeName(value); + } }] } }); |