From 35e8f4b4974515733737c5cc1dd439ca47860007 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 31 May 2017 16:55:00 +0500 Subject: Implement Events panel --- web/app/AttributeFormatter.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'web/app/AttributeFormatter.js') diff --git a/web/app/AttributeFormatter.js b/web/app/AttributeFormatter.js index 83d310c..302a894 100644 --- a/web/app/AttributeFormatter.js +++ b/web/app/AttributeFormatter.js @@ -71,6 +71,26 @@ Ext.define('Traccar.AttributeFormatter', { return Ext.getStore('Devices').getById(value).get('name'); }, + lastUpdateFormatter: function (value) { + var seconds, interval; + + if (value) { + seconds = Math.floor((new Date() - value) / 1000); + if (seconds < 0) { + seconds = 0; + } + interval = Math.floor(seconds / 86400); + if (interval > 1) { + return interval + ' ' + Strings.sharedDays; + } + interval = Math.floor(seconds / 3600); + if (interval > 1) { + return interval + ' ' + Strings.sharedHours; + } + return Math.floor(seconds / 60) + ' ' + Strings.sharedMinutes; + } + }, + defaultFormatter: function (value) { if (typeof value === 'number') { return Number(value.toFixed(Traccar.Style.numberPrecision)); @@ -104,6 +124,8 @@ Ext.define('Traccar.AttributeFormatter', { return this.durationFormatter; } else if (key === 'deviceId') { return this.deviceIdFormatter; + } else if (key === 'lastUpdate') { + return this.lastUpdateFormatter; } else { return this.defaultFormatter; } -- cgit v1.2.3