diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-09-16 19:45:57 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-09-16 19:45:57 +1200 |
commit | c83cd82f605e93d17666ce5fd165552e56e21a31 (patch) | |
tree | 8795aaf5b88e2073a31120c6055cefe1cdac808b /web | |
parent | 2c9cbb340ff17a8af0129ab7a4ffa9e535c26a22 (diff) | |
download | traccar-server-c83cd82f605e93d17666ce5fd165552e56e21a31.tar.gz traccar-server-c83cd82f605e93d17666ce5fd165552e56e21a31.tar.bz2 traccar-server-c83cd82f605e93d17666ce5fd165552e56e21a31.zip |
Add attribute formatter class
Diffstat (limited to 'web')
-rw-r--r-- | web/app/Application.js | 35 | ||||
-rw-r--r-- | web/app/AttributeFormatter.js | 61 | ||||
-rw-r--r-- | web/app/view/report/Report.js | 10 | ||||
-rw-r--r-- | web/app/view/state/StateController.js | 4 |
4 files changed, 71 insertions, 39 deletions
diff --git a/web/app/Application.js b/web/app/Application.js index 93f197fb1..91d2b7835 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -20,7 +20,8 @@ Ext.define('Traccar.Application', { requires: [ 'Traccar.Resources', - 'Traccar.ErrorManager' + 'Traccar.ErrorManager', + 'Traccar.AttributeFormatter' ], models: [ @@ -68,36 +69,6 @@ Ext.define('Traccar.Application', { 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/AttributeFormatter.js b/web/app/AttributeFormatter.js new file mode 100644 index 000000000..294fdaaba --- /dev/null +++ b/web/app/AttributeFormatter.js @@ -0,0 +1,61 @@ +/* + * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.AttributeFormatter', { + singleton: true, + + coordinateFormatter: function(value) { + return value.toFixed(5); + }, + + speedFormatter: function(value) { + return Ext.getStore('SpeedUnits').formatValue(value, Traccar.app.getPreference('speedUnit')); + }, + + courseValues: ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'], + + courseFormatter: function(value) { + return this.courseValues[Math.floor(value / 45)]; + }, + + distanceFormatter: function(value) { + return Ext.getStore('DistanceUnits').formatValue(value, Traccar.app.getPreference('distanceUnit')); + }, + + defaultFormatter: function(value) { + if (value instanceof Number) { + return value.toFixed(2); + } else if (value instanceof Date) { + return Ext.Date.format(value, styles.dateTimeFormat); + } + return value; + }, + + getFormatter: function(key) { + if (key === 'latitude' || key === 'longitude') { + return this.coordinateFormatter; + } else if (key === 'speed') { + return this.speedFormatter; + } else if (key === 'course') { + return this.courseFormatter; + } else if (key === 'distance' || key === 'odometer') { + return this.distanceFormatter; + } else { + return this.defaultFormatter; + } + } + +}); diff --git a/web/app/view/report/Report.js b/web/app/view/report/Report.js index 67547e536..25f3b244a 100644 --- a/web/app/view/report/Report.js +++ b/web/app/view/report/Report.js @@ -87,27 +87,27 @@ Ext.define('Traccar.view.report.Report', { dataIndex: 'fixTime', flex: 1, xtype: 'datecolumn', - //renderer: Traccar.app.getRenderer() + renderer: Traccar.AttributeFormatter.getFormatter('fixTime') }, { text: strings.positionLatitude, dataIndex: 'latitude', flex: 1, - //renderer: Traccar.app.getRenderer('latitude') + renderer: Traccar.AttributeFormatter.getFormatter('latitude') }, { text: strings.positionLongitude, dataIndex: 'longitude', flex: 1, - //renderer: Traccar.app.getRenderer('latitude') + renderer: Traccar.AttributeFormatter.getFormatter('latitude') }, { text: strings.positionAltitude, dataIndex: 'altitude', flex: 1, - //renderer: Traccar.app.getRenderer('altitude') + renderer: Traccar.AttributeFormatter.getFormatter('altitude') }, { text: strings.positionSpeed, dataIndex: 'speed', flex: 1, - //renderer: Traccar.app.getRenderer('speed') + renderer: Traccar.AttributeFormatter.getFormatter('speed') }, { text: strings.positionAddress, dataIndex: 'address', diff --git a/web/app/view/state/StateController.js b/web/app/view/state/StateController.js index 91fa7714f..9019d996e 100644 --- a/web/app/view/state/StateController.js +++ b/web/app/view/state/StateController.js @@ -94,7 +94,7 @@ Ext.define('Traccar.view.state.StateController', { store.add(Ext.create('Traccar.model.Attribute', { priority: this.keys[key].priority, name: this.keys[key].name, - value: Traccar.getApplication().getRenderer(key)(position.get(key)) + value: Traccar.AttributeFormatter.getFormatter(key)(position.get(key)) })); } } @@ -112,7 +112,7 @@ Ext.define('Traccar.view.state.StateController', { name: key.replace(/^./, function (match) { return match.toUpperCase(); }), - value: Traccar.getApplication().getRenderer(key)(attributes[key]) + value: Traccar.AttributeFormatter.getFormatter(key)(attributes[key]) })); } } |