diff options
Diffstat (limited to 'web/app')
-rw-r--r-- | web/app/Application.js | 3 | ||||
-rw-r--r-- | web/app/AttributeFormatter.js | 24 | ||||
-rw-r--r-- | web/app/model/ReportStop.js | 4 | ||||
-rw-r--r-- | web/app/model/ReportSummary.js | 4 | ||||
-rw-r--r-- | web/app/model/ReportTrip.js | 4 | ||||
-rw-r--r-- | web/app/model/Server.js | 9 | ||||
-rw-r--r-- | web/app/model/User.js | 9 | ||||
-rw-r--r-- | web/app/store/CommonUserAttributes.js | 20 | ||||
-rw-r--r-- | web/app/store/VolumeUnits.js | 57 | ||||
-rw-r--r-- | web/app/view/dialog/AttributeController.js | 81 | ||||
-rw-r--r-- | web/app/view/dialog/Server.js | 24 | ||||
-rw-r--r-- | web/app/view/dialog/User.js | 24 |
12 files changed, 168 insertions, 95 deletions
diff --git a/web/app/Application.js b/web/app/Application.js index 4f43900..dee3889 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -95,7 +95,8 @@ Ext.define('Traccar.Application', { 'AttributeValueTypes', 'Drivers', 'AllDrivers', - 'KnownCommands' + 'KnownCommands', + 'VolumeUnits' ], controllers: [ diff --git a/web/app/AttributeFormatter.js b/web/app/AttributeFormatter.js index abe0f48..8a9e3dc 100644 --- a/web/app/AttributeFormatter.js +++ b/web/app/AttributeFormatter.js @@ -32,11 +32,11 @@ Ext.define('Traccar.AttributeFormatter', { }, speedFormatter: function (value) { - return Ext.getStore('SpeedUnits').formatValue(value, Traccar.app.getPreference('speedUnit')); + return Ext.getStore('SpeedUnits').formatValue(value, Traccar.app.getAttributePreference('speedUnit')); }, speedConverter: function (value) { - return Ext.getStore('SpeedUnits').convertValue(value, Traccar.app.getPreference('speedUnit')); + return Ext.getStore('SpeedUnits').convertValue(value, Traccar.app.getAttributePreference('speedUnit')); }, courseFormatter: function (value) { @@ -45,11 +45,19 @@ Ext.define('Traccar.AttributeFormatter', { }, distanceFormatter: function (value) { - return Ext.getStore('DistanceUnits').formatValue(value, Traccar.app.getPreference('distanceUnit')); + return Ext.getStore('DistanceUnits').formatValue(value, Traccar.app.getAttributePreference('distanceUnit')); }, distanceConverter: function (value) { - return Ext.getStore('DistanceUnits').convertValue(value, Traccar.app.getPreference('distanceUnit')); + return Ext.getStore('DistanceUnits').convertValue(value, Traccar.app.getAttributePreference('distanceUnit')); + }, + + volumeFormatter: function (value) { + return Ext.getStore('VolumeUnits').formatValue(value, Traccar.app.getAttributePreference('volumeUnit')); + }, + + volumeConverter: function (value) { + return Ext.getStore('VolumeUnits').convertValue(value, Traccar.app.getAttributePreference('volumeUnit')); }, durationFormatter: function (value) { @@ -164,7 +172,7 @@ Ext.define('Traccar.AttributeFormatter', { case 'lastUpdate': return this.lastUpdateFormatter; case 'spentFuel': - return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedLiterAbbreviation); + return this.volumeFormatter; case 'driverUniqueId': return this.driverUniqueIdFormatter; default: @@ -179,6 +187,8 @@ Ext.define('Traccar.AttributeFormatter', { case 'distance': case 'accuracy': return this.distanceConverter; + case 'spentFuel': + return this.volumeConverter; default: return function (value) { return value; @@ -203,7 +213,7 @@ Ext.define('Traccar.AttributeFormatter', { case 'temperature': return this.numberFormatterFactory(Traccar.Style.numberPrecision, '°C'); case 'volume': - return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedLiterAbbreviation); + return this.volumeFormatter; case 'consumption': return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedLiterPerHourAbbreviation); default: @@ -219,6 +229,8 @@ Ext.define('Traccar.AttributeFormatter', { return this.distanceConverter; case 'speed': return this.speedConverter; + case 'volume': + return this.volumeConverter; default: return function (value) { return value; diff --git a/web/app/model/ReportStop.js b/web/app/model/ReportStop.js index c0ca400..1867f73 100644 --- a/web/app/model/ReportStop.js +++ b/web/app/model/ReportStop.js @@ -46,5 +46,9 @@ Ext.define('Traccar.model.ReportStop', { }, { name: 'positionId', type: 'int' + }, { + name: 'spentFuel', + type: 'float', + convert: Traccar.AttributeFormatter.getConverter('spentFuel') }] }); diff --git a/web/app/model/ReportSummary.js b/web/app/model/ReportSummary.js index 5cfbdcd..4bc7873 100644 --- a/web/app/model/ReportSummary.js +++ b/web/app/model/ReportSummary.js @@ -41,5 +41,9 @@ Ext.define('Traccar.model.ReportSummary', { }, { name: 'engineHours', type: 'int' + }, { + name: 'spentFuel', + type: 'float', + convert: Traccar.AttributeFormatter.getConverter('spentFuel') }] }); diff --git a/web/app/model/ReportTrip.js b/web/app/model/ReportTrip.js index edff02b..9004b86 100644 --- a/web/app/model/ReportTrip.js +++ b/web/app/model/ReportTrip.js @@ -56,6 +56,10 @@ Ext.define('Traccar.model.ReportTrip', { name: 'endAddress', type: 'string' }, { + name: 'spentFuel', + type: 'float', + convert: Traccar.AttributeFormatter.getConverter('spentFuel') + }, { name: 'driverUniqueId', type: 'string' }, { diff --git a/web/app/model/Server.js b/web/app/model/Server.js index 286f9da..b8a8875 100644 --- a/web/app/model/Server.js +++ b/web/app/model/Server.js @@ -41,12 +41,6 @@ Ext.define('Traccar.model.Server', { name: 'mapUrl', type: 'string' }, { - name: 'distanceUnit', - type: 'string' - }, { - name: 'speedUnit', - type: 'string' - }, { name: 'latitude', type: 'float' }, { @@ -65,9 +59,6 @@ Ext.define('Traccar.model.Server', { name: 'coordinateFormat', type: 'string' }, { - name: 'timezone', - type: 'string' - }, { name: 'attributes' }], diff --git a/web/app/model/User.js b/web/app/model/User.js index a77deeb..c47a8d1 100644 --- a/web/app/model/User.js +++ b/web/app/model/User.js @@ -44,12 +44,6 @@ Ext.define('Traccar.model.User', { name: 'map', type: 'string' }, { - name: 'distanceUnit', - type: 'string' - }, { - name: 'speedUnit', - type: 'string' - }, { name: 'latitude', type: 'float' }, { @@ -84,9 +78,6 @@ Ext.define('Traccar.model.User', { name: 'token', type: 'string' }, { - name: 'timezone', - type: 'string' - }, { name: 'attributes' }], diff --git a/web/app/store/CommonUserAttributes.js b/web/app/store/CommonUserAttributes.js index d07d955..d000909 100644 --- a/web/app/store/CommonUserAttributes.js +++ b/web/app/store/CommonUserAttributes.js @@ -58,5 +58,25 @@ Ext.define('Traccar.store.CommonUserAttributes', { key: 'ui.disableCalendars', name: Strings.attributeUiDisableCalendars, valueType: 'boolean' + }, { + key: 'distanceUnit', + name: Strings.sharedDistance, + valueType: 'string', + dataType: 'distanceUnit' + }, { + key: 'speedUnit', + name: Strings.settingsSpeedUnit, + valueType: 'string', + dataType: 'speedUnit' + }, { + key: 'volumeUnit', + name: Strings.sharedVolumeUnit, + valueType: 'string', + dataType: 'volumeUnit' + }, { + key: 'timezone', + name: Strings.sharedTimezone, + valueType: 'string', + dataType: 'timezone' }] }); diff --git a/web/app/store/VolumeUnits.js b/web/app/store/VolumeUnits.js new file mode 100644 index 0000000..2bdf668 --- /dev/null +++ b/web/app/store/VolumeUnits.js @@ -0,0 +1,57 @@ +/* + * 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.store.VolumeUnits', { + extend: 'Ext.data.Store', + fields: ['key', 'name', 'fullName', 'factor'], + + data: [{ + key: 'ltr', + name: Strings.sharedLiterAbbreviation, + fullName: Strings.sharedLiter, + factor: 1 + }, { + key: 'impGal', + name: Strings.sharedGallonAbbreviation, + fullName: Strings.sharedImpGallon, + factor: 4.546 + }, { + key: 'usGal', + name: Strings.sharedGallonAbbreviation, + fullName: Strings.sharedUsGallon, + factor: 3.785 + }], + + convertValue: function (value, unit, back) { + var model; + if (!unit) { + unit = 'ltr'; + } + model = this.findRecord('key', unit); + return back ? value * model.get('factor') : value / model.get('factor'); + }, + + formatValue: function (value, unit, convert) { + var model; + if (!unit) { + unit = 'ltr'; + } + model = this.findRecord('key', unit); + return (convert ? this.convertValue(value, unit) : value).toFixed(1) + ' ' + model.get('name'); + } +}); diff --git a/web/app/view/dialog/AttributeController.js b/web/app/view/dialog/AttributeController.js index 12e31e8..e85125d 100644 --- a/web/app/view/dialog/AttributeController.js +++ b/web/app/view/dialog/AttributeController.js @@ -53,35 +53,72 @@ Ext.define('Traccar.view.dialog.AttributeController', { }, onNameChange: function (combobox, newValue) { - var valueType, config, attribute, valueField = this.lookupReference('valueField'); + var config, attribute, valueField = this.lookupReference('valueField'); attribute = combobox.getStore().getById(newValue); if (attribute) { - valueType = attribute.get('valueType'); config = Ext.clone(this.defaultFieldConfig); - if (valueType === 'number') { - config.xtype = 'customNumberField'; - if (attribute.get('allowDecimals') !== undefined) { - config.allowDecimals = attribute.get('allowDecimals'); - } else { - config.allowDecimals = true; - } - config.dataType = attribute.get('dataType'); - config.maxValue = attribute.get('maxValue'); - config.minValue = attribute.get('minValue'); - } else if (valueType === 'boolean') { - config.xtype = 'checkboxfield'; - config.inputValue = true; - config.uncheckedValue = false; - } else if (valueType === 'color') { - config.xtype = 'customcolorpicker'; - } else { - config.xtype = 'textfield'; + switch (attribute.get('valueType')) { + case 'number': + config.xtype = 'customNumberField'; + if (attribute.get('allowDecimals') !== undefined) { + config.allowDecimals = attribute.get('allowDecimals'); + } else { + config.allowDecimals = true; + } + config.dataType = attribute.get('dataType'); + config.maxValue = attribute.get('maxValue'); + config.minValue = attribute.get('minValue'); + break; + case 'boolean': + config.xtype = 'checkboxfield'; + config.inputValue = true; + config.uncheckedValue = false; + break; + case 'color': + config.xtype = 'customcolorpicker'; + break; + default: + if (attribute.get('dataType')) { + config.xtype = 'combobox'; + config.queryMode = 'local'; + config.editable = false; + switch (attribute.get('dataType')) { + case 'distanceUnit': + config.store = 'DistanceUnits'; + config.displayField = 'name'; + config.valueField = 'key'; + break; + case 'speedUnit': + config.store = 'SpeedUnits'; + config.displayField = 'name'; + config.valueField = 'key'; + break; + case 'volumeUnit': + config.store = 'VolumeUnits'; + config.displayField = 'fullName'; + config.valueField = 'key'; + break; + case 'timezone': + config.store = 'AllTimezones'; + config.displayField = 'key'; + break; + default: + break; + } + } else { + config.xtype = 'textfield'; + } + break; } - if (valueField.getXType() !== config.xtype || valueField.convert !== config.convert) { + if (valueField.getXType() !== config.xtype) { this.getView().down('form').insert(this.getView().down('form').items.indexOf(valueField), config); this.getView().down('form').remove(valueField); - } else if (config.xtype === 'numberfield') { + } else if (config.xtype === 'customNumberField') { + valueField.setConfig(config); + valueField.validate(); + } else if (config.xtype === 'combobox') { valueField.setConfig(config); + valueField.setValue(); } } } diff --git a/web/app/view/dialog/Server.js b/web/app/view/dialog/Server.js index a86b7b7..c7b9457 100644 --- a/web/app/view/dialog/Server.js +++ b/web/app/view/dialog/Server.js @@ -47,22 +47,6 @@ Ext.define('Traccar.view.dialog.Server', { name: 'mapUrl', fieldLabel: Strings.mapCustom }, { - xtype: 'combobox', - name: 'distanceUnit', - fieldLabel: Strings.sharedDistance, - store: 'DistanceUnits', - displayField: 'name', - valueField: 'key', - editable: false - }, { - xtype: 'combobox', - name: 'speedUnit', - fieldLabel: Strings.settingsSpeedUnit, - store: 'SpeedUnits', - displayField: 'name', - valueField: 'key', - editable: false - }, { xtype: 'numberfield', reference: 'latitude', name: 'latitude', @@ -101,14 +85,6 @@ Ext.define('Traccar.view.dialog.Server', { displayField: 'name', valueField: 'key', editable: false - }, { - xtype: 'combobox', - name: 'timezone', - fieldLabel: Strings.sharedTimezone, - store: 'AllTimezones', - queryMode: 'local', - displayField: 'key', - editable: false }] }, { xtype: 'fieldset', diff --git a/web/app/view/dialog/User.js b/web/app/view/dialog/User.js index 344a8f6..f646d49 100644 --- a/web/app/view/dialog/User.js +++ b/web/app/view/dialog/User.js @@ -64,22 +64,6 @@ Ext.define('Traccar.view.dialog.User', { valueField: 'key', editable: false }, { - xtype: 'combobox', - name: 'distanceUnit', - fieldLabel: Strings.sharedDistance, - store: 'DistanceUnits', - displayField: 'name', - valueField: 'key', - editable: false - }, { - xtype: 'combobox', - name: 'speedUnit', - fieldLabel: Strings.settingsSpeedUnit, - store: 'SpeedUnits', - displayField: 'name', - valueField: 'key', - editable: false - }, { xtype: 'numberfield', reference: 'latitude', name: 'latitude', @@ -111,14 +95,6 @@ Ext.define('Traccar.view.dialog.User', { displayField: 'name', valueField: 'key', editable: false - }, { - xtype: 'combobox', - name: 'timezone', - fieldLabel: Strings.sharedTimezone, - store: 'AllTimezones', - queryMode: 'local', - displayField: 'key', - editable: false }] }, { xtype: 'fieldset', |