From 1edfec60e54b26f3cd7970075b58bb69920b37f7 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 6 Sep 2017 13:28:48 +0500 Subject: Move units to attributes and add volume units --- web/app/Application.js | 3 +- web/app/AttributeFormatter.js | 24 ++++++--- web/app/model/ReportStop.js | 4 ++ web/app/model/ReportSummary.js | 4 ++ web/app/model/ReportTrip.js | 4 ++ web/app/model/Server.js | 9 ---- web/app/model/User.js | 9 ---- web/app/store/CommonUserAttributes.js | 20 ++++++++ web/app/store/VolumeUnits.js | 57 +++++++++++++++++++++ web/app/view/dialog/AttributeController.js | 81 ++++++++++++++++++++++-------- web/app/view/dialog/Server.js | 24 --------- web/app/view/dialog/User.js | 24 --------- web/l10n/en.json | 5 ++ 13 files changed, 173 insertions(+), 95 deletions(-) create mode 100644 web/app/store/VolumeUnits.js 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 @@ -55,6 +55,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 @@ -40,12 +40,6 @@ Ext.define('Traccar.model.Server', { }, { name: 'mapUrl', type: 'string' - }, { - name: 'distanceUnit', - type: 'string' - }, { - name: 'speedUnit', - type: 'string' }, { name: 'latitude', type: 'float' @@ -64,9 +58,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 @@ -43,12 +43,6 @@ Ext.define('Traccar.model.User', { }, { name: 'map', type: 'string' - }, { - name: 'distanceUnit', - type: 'string' - }, { - name: 'speedUnit', - type: 'string' }, { name: 'latitude', type: 'float' @@ -83,9 +77,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 . + */ + +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 @@ -46,22 +46,6 @@ Ext.define('Traccar.view.dialog.Server', { xtype: 'textfield', 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', @@ -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 @@ -63,22 +63,6 @@ Ext.define('Traccar.view.dialog.User', { displayField: 'name', 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', @@ -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', diff --git a/web/l10n/en.json b/web/l10n/en.json index 894ae2e..596e213 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -42,6 +42,10 @@ "sharedSecondAbbreviation": "s", "sharedVoltAbbreviation": "V", "sharedLiterAbbreviation": "l", + "sharedGallonAbbreviation": "gal", + "sharedLiter": "Liter", + "sharedImpGallon": "Imp. Gallon", + "sharedUsGallon": "U.S. Gallon", "sharedLiterPerHourAbbreviation": "l/h", "sharedGetMapState": "Get Map State", "sharedComputedAttribute": "Computed Attribute", @@ -64,6 +68,7 @@ "sharedTypeNumber": "Number", "sharedTypeBoolean": "Boolean", "sharedTimezone": "Timezone", + "sharedVolumeUnit": "Volume", "sharedInfoTitle": "Info", "attributeSpeedLimit": "Speed Limit", "attributeReportIgnoreOdometer": "Report: Ignore Odometer", -- cgit v1.2.3 From ae877a48698f28beae82753feae9b4a8e0993ca2 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 6 Sep 2017 16:51:44 +0500 Subject: Add "Unit" to strings --- web/app/store/CommonUserAttributes.js | 4 ++-- web/l10n/en.json | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/web/app/store/CommonUserAttributes.js b/web/app/store/CommonUserAttributes.js index d000909..1ba223f 100644 --- a/web/app/store/CommonUserAttributes.js +++ b/web/app/store/CommonUserAttributes.js @@ -60,7 +60,7 @@ Ext.define('Traccar.store.CommonUserAttributes', { valueType: 'boolean' }, { key: 'distanceUnit', - name: Strings.sharedDistance, + name: Strings.settingsDistanceUnit, valueType: 'string', dataType: 'distanceUnit' }, { @@ -70,7 +70,7 @@ Ext.define('Traccar.store.CommonUserAttributes', { dataType: 'speedUnit' }, { key: 'volumeUnit', - name: Strings.sharedVolumeUnit, + name: Strings.settingsVolumeUnit, valueType: 'string', dataType: 'volumeUnit' }, { diff --git a/web/l10n/en.json b/web/l10n/en.json index 596e213..2769698 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -68,7 +68,6 @@ "sharedTypeNumber": "Number", "sharedTypeBoolean": "Boolean", "sharedTimezone": "Timezone", - "sharedVolumeUnit": "Volume", "sharedInfoTitle": "Info", "attributeSpeedLimit": "Speed Limit", "attributeReportIgnoreOdometer": "Report: Ignore Odometer", @@ -141,7 +140,9 @@ "settingsGroups": "Groups", "settingsServer": "Server", "settingsUsers": "Users", - "settingsSpeedUnit": "Speed", + "settingsDistanceUnit": "Distance Unit", + "settingsSpeedUnit": "Speed Unit", + "settingsVolumeUnit": "Volume Unit", "settingsTwelveHourFormat": "12-hour Format", "settingsCoordinateFormat": "Coordinates Format", "reportTitle": "Reports", -- cgit v1.2.3