aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-09-15 22:40:32 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-09-15 22:40:32 +1200
commit4c13d0f9ee6b431c215783070f8a1f410697dc7b (patch)
treefad4674ff5784e4df071419527c4d588be3fa576
parent059e040546df731827a455cefd5b293c3b14694c (diff)
downloadtrackermap-server-4c13d0f9ee6b431c215783070f8a1f410697dc7b.tar.gz
trackermap-server-4c13d0f9ee6b431c215783070f8a1f410697dc7b.tar.bz2
trackermap-server-4c13d0f9ee6b431c215783070f8a1f410697dc7b.zip
Move value formatting code
-rw-r--r--web/app/Application.js34
-rw-r--r--web/app/store/DistanceUnits.js2
-rw-r--r--web/app/store/SpeedUnits.js2
-rw-r--r--web/app/view/report/Report.js54
-rw-r--r--web/app/view/state/StateController.js23
5 files changed, 74 insertions, 41 deletions
diff --git a/web/app/Application.js b/web/app/Application.js
index 0ed509686..93f197fb1 100644
--- a/web/app/Application.js
+++ b/web/app/Application.js
@@ -64,6 +64,40 @@ Ext.define('Traccar.Application', {
getServer: function() {
return this.server;
+ },
+
+ getPreference: function(key, defaultValue) {
+ return this.getUser().get('distanceUnit') | this.getServer().get('distanceUnit') | defaultValue;
+ },
+
+ getRenderer: function(key) {
+ if (key === 'latitude' || key === 'longitude') {
+ return function(value) {
+ return value.toFixed(5);
+ }
+ } else if (key === 'speed') {
+ return function(value) {
+ return Ext.getStore('SpeedUnits').formatValue(value, this.getPreference('speedUnit'));
+ }
+ } else if (key === 'course') {
+ return function(value) {
+ var directions = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
+ return directions[Math.floor(value / 45)];
+ }
+ } else if (key === 'distance' || key === 'odometer') {
+ return function(value) {
+ return Ext.getStore('DistanceUnits').formatValue(value, this.getPreference('distanceUnit'));
+ }
+ } else {
+ return function(value) {
+ if (value instanceof Number) {
+ return value.toFixed(2);
+ } else if (value instanceof Date) {
+ return Ext.Date.format(value, styles.dateTimeFormat);
+ }
+ return value;
+ }
+ }
}
});
diff --git a/web/app/store/DistanceUnits.js b/web/app/store/DistanceUnits.js
index cedff592a..943a4327c 100644
--- a/web/app/store/DistanceUnits.js
+++ b/web/app/store/DistanceUnits.js
@@ -32,7 +32,7 @@ Ext.define('Traccar.store.DistanceUnits', {
var model;
if (unit) {
model = this.findRecord('key', unit);
- return Math.round(value * model.get('factor') * 100) / 100 + ' ' + model.get('name');
+ return (value * model.get('factor')).toFixed(2) + ' ' + model.get('name');
} else {
return value;
}
diff --git a/web/app/store/SpeedUnits.js b/web/app/store/SpeedUnits.js
index 037670c8d..c243e52b6 100644
--- a/web/app/store/SpeedUnits.js
+++ b/web/app/store/SpeedUnits.js
@@ -32,7 +32,7 @@ Ext.define('Traccar.store.SpeedUnits', {
var model;
if (unit) {
model = this.findRecord('key', unit);
- return Math.round(value * model.get('factor') * 10) / 10 + ' ' + model.get('name');
+ return (value * model.get('factor')).toFixed(1) + ' ' + model.get('name');
} else {
return value;
}
diff --git a/web/app/view/report/Report.js b/web/app/view/report/Report.js
index 8a1dae9c4..67547e536 100644
--- a/web/app/view/report/Report.js
+++ b/web/app/view/report/Report.js
@@ -78,23 +78,39 @@ Ext.define('Traccar.view.report.Report', {
selectionchange: 'onSelectionChange'
},
- columns: [
- { text: strings.positionValid, dataIndex: 'valid', flex: 1 },
- { text: strings.positionTime, dataIndex: 'fixTime', flex: 1, xtype: 'datecolumn', format: styles.dateTimeFormat },
- { text: strings.positionLatitude, dataIndex: 'latitude', flex: 1 },
- { text: strings.positionLongitude, dataIndex: 'longitude', flex: 1 },
- { text: strings.positionAltitude, dataIndex: 'altitude', flex: 1 },
- {
- text: strings.positionSpeed,
- dataIndex: 'speed',
- flex: 1,
- renderer: function(value) {
- var speedUnits = Ext.getStore('SpeedUnits');
- var unit = Traccar.getApplication().getUser().get('speedUnit') || Traccar.getApplication().getServer().get('speedUnit') || '';
- return speedUnits.formatValue(value, unit);
- }
- },
- { text: strings.positionAddress, dataIndex: 'address', flex: 1 }
- ]
-
+ columns: [{
+ text: strings.positionValid,
+ dataIndex: 'valid',
+ flex: 1
+ }, {
+ text: strings.positionTime,
+ dataIndex: 'fixTime',
+ flex: 1,
+ xtype: 'datecolumn',
+ //renderer: Traccar.app.getRenderer()
+ }, {
+ text: strings.positionLatitude,
+ dataIndex: 'latitude',
+ flex: 1,
+ //renderer: Traccar.app.getRenderer('latitude')
+ }, {
+ text: strings.positionLongitude,
+ dataIndex: 'longitude',
+ flex: 1,
+ //renderer: Traccar.app.getRenderer('latitude')
+ }, {
+ text: strings.positionAltitude,
+ dataIndex: 'altitude',
+ flex: 1,
+ //renderer: Traccar.app.getRenderer('altitude')
+ }, {
+ text: strings.positionSpeed,
+ dataIndex: 'speed',
+ flex: 1,
+ //renderer: Traccar.app.getRenderer('speed')
+ }, {
+ text: strings.positionAddress,
+ dataIndex: 'address',
+ flex: 1
+ }]
});
diff --git a/web/app/view/state/StateController.js b/web/app/view/state/StateController.js
index 23ac72db3..91fa7714f 100644
--- a/web/app/view/state/StateController.js
+++ b/web/app/view/state/StateController.js
@@ -91,19 +91,10 @@ Ext.define('Traccar.view.state.StateController', {
for (var key in position.data) {
if (position.data.hasOwnProperty(key) && this.keys[key] !== undefined) {
- value = position.get(key);
- if (key === 'speed') {
- var speedUnits = Ext.getStore('SpeedUnits');
- unit = Traccar.getApplication().getUser().get('speedUnit') || Traccar.getApplication().getServer().get('speedUnit') || '';
- value = speedUnits.formatValue(value, unit);
- } else if (value instanceof Date) {
- value = Ext.Date.format(value, styles.dateTimeFormat);
- }
-
store.add(Ext.create('Traccar.model.Attribute', {
priority: this.keys[key].priority,
name: this.keys[key].name,
- value: this.formatValue(value)
+ value: Traccar.getApplication().getRenderer(key)(position.get(key))
}));
}
}
@@ -116,20 +107,12 @@ Ext.define('Traccar.view.state.StateController', {
}
for (var key in attributes) {
if (attributes.hasOwnProperty(key)) {
-
- value = attributes[key];
- if (key === 'distance' || key === 'odometer') {
- var distanceUnits = Ext.getStore('DistanceUnits');
- unit = Traccar.getApplication().getUser().get('distanceUnit') || Traccar.getApplication().getServer().get('distanceUnit') || '';
- value = distanceUnits.formatValue(value, unit);
- }
-
store.add(Ext.create('Traccar.model.Attribute', {
- priority: 999,
+ priority: 1024,
name: key.replace(/^./, function (match) {
return match.toUpperCase();
}),
- value: this.formatValue(value)
+ value: Traccar.getApplication().getRenderer(key)(attributes[key])
}));
}
}