aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-09-15 12:24:13 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-09-15 12:24:13 +1200
commitd2139af877194952e3d49ca882188bcebbbd927e (patch)
treef5f6c81df6f04269a0f57d83e5fce17b8c98c346
parent5cf1061cfcc5baf214bce145961512fd4f672621 (diff)
downloadtraccar-server-d2139af877194952e3d49ca882188bcebbbd927e.tar.gz
traccar-server-d2139af877194952e3d49ca882188bcebbbd927e.tar.bz2
traccar-server-d2139af877194952e3d49ca882188bcebbbd927e.zip
Update and format store classes
-rw-r--r--web/app/store/CommandTypes.js20
-rw-r--r--web/app/store/DistanceUnits.js36
-rw-r--r--web/app/store/Languages.js5
-rw-r--r--web/app/store/SpeedUnits.js32
-rw-r--r--web/app/view/report/Report.js2
-rw-r--r--web/app/view/state/StateController.js4
6 files changed, 52 insertions, 47 deletions
diff --git a/web/app/store/CommandTypes.js b/web/app/store/CommandTypes.js
index 6ce247b30..8ff78b5df 100644
--- a/web/app/store/CommandTypes.js
+++ b/web/app/store/CommandTypes.js
@@ -17,10 +17,18 @@
Ext.define('Traccar.store.CommandTypes', {
extend: 'Ext.data.Store',
fields: ['key', 'name'],
- data: [
- {'key': 'positionPeriodic', 'name': strings.commandPositionPeriodic},
- {'key': 'positionStop', 'name': strings.commandPositionStop},
- {'key': 'engineStop', 'name': strings.commandEngineStop},
- {'key': 'engineResume', 'name': strings.commandEngineResume}
- ]
+
+ data: [{
+ key: 'positionPeriodic',
+ name: strings.commandPositionPeriodic
+ }, {
+ key: 'positionStop',
+ name: strings.commandPositionStop
+ }, {
+ key: 'engineStop',
+ name: strings.commandEngineStop
+ }, {
+ key: 'engineResume',
+ name: strings.commandEngineResume
+ }]
});
diff --git a/web/app/store/DistanceUnits.js b/web/app/store/DistanceUnits.js
index 653bf6efb..cedff592a 100644
--- a/web/app/store/DistanceUnits.js
+++ b/web/app/store/DistanceUnits.js
@@ -16,27 +16,25 @@
Ext.define('Traccar.store.DistanceUnits', {
extend: 'Ext.data.Store',
- fields: ['key', 'name'],
- data: [
- {'key': 'km', 'name': strings.sharedKm},
- {'key': 'mi', 'name': strings.sharedMi}
- ],
-
- convert: function(value, unit) {
- switch (unit) {
- case 'km':
- return Math.round(value * 0.1) / 100;
- case 'mi':
- return Math.round(value * 0.0621371) / 100;
- }
- return value;
- },
-
- getUnitName: function(unit) {
+ fields: ['key', 'name', 'factor'],
+
+ data: [{
+ key: 'km',
+ name: strings.sharedKm,
+ factor: 0.001
+ }, {
+ key: 'mi',
+ name: strings.sharedMi,
+ factor: 0.00621371
+ }],
+
+ formatValue: function(value, unit) {
+ var model;
if (unit) {
- return this.findRecord('key', unit).get('name');
+ model = this.findRecord('key', unit);
+ return Math.round(value * model.get('factor') * 100) / 100 + ' ' + model.get('name');
} else {
- return '';
+ return value;
}
}
});
diff --git a/web/app/store/Languages.js b/web/app/store/Languages.js
index 97a581805..360508fd1 100644
--- a/web/app/store/Languages.js
+++ b/web/app/store/Languages.js
@@ -17,13 +17,14 @@
Ext.define('Traccar.store.Languages', {
extend: 'Ext.data.Store',
fields: ['code', 'name'],
+
data: function() {
var data = [];
for (var code in availableLanguages) {
if (availableLanguages.hasOwnProperty(code)) {
data.push({
- 'code': code,
- 'name': availableLanguages[code].name
+ code: code,
+ name: availableLanguages[code].name
});
}
}
diff --git a/web/app/store/SpeedUnits.js b/web/app/store/SpeedUnits.js
index 15c52625f..037670c8d 100644
--- a/web/app/store/SpeedUnits.js
+++ b/web/app/store/SpeedUnits.js
@@ -16,27 +16,25 @@
Ext.define('Traccar.store.SpeedUnits', {
extend: 'Ext.data.Store',
- fields: ['key', 'name'],
- data: [
- {'key': 'kmh', 'name': strings.sharedKmh},
- {'key': 'mph', 'name': strings.sharedMph}
- ],
+ fields: ['key', 'name', 'factor'],
- convert: function(value, unit) {
- switch (unit) {
- case 'kmh':
- return Math.round(value * 1.852 * 10) / 10;
- case 'mph':
- return Math.round(value * 1.15078 * 10) / 10;
- }
- return value;
- },
+ data: [{
+ key: 'kmh',
+ name: strings.sharedKmh,
+ factor: 1.852
+ }, {
+ key: 'mph',
+ name: strings.sharedMph,
+ factor: 1.15078
+ }],
- getUnitName: function(unit) {
+ formatValue: function(value, unit) {
+ var model;
if (unit) {
- return this.findRecord('key', unit).get('name');
+ model = this.findRecord('key', unit);
+ return Math.round(value * model.get('factor') * 10) / 10 + ' ' + model.get('name');
} else {
- return '';
+ return value;
}
}
});
diff --git a/web/app/view/report/Report.js b/web/app/view/report/Report.js
index 8b86b9cc7..8a1dae9c4 100644
--- a/web/app/view/report/Report.js
+++ b/web/app/view/report/Report.js
@@ -91,7 +91,7 @@ Ext.define('Traccar.view.report.Report', {
renderer: function(value) {
var speedUnits = Ext.getStore('SpeedUnits');
var unit = Traccar.getApplication().getUser().get('speedUnit') || Traccar.getApplication().getServer().get('speedUnit') || '';
- return speedUnits.convert(value, unit) + ' ' + speedUnits.getUnitName(unit);
+ return speedUnits.formatValue(value, unit);
}
},
{ text: strings.positionAddress, dataIndex: 'address', flex: 1 }
diff --git a/web/app/view/state/StateController.js b/web/app/view/state/StateController.js
index 36978c3d0..bc125e529 100644
--- a/web/app/view/state/StateController.js
+++ b/web/app/view/state/StateController.js
@@ -95,7 +95,7 @@ Ext.define('Traccar.view.state.StateController', {
if (key === 'speed') {
var speedUnits = Ext.getStore('SpeedUnits');
unit = Traccar.getApplication().getUser().get('speedUnit') || Traccar.getApplication().getServer().get('speedUnit') || '';
- value = speedUnits.convert(value, unit) + ' ' + speedUnits.getUnitName(unit);
+ value = speedUnits.formatValue(value, unit);
} else if (value instanceof Date) {
value = Ext.Date.format(value, styles.dateTimeFormat);
}
@@ -121,7 +121,7 @@ Ext.define('Traccar.view.state.StateController', {
if (key === 'distance' || key === 'odometer') {
var distanceUnits = Ext.getStore('DistanceUnits');
unit = Traccar.getApplication().getUser().get('distanceUnit') || Traccar.getApplication().getServer().get('distanceUnit') || '';
- value = distanceUnits.convert(value, unit) + ' ' + distanceUnits.getUnitName(unit);
+ value = distanceUnits.formatValue(value, unit);
}
store.add(Ext.create('Traccar.model.Attribute', {