From 4f61e2a9fd0f9632e05d5bac0648c2548b9cef39 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 6 Jun 2017 13:52:35 +0500 Subject: Optimize formatValue functions --- web/app/store/DistanceUnits.js | 13 ++----------- web/app/store/SpeedUnits.js | 13 ++----------- web/app/view/edit/Attributes.js | 4 ++-- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/web/app/store/DistanceUnits.js b/web/app/store/DistanceUnits.js index 189f79b..e64ce23 100644 --- a/web/app/store/DistanceUnits.js +++ b/web/app/store/DistanceUnits.js @@ -42,21 +42,12 @@ Ext.define('Traccar.store.DistanceUnits', { return back ? value / model.get('factor') : value * model.get('factor'); }, - formatValue: function (value, unit) { + formatValue: function (value, unit, convert) { var model; if (!unit) { unit = 'km'; } model = this.findRecord('key', unit); - return value.toFixed(2) + ' ' + model.get('name'); - }, - - convertAndFormat: function (value, unit) { - var model; - if (!unit) { - unit = 'km'; - } - model = this.findRecord('key', unit); - return this.convertValue(value, unit).toFixed(2) + ' ' + model.get('name'); + return (convert ? this.convertValue(value, unit) : value).toFixed(2) + ' ' + model.get('name'); } }); diff --git a/web/app/store/SpeedUnits.js b/web/app/store/SpeedUnits.js index fc2e573..a36be92 100644 --- a/web/app/store/SpeedUnits.js +++ b/web/app/store/SpeedUnits.js @@ -42,21 +42,12 @@ Ext.define('Traccar.store.SpeedUnits', { return back ? value / model.get('factor') : value * model.get('factor'); }, - formatValue: function (value, unit) { + formatValue: function (value, unit, convert) { var model; if (!unit) { unit = 'kn'; } model = this.findRecord('key', unit); - return value.toFixed(1) + ' ' + model.get('name'); - }, - - convertAndFormat: function (value, unit) { - var model; - if (!unit) { - unit = 'kn'; - } - model = this.findRecord('key', unit); - return this.convertValue(value, unit).toFixed(1) + ' ' + model.get('name'); + return (convert ? this.convertValue(value, unit) : value).toFixed(1) + ' ' + model.get('name'); } }); diff --git a/web/app/view/edit/Attributes.js b/web/app/view/edit/Attributes.js index 0d16e1e..66d8bb1 100644 --- a/web/app/view/edit/Attributes.js +++ b/web/app/view/edit/Attributes.js @@ -58,9 +58,9 @@ Ext.define('Traccar.view.edit.Attributes', { attribute = Ext.getStore(this.attributesStore).getById(record.get('name')); } if (attribute && attribute.get('dataType') === 'speed') { - return Ext.getStore('SpeedUnits').convertAndFormat(value, Traccar.app.getPreference('speedUnit', 'kn')); + return Ext.getStore('SpeedUnits').formatValue(value, Traccar.app.getPreference('speedUnit', 'kn'), true); } else if (attribute && attribute.get('dataType') === 'distance') { - return Ext.getStore('DistanceUnits').convertAndFormat(value, Traccar.app.getPreference('distanceUnit', 'km')); + return Ext.getStore('DistanceUnits').formatValue(value, Traccar.app.getPreference('distanceUnit', 'km'), true); } else { return value; } -- cgit v1.2.3