diff options
Diffstat (limited to 'web/app/AttributeFormatter.js')
-rw-r--r-- | web/app/AttributeFormatter.js | 72 |
1 files changed, 66 insertions, 6 deletions
diff --git a/web/app/AttributeFormatter.js b/web/app/AttributeFormatter.js index 289aff91..c2793827 100644 --- a/web/app/AttributeFormatter.js +++ b/web/app/AttributeFormatter.js @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -60,15 +60,29 @@ Ext.define('Traccar.AttributeFormatter', { return Ext.getStore('VolumeUnits').convertValue(value, Traccar.app.getAttributePreference('volumeUnit')); }, + hoursFormatter: function (value) { + return Ext.getStore('HoursUnits').formatValue(value, 'h'); + }, + + hoursConverter: function (value) { + return Ext.getStore('HoursUnits').convertValue(value, 'h'); + }, + durationFormatter: function (value) { - var hours, minutes; - hours = Math.floor(value / 3600000); - minutes = Math.floor(value % 3600000 / 60000); - return hours + ' ' + Strings.sharedHourAbbreviation + ' ' + minutes + ' ' + Strings.sharedMinuteAbbreviation; + return Ext.getStore('HoursUnits').formatValue(value, 'h', true); }, deviceIdFormatter: function (value) { - return Ext.getStore('Devices').getById(value).get('name'); + var device, store; + if (value !== 0) { + store = Ext.getStore('AllDevices'); + if (store.getTotalCount() === 0) { + store = Ext.getStore('Devices'); + } + device = store.getById(value); + return device ? device.get('name') : ''; + } + return null; }, groupIdFormatter: function (value) { @@ -97,6 +111,19 @@ Ext.define('Traccar.AttributeFormatter', { return null; }, + calendarIdFormatter: function (value) { + var calendar, store; + if (value !== 0) { + store = Ext.getStore('AllCalendars'); + if (store.getTotalCount() === 0) { + store = Ext.getStore('Calendars'); + } + calendar = store.getById(value); + return calendar ? calendar.get('name') : ''; + } + return null; + }, + driverUniqueIdFormatter: function (value) { var driver, store; if (value !== 0) { @@ -110,6 +137,19 @@ Ext.define('Traccar.AttributeFormatter', { return null; }, + maintenanceIdFormatter: function (value) { + var maintenance, store; + if (value !== 0) { + store = Ext.getStore('AllMaintenances'); + if (store.getTotalCount() === 0) { + store = Ext.getStore('Maintenances'); + } + maintenance = store.getById(value); + return maintenance ? maintenance.get('name') : ''; + } + return null; + }, + lastUpdateFormatter: function (value) { var seconds, interval; if (value) { @@ -174,6 +214,10 @@ Ext.define('Traccar.AttributeFormatter', { return this.groupIdFormatter; case 'geofenceId': return this.geofenceIdFormatter; + case 'maintenanceId': + return this.maintenanceIdFormatter; + case 'calendarId': + return this.calendarIdFormatter; case 'lastUpdate': return this.lastUpdateFormatter; case 'spentFuel': @@ -221,6 +265,8 @@ Ext.define('Traccar.AttributeFormatter', { return this.numberFormatterFactory(Traccar.Style.numberPrecision, '°C'); case 'volume': return this.volumeFormatter; + case 'hours': + return this.hoursFormatter; case 'consumption': return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedLiterPerHourAbbreviation); default: @@ -238,10 +284,24 @@ Ext.define('Traccar.AttributeFormatter', { return this.speedConverter; case 'volume': return this.volumeConverter; + case 'hours': + return this.hoursConverter; default: return function (value) { return value; }; } + }, + + renderAttribute: function (value, attribute) { + if (attribute && attribute.get('dataType') === 'speed') { + return Ext.getStore('SpeedUnits').formatValue(value, Traccar.app.getAttributePreference('speedUnit', 'kn'), true); + } else if (attribute && attribute.get('dataType') === 'distance') { + return Ext.getStore('DistanceUnits').formatValue(value, Traccar.app.getAttributePreference('distanceUnit', 'km'), true); + } else if (attribute && attribute.get('dataType') === 'hours') { + return Ext.getStore('HoursUnits').formatValue(value, 'h', true); + } else { + return value; + } } }); |