diff options
Diffstat (limited to 'web/app/view')
-rw-r--r-- | web/app/view/CommandDialog.js | 2 | ||||
-rw-r--r-- | web/app/view/Report.js | 63 | ||||
-rw-r--r-- | web/app/view/ReportController.js | 177 | ||||
-rw-r--r-- | web/app/view/ServerDialog.js | 2 | ||||
-rw-r--r-- | web/app/view/UserDialog.js | 2 |
5 files changed, 191 insertions, 55 deletions
diff --git a/web/app/view/CommandDialog.js b/web/app/view/CommandDialog.js index 031815273..8e9a80dbf 100644 --- a/web/app/view/CommandDialog.js +++ b/web/app/view/CommandDialog.js @@ -29,7 +29,7 @@ Ext.define('Traccar.view.CommandDialog', { items: [{ xtype: 'combobox', name: 'type', - fieldLabel: Strings.commandType, + fieldLabel: Strings.sharedType, store: 'CommandTypes', displayField: 'name', valueField: 'type', diff --git a/web/app/view/Report.js b/web/app/view/Report.js index b4578915a..7bcfdcb52 100644 --- a/web/app/view/Report.js +++ b/web/app/view/Report.js @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 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. @@ -24,12 +24,24 @@ Ext.define('Traccar.view.Report', { ], controller: 'report', - store: 'ReportRoute', title: Strings.reportTitle, tbar: [{ xtype: 'tbtext', + html: Strings.sharedType + }, { + xtype: 'combobox', + reference: 'reportTypeField', + store: 'ReportTypes', + displayField: 'name', + valueField: 'key', + typeAhead: true, + listeners: { + change: 'onTypeChange' + } + }, '-', { + xtype: 'tbtext', html: Strings.reportDevice }, { xtype: 'combobox', @@ -69,7 +81,12 @@ Ext.define('Traccar.view.Report', { value: new Date() }, '-', { text: Strings.reportShow, - handler: 'onShowClick' + reference: 'showButton', + handler: 'onReportClick' + }, { + text: Strings.reportCsv, + reference: 'csvButton', + handler: 'onReportClick' }, { text: Strings.reportClear, handler: 'onClearClick' @@ -77,43 +94,5 @@ Ext.define('Traccar.view.Report', { listeners: { selectionchange: 'onSelectionChange' - }, - - columns: [{ - text: Strings.positionValid, - dataIndex: 'valid', - flex: 1, - renderer: Traccar.AttributeFormatter.getFormatter('valid') - }, { - text: Strings.positionFixTime, - dataIndex: 'fixTime', - flex: 1, - xtype: 'datecolumn', - renderer: Traccar.AttributeFormatter.getFormatter('fixTime') - }, { - text: Strings.positionLatitude, - dataIndex: 'latitude', - flex: 1, - renderer: Traccar.AttributeFormatter.getFormatter('latitude') - }, { - text: Strings.positionLongitude, - dataIndex: 'longitude', - flex: 1, - renderer: Traccar.AttributeFormatter.getFormatter('latitude') - }, { - text: Strings.positionAltitude, - dataIndex: 'altitude', - flex: 1, - renderer: Traccar.AttributeFormatter.getFormatter('altitude') - }, { - text: Strings.positionSpeed, - dataIndex: 'speed', - flex: 1, - renderer: Traccar.AttributeFormatter.getFormatter('speed') - }, { - text: Strings.positionAddress, - dataIndex: 'address', - flex: 1, - renderer: Traccar.AttributeFormatter.getFormatter('address') - }] + } }); diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js index 04e07e640..4236aadcb 100644 --- a/web/app/view/ReportController.js +++ b/web/app/view/ReportController.js @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 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. @@ -29,15 +29,17 @@ Ext.define('Traccar.view.ReportController', { } }, - onShowClick: function () { - var deviceId, fromDate, fromTime, from, toDate, toTime, to, store; + onReportClick: function (button) { + var reportType, deviceId, fromDate, fromTime, from, toDate, toTime, to, store, url; + + reportType = this.lookupReference('reportTypeField').getValue(); deviceId = this.lookupReference('deviceField').getValue(); fromDate = this.lookupReference('fromDateField').getValue(); fromTime = this.lookupReference('fromTimeField').getValue(); - if (deviceId) { + if (reportType && deviceId) { from = new Date( fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDate(), fromTime.getHours(), fromTime.getMinutes(), fromTime.getSeconds(), fromTime.getMilliseconds()); @@ -49,19 +51,30 @@ Ext.define('Traccar.view.ReportController', { toDate.getFullYear(), toDate.getMonth(), toDate.getDate(), toTime.getHours(), toTime.getMinutes(), toTime.getSeconds(), toTime.getMilliseconds()); - store = Ext.getStore('ReportRoute'); - store.load({ - params: { + if (button.reference === "showButton") { + store = this.getView().getStore(); + store.load({ + params: { + deviceId: deviceId, + type: '%', + from: from.toISOString(), + to: to.toISOString() + } + }); + } else if (button.reference === "csvButton") { + url = this.getView().getStore().getProxy().url; + this.doDownloadCsv(url, { deviceId: deviceId, + type: '%', from: from.toISOString(), to: to.toISOString() - } - }); + }); + } } }, onClearClick: function () { - Ext.getStore('ReportRoute').removeAll(); + this.getView().getStore().removeAll(); }, onSelectionChange: function (selected) { @@ -78,5 +91,149 @@ Ext.define('Traccar.view.ReportController', { selectReport: function (position, center) { this.getView().getSelectionModel().select([position], false, true); + }, + + doDownloadCsv: function (requestUrl, requestParams) { + Ext.Ajax.request({ + url: requestUrl, + method: 'GET', + params: requestParams, + headers: { + Accept: 'text/csv' + }, + success: function (response) { + var disposition, filename, type, blob, url, downloadUrl, a; + disposition = response.getResponseHeader('Content-Disposition'); + filename = disposition.slice(disposition.indexOf("=") + 1, disposition.length); + type = response.getResponseHeader('Content-Type'); + blob = new Blob([response.responseText], { type: type }); + if (typeof window.navigator.msSaveBlob !== 'undefined') { + // IE workaround + window.navigator.msSaveBlob(blob, filename); + } else { + url = window.URL || window.webkitURL; + downloadUrl = URL.createObjectURL(blob); + if (filename) { + a = document.createElement("a"); + a.href = downloadUrl; + a.download = filename; + document.body.appendChild(a); + a.click(); + } + setTimeout(function () { + url.revokeObjectURL(downloadUrl); + }, 100); + } + } + }); + }, + + onTypeChange: function (combobox, newValue, oldValue) { + var routeColumns, eventsColumns, summaryColumns; + if (oldValue !== null) { + this.onClearClick(); + } + routeColumns = [{ + text: Strings.positionValid, + dataIndex: 'valid', + flex: 1, + renderer: Traccar.AttributeFormatter.getFormatter('valid') + }, { + text: Strings.positionFixTime, + dataIndex: 'fixTime', + flex: 1, + xtype: 'datecolumn', + renderer: Traccar.AttributeFormatter.getFormatter('fixTime') + }, { + text: Strings.positionLatitude, + dataIndex: 'latitude', + flex: 1, + renderer: Traccar.AttributeFormatter.getFormatter('latitude') + }, { + text: Strings.positionLongitude, + dataIndex: 'longitude', + flex: 1, + renderer: Traccar.AttributeFormatter.getFormatter('latitude') + }, { + text: Strings.positionAltitude, + dataIndex: 'altitude', + flex: 1, + renderer: Traccar.AttributeFormatter.getFormatter('altitude') + }, { + text: Strings.positionSpeed, + dataIndex: 'speed', + flex: 1, + renderer: Traccar.AttributeFormatter.getFormatter('speed') + }, { + text: Strings.positionAddress, + dataIndex: 'address', + flex: 1, + renderer: Traccar.AttributeFormatter.getFormatter('address') + }]; + + eventsColumns = [{ + text: Strings.positionFixTime, + dataIndex: 'serverTime', + flex: 1, + xtype: 'datecolumn', + renderer: Traccar.AttributeFormatter.getFormatter('serverTime') + }, { + text: Strings.reportDeviceName, + dataIndex: 'deviceId', + flex: 1, + renderer: function (value) { + return Ext.getStore('Devices').findRecord('id', value).get('name'); + } + }, { + text: Strings.sharedType, + dataIndex: 'type', + flex: 1, + renderer: function (value) { + var typeKey = 'event' + value.charAt(0).toUpperCase() + value.slice(1); + return Strings[typeKey]; + } + }, { + text: Strings.sharedGeofence, + dataIndex: 'geofenceId', + flex: 1, + renderer: function (value) { + if (value !== 0) { + return Ext.getStore('Geofences').findRecord('id', value).get('name'); + } + } + }]; + + summaryColumns = [{ + text: Strings.reportDeviceName, + dataIndex: 'deviceId', + flex: 1, + renderer: function (value) { + return Ext.getStore('Devices').findRecord('id', value).get('name'); + } + }, { + text: Strings.sharedDistance, + dataIndex: 'distance', + flex: 1, + renderer: Traccar.AttributeFormatter.getFormatter('distance') + }, { + text: Strings.summaryAverageSpeed, + dataIndex: 'averageSpeed', + flex: 1, + renderer: Traccar.AttributeFormatter.getFormatter('speed') + }, { + text: Strings.summaryMaximumSpeed, + dataIndex: 'maxSpeed', + flex: 1, + renderer: Traccar.AttributeFormatter.getFormatter('speed') + }]; + + if (newValue === 'route') { + this.getView().reconfigure('ReportRoute', routeColumns); + } else if (newValue === 'events') { + this.getView().reconfigure('ReportEvents', eventsColumns); + } else if (newValue === 'summary') { + this.getView().reconfigure('ReportSummary', summaryColumns); + } } + }); diff --git a/web/app/view/ServerDialog.js b/web/app/view/ServerDialog.js index 1af000042..dd4579168 100644 --- a/web/app/view/ServerDialog.js +++ b/web/app/view/ServerDialog.js @@ -54,7 +54,7 @@ Ext.define('Traccar.view.ServerDialog', { }, { xtype: 'combobox', name: 'distanceUnit', - fieldLabel: Strings.settingsDistanceUnit, + fieldLabel: Strings.sharedDistance, store: 'DistanceUnits', displayField: 'name', valueField: 'key' diff --git a/web/app/view/UserDialog.js b/web/app/view/UserDialog.js index df8a26e7e..07fc1431f 100644 --- a/web/app/view/UserDialog.js +++ b/web/app/view/UserDialog.js @@ -58,7 +58,7 @@ Ext.define('Traccar.view.UserDialog', { }, { xtype: 'combobox', name: 'distanceUnit', - fieldLabel: Strings.settingsDistanceUnit, + fieldLabel: Strings.sharedDistance, store: 'DistanceUnits', displayField: 'name', valueField: 'key' |