aboutsummaryrefslogtreecommitdiff
path: root/web/app
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-09-06 23:56:08 +1200
committerGitHub <noreply@github.com>2017-09-06 23:56:08 +1200
commit019fccd1bd4a123fe93228462b33f14889b23394 (patch)
tree5323e6bed0fcf18caa4847b47a2acecc9b060198 /web/app
parentf819f04cc8fbc85c299ca647707364a2436d8987 (diff)
parentae877a48698f28beae82753feae9b4a8e0993ca2 (diff)
downloadtrackermap-web-019fccd1bd4a123fe93228462b33f14889b23394.tar.gz
trackermap-web-019fccd1bd4a123fe93228462b33f14889b23394.tar.bz2
trackermap-web-019fccd1bd4a123fe93228462b33f14889b23394.zip
Merge pull request #573 from Abyss777/units_attributes
Move units to attributes and add volume units
Diffstat (limited to 'web/app')
-rw-r--r--web/app/Application.js3
-rw-r--r--web/app/AttributeFormatter.js24
-rw-r--r--web/app/model/ReportStop.js4
-rw-r--r--web/app/model/ReportSummary.js4
-rw-r--r--web/app/model/ReportTrip.js4
-rw-r--r--web/app/model/Server.js9
-rw-r--r--web/app/model/User.js9
-rw-r--r--web/app/store/CommonUserAttributes.js20
-rw-r--r--web/app/store/VolumeUnits.js57
-rw-r--r--web/app/view/dialog/AttributeController.js81
-rw-r--r--web/app/view/dialog/Server.js24
-rw-r--r--web/app/view/dialog/User.js24
12 files changed, 168 insertions, 95 deletions
diff --git a/web/app/Application.js b/web/app/Application.js
index 4f43900b..dee3889b 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 abe0f485..8a9e3dca 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, '&deg;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 c0ca4004..1867f73b 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 5cfbdcd7..4bc78731 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 edff02b5..9004b86d 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 286f9da3..b8a88756 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 a77deebf..c47a8d16 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 d07d955d..1ba223f2 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.settingsDistanceUnit,
+ valueType: 'string',
+ dataType: 'distanceUnit'
+ }, {
+ key: 'speedUnit',
+ name: Strings.settingsSpeedUnit,
+ valueType: 'string',
+ dataType: 'speedUnit'
+ }, {
+ key: 'volumeUnit',
+ name: Strings.settingsVolumeUnit,
+ 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 00000000..2bdf6684
--- /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 12e31e8e..e85125d0 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 a86b7b77..c7b94576 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 344a8f6d..f646d493 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',