aboutsummaryrefslogtreecommitdiff
path: root/web/app/AttributeFormatter.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-06-07 08:21:06 -0700
committerGitHub <noreply@github.com>2017-06-07 08:21:06 -0700
commita330ae09293c62aae381cb2c7f36cfa76b86e813 (patch)
tree26478c08fc6f7136ec8355d13af2a1bbf97207dc /web/app/AttributeFormatter.js
parentb6f2faab0d35d54189fefd7567b6310023c3ad7b (diff)
parente04a02921ea015d4f4fe69c1c3f1813a07be9cf4 (diff)
downloadtrackermap-web-a330ae09293c62aae381cb2c7f36cfa76b86e813.tar.gz
trackermap-web-a330ae09293c62aae381cb2c7f36cfa76b86e813.tar.bz2
trackermap-web-a330ae09293c62aae381cb2c7f36cfa76b86e813.zip
Merge pull request #501 from Abyss777/position_attributes_reports
Known position attributes for reports and charts
Diffstat (limited to 'web/app/AttributeFormatter.js')
-rw-r--r--web/app/AttributeFormatter.js73
1 files changed, 50 insertions, 23 deletions
diff --git a/web/app/AttributeFormatter.js b/web/app/AttributeFormatter.js
index 302a8941..3f7c1276 100644
--- a/web/app/AttributeFormatter.js
+++ b/web/app/AttributeFormatter.js
@@ -18,6 +18,14 @@
Ext.define('Traccar.AttributeFormatter', {
singleton: true,
+ numberFormatterFactory: function (precision, suffix) {
+ return function (value) {
+ if (value !== undefined) {
+ return Number(value.toFixed(precision)) + ' ' + suffix;
+ }
+ };
+ },
+
coordinateFormatter: function (key, value) {
return Ext.getStore('CoordinateFormats').formatValue(key, value, Traccar.app.getPreference('coordinateFormat'));
},
@@ -26,6 +34,10 @@ Ext.define('Traccar.AttributeFormatter', {
return Ext.getStore('SpeedUnits').formatValue(value, Traccar.app.getPreference('speedUnit'));
},
+ speedConverter: function (value) {
+ return Ext.getStore('SpeedUnits').convertValue(value, Traccar.app.getPreference('speedUnit'));
+ },
+
courseFormatter: function (value) {
var courseValues = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
return courseValues[Math.floor(value / 45)];
@@ -35,24 +47,8 @@ Ext.define('Traccar.AttributeFormatter', {
return Ext.getStore('DistanceUnits').formatValue(value, Traccar.app.getPreference('distanceUnit'));
},
- voltageFormatter: function (value) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' ' + Strings.sharedVoltAbbreviation;
- },
-
- percentageFormatter: function (value) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' &#37;';
- },
-
- temperatureFormatter: function (value) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' &deg;C';
- },
-
- volumeFormatter: function (value) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' ' + Strings.sharedLiterAbbreviation;
- },
-
- consumptionFormatter: function (value) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' ' + Strings.sharedLiterPerHourAbbreviation;
+ distanceConverter: function (value) {
+ return Ext.getStore('DistanceUnits').convertValue(value, Traccar.app.getPreference('distanceUnit'));
},
hoursFormatter: function (value) {
@@ -131,6 +127,18 @@ Ext.define('Traccar.AttributeFormatter', {
}
},
+ getConverter: function (key) {
+ if (key === 'speed') {
+ return this.speedConverter;
+ } else if (key === 'distance' || key === 'accuracy') {
+ return this.distanceConverter;
+ } else {
+ return function (value) {
+ return value;
+ };
+ }
+ },
+
getAttributeFormatter: function (key) {
var dataType = Ext.getStore('PositionAttributes').getAttributeDataType(key);
if (!dataType) {
@@ -141,18 +149,37 @@ Ext.define('Traccar.AttributeFormatter', {
} else if (dataType === 'speed') {
return this.speedFormatter;
} else if (dataType === 'voltage') {
- return this.voltageFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedVoltAbbreviation);
} else if (dataType === 'percentage') {
- return this.percentageFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, '&#37;');
} else if (dataType === 'temperature') {
- return this.temperatureFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, '&deg;C');
} else if (dataType === 'volume') {
- return this.volumeFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedLiterAbbreviation);
} else if (dataType === 'consumption') {
- return this.consumptionFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedLiterPerHourAbbreviation);
} else {
return this.defaultFormatter;
}
}
+ },
+
+ getAttributeConverter: function (key) {
+ var dataType = Ext.getStore('PositionAttributes').getAttributeDataType(key);
+ if (!dataType) {
+ return function (value) {
+ return value;
+ };
+ } else {
+ if (dataType === 'distance') {
+ return this.distanceConverter;
+ } else if (dataType === 'speed') {
+ return this.speedConverter;
+ } else {
+ return function (value) {
+ return value;
+ };
+ }
+ }
}
});