diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-09-01 00:23:06 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-01 00:23:05 +1200 |
commit | ee8beb01019f381eae09fb94e249e3d5b9312bbb (patch) | |
tree | 24ff56d9763f881e591fc027a48cab8c962a8bc9 | |
parent | 0a63cdc62c4499076f9c151cdbd5db783e87fea5 (diff) | |
parent | 9377bef7e0c0abae2ca0f7638662dc61c89fbc31 (diff) | |
download | trackermap-server-ee8beb01019f381eae09fb94e249e3d5b9312bbb.tar.gz trackermap-server-ee8beb01019f381eae09fb94e249e3d5b9312bbb.tar.bz2 trackermap-server-ee8beb01019f381eae09fb94e249e3d5b9312bbb.zip |
Merge pull request #2269 from Abyss777/reports_web_configure
Implemented configure dialog for reports
-rw-r--r-- | web/app/Application.js | 3 | ||||
-rw-r--r-- | web/app/Style.js | 3 | ||||
-rw-r--r-- | web/app/controller/Root.js | 3 | ||||
-rw-r--r-- | web/app/store/ReportEventTypes.js | 25 | ||||
-rw-r--r-- | web/app/view/AttributesController.js | 3 | ||||
-rw-r--r-- | web/app/view/DevicesController.js | 5 | ||||
-rw-r--r-- | web/app/view/GeofencesController.js | 2 | ||||
-rw-r--r-- | web/app/view/GroupsController.js | 4 | ||||
-rw-r--r-- | web/app/view/NotificationsController.js | 4 | ||||
-rw-r--r-- | web/app/view/Report.js | 46 | ||||
-rw-r--r-- | web/app/view/ReportConfigController.js | 69 | ||||
-rw-r--r-- | web/app/view/ReportConfigDialog.js | 98 | ||||
-rw-r--r-- | web/app/view/ReportController.js | 82 | ||||
-rw-r--r-- | web/app/view/StateController.js | 5 | ||||
-rw-r--r-- | web/app/view/UsersController.js | 3 | ||||
-rw-r--r-- | web/l10n/en.json | 4 |
16 files changed, 287 insertions, 72 deletions
diff --git a/web/app/Application.js b/web/app/Application.js index da28070e6..2d806534e 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -63,7 +63,8 @@ Ext.define('Traccar.Application', { 'ReportEvents', 'ReportTrips', 'ReportSummary', - 'ReportTypes' + 'ReportTypes', + 'ReportEventTypes' ], controllers: [ diff --git a/web/app/Style.js b/web/app/Style.js index 349f3d7eb..b3b296b75 100644 --- a/web/app/Style.js +++ b/web/app/Style.js @@ -75,6 +75,5 @@ Ext.define('Traccar.Style', { coordinatePrecision: 6, numberPrecision: 2, - maxTagfieldWidth: 200, - maxTagfieldGrow: 1 + reportTagfieldWidth: 375 }); diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index 9ca7c9e40..dc759a08b 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -20,7 +20,8 @@ Ext.define('Traccar.controller.Root', { requires: [ 'Traccar.view.Login', 'Traccar.view.Main', - 'Traccar.view.MainMobile' + 'Traccar.view.MainMobile', + 'Traccar.model.Position' ], init: function () { diff --git a/web/app/store/ReportEventTypes.js b/web/app/store/ReportEventTypes.js new file mode 100644 index 000000000..27bc1fd5d --- /dev/null +++ b/web/app/store/ReportEventTypes.js @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.store.ReportEventTypes', { + extend: 'Ext.data.Store', + fields: ['type', 'name'], + + statics: { + allEvents: '%' + } +}); diff --git a/web/app/view/AttributesController.js b/web/app/view/AttributesController.js index 5be94dec3..91d69a8e2 100644 --- a/web/app/view/AttributesController.js +++ b/web/app/view/AttributesController.js @@ -20,7 +20,8 @@ Ext.define('Traccar.view.AttributesController', { requires: [ 'Traccar.view.AttributeDialog', - 'Traccar.store.Attributes' + 'Traccar.store.Attributes', + 'Traccar.model.Attribute' ], init: function () { diff --git a/web/app/view/DevicesController.js b/web/app/view/DevicesController.js index 8058db376..17f98629f 100644 --- a/web/app/view/DevicesController.js +++ b/web/app/view/DevicesController.js @@ -21,7 +21,10 @@ Ext.define('Traccar.view.DevicesController', { requires: [ 'Traccar.view.CommandDialog', 'Traccar.view.DeviceDialog', - 'Traccar.view.DeviceGeofences' + 'Traccar.view.DeviceGeofences', + 'Traccar.view.BaseWindow', + 'Traccar.model.Device', + 'Traccar.model.Command' ], config: { diff --git a/web/app/view/GeofencesController.js b/web/app/view/GeofencesController.js index 59e416d56..5faee139f 100644 --- a/web/app/view/GeofencesController.js +++ b/web/app/view/GeofencesController.js @@ -20,7 +20,7 @@ Ext.define('Traccar.view.GeofencesController', { requires: [ 'Traccar.view.GeofenceDialog', - 'Traccar.view.BaseWindow' + 'Traccar.model.Geofence' ], init: function () { diff --git a/web/app/view/GroupsController.js b/web/app/view/GroupsController.js index 7413f64a8..f1d6e53f3 100644 --- a/web/app/view/GroupsController.js +++ b/web/app/view/GroupsController.js @@ -20,7 +20,9 @@ Ext.define('Traccar.view.GroupsController', { requires: [ 'Traccar.view.GroupDialog', - 'Traccar.view.GroupGeofences' + 'Traccar.view.GroupGeofences', + 'Traccar.view.BaseWindow', + 'Traccar.model.Group' ], onAddClick: function () { diff --git a/web/app/view/NotificationsController.js b/web/app/view/NotificationsController.js index 628343a84..d880c5d41 100644 --- a/web/app/view/NotificationsController.js +++ b/web/app/view/NotificationsController.js @@ -18,6 +18,10 @@ Ext.define('Traccar.view.NotificationsController', { extend: 'Ext.app.ViewController', alias: 'controller.notificationsController', + requires: [ + 'Traccar.store.Notifications' + ], + init: function () { this.userId = this.getView().user.getData().id; this.getView().getStore().load({ diff --git a/web/app/view/Report.js b/web/app/view/Report.js index 2ce9137ee..7e77ef4f4 100644 --- a/web/app/view/Report.js +++ b/web/app/view/Report.js @@ -19,8 +19,7 @@ Ext.define('Traccar.view.Report', { xtype: 'reportView', requires: [ - 'Traccar.view.ReportController', - 'Traccar.view.CustomTimeField' + 'Traccar.view.ReportController' ], controller: 'report', @@ -41,52 +40,17 @@ Ext.define('Traccar.view.Report', { change: 'onTypeChange' } }, '-', { - xtype: 'tbtext', - html: Strings.reportDevice - }, { - xtype: 'tagfield', - maxWidth: Traccar.Style.maxTagfieldWidth, - growMax: Traccar.Style.maxTagfieldGrow, - reference: 'deviceField', - store: 'Devices', - valueField: 'id', - displayField: 'name', - queryMode: 'local' - }, '-', { - xtype: 'tbtext', - html: Strings.reportFrom - }, { - xtype: 'datefield', - reference: 'fromDateField', - startDay: Traccar.Style.weekStartDay, - format: Traccar.Style.dateFormat, - value: new Date(new Date().getTime() - 30 * 60 * 1000) - }, { - xtype: 'customTimeField', - reference: 'fromTimeField', - maxWidth: Traccar.Style.reportTime, - value: new Date(new Date().getTime() - 30 * 60 * 1000) - }, '-', { - xtype: 'tbtext', - html: Strings.reportTo - }, { - xtype: 'datefield', - reference: 'toDateField', - startDay: Traccar.Style.weekStartDay, - format: Traccar.Style.dateFormat, - value: new Date() - }, { - xtype: 'customTimeField', - reference: 'toTimeField', - maxWidth: Traccar.Style.reportTime, - value: new Date() + text: Strings.reportConfigure, + handler: 'onConfigureClick' }, '-', { text: Strings.reportShow, reference: 'showButton', + disabled: true, handler: 'onReportClick' }, { text: Strings.reportCsv, reference: 'csvButton', + disabled: true, handler: 'onReportClick' }, { text: Strings.reportClear, diff --git a/web/app/view/ReportConfigController.js b/web/app/view/ReportConfigController.js new file mode 100644 index 000000000..df0c1ce4a --- /dev/null +++ b/web/app/view/ReportConfigController.js @@ -0,0 +1,69 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.view.ReportConfigController', { + extend: 'Ext.app.ViewController', + alias: 'controller.reportConfigDialog', + + requires: [ + 'Traccar.store.ReportEventTypes', + 'Traccar.store.AllNotifications' + ], + + init: function () { + var store = this.lookupReference('eventTypeField').getStore(); + if (store.getCount() === 0) { + store.add({ + type: Traccar.store.ReportEventTypes.allEvents, + name: Strings.eventAll + }); + Ext.create('Traccar.store.AllNotifications').load({ + scope: this, + callback: function (records, operation, success) { + var i, value, name, typeKey; + if (success) { + for (i = 0; i < records.length; i++) { + value = records[i].get('type'); + typeKey = 'event' + value.charAt(0).toUpperCase() + value.slice(1); + name = Strings[typeKey]; + store.add({type: value, name: name}); + } + } + } + }); + } + }, + + onSaveClick: function (button) { + var eventType; + this.getView().callingPanel.deviceId = this.lookupReference('deviceField').getValue(); + this.getView().callingPanel.groupId = this.lookupReference('groupField').getValue(); + eventType = this.lookupReference('eventTypeField').getValue(); + if (eventType.indexOf(Traccar.store.ReportEventTypes.allEvents) > -1) { + eventType = [Traccar.store.ReportEventTypes.allEvents]; + } else if (eventType.length === this.lookupReference('eventTypeField').getStore().getCount() - 1) { + eventType = [Traccar.store.ReportEventTypes.allEvents]; + } + this.getView().callingPanel.eventType = eventType; + this.getView().callingPanel.fromDate = this.lookupReference('fromDateField').getValue(); + this.getView().callingPanel.fromTime = this.lookupReference('fromTimeField').getValue(); + this.getView().callingPanel.toDate = this.lookupReference('toDateField').getValue(); + this.getView().callingPanel.toTime = this.lookupReference('toTimeField').getValue(); + this.getView().callingPanel.updateButtons(); + button.up('window').close(); + } +}); diff --git a/web/app/view/ReportConfigDialog.js b/web/app/view/ReportConfigDialog.js new file mode 100644 index 000000000..547bd2975 --- /dev/null +++ b/web/app/view/ReportConfigDialog.js @@ -0,0 +1,98 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.view.ReportConfigDialog', { + extend: 'Traccar.view.BaseDialog', + + requires: [ + 'Traccar.view.ReportConfigController', + 'Traccar.view.CustomTimeField' + ], + + controller: 'reportConfigDialog', + title: Strings.reportConfigure, + + items: [{ + fieldLabel: Strings.reportDevice, + xtype: 'tagfield', + width: Traccar.Style.reportTagfieldWidth, + reference: 'deviceField', + store: 'Devices', + valueField: 'id', + displayField: 'name', + queryMode: 'local' + }, { + fieldLabel: Strings.reportGroup, + xtype: 'tagfield', + width: Traccar.Style.reportTagfieldWidth, + reference: 'groupField', + store: 'Groups', + valueField: 'id', + displayField: 'name', + queryMode: 'local' + }, { + fieldLabel: Strings.reportEventTypes, + xtype: 'tagfield', + width: Traccar.Style.reportTagfieldWidth, + reference: 'eventTypeField', + store: 'ReportEventTypes', + hidden: true, + valueField: 'type', + displayField: 'name', + queryMode: 'local' + }, { + xtype: 'fieldcontainer', + layout: 'hbox', + items: [{ + xtype: 'datefield', + fieldLabel: Strings.reportFrom, + reference: 'fromDateField', + startDay: Traccar.Style.weekStartDay, + format: Traccar.Style.dateFormat, + value: new Date(new Date().getTime() - 30 * 60 * 1000) + }, { + xtype: 'customTimeField', + reference: 'fromTimeField', + maxWidth: Traccar.Style.reportTime, + value: new Date(new Date().getTime() - 30 * 60 * 1000) + }] + }, { + xtype: 'fieldcontainer', + layout: 'hbox', + items: [{ + xtype: 'datefield', + fieldLabel: Strings.reportTo, + reference: 'toDateField', + startDay: Traccar.Style.weekStartDay, + format: Traccar.Style.dateFormat, + value: new Date() + }, { + xtype: 'customTimeField', + reference: 'toTimeField', + maxWidth: Traccar.Style.reportTime, + value: new Date() + }] + }], + + buttons: [{ + text: Strings.sharedSave, + handler: 'onSaveClick' + }, { + text: Strings.sharedCancel, + handler: 'closeView' + }] +}); diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js index aeaa1849e..3a3345d83 100644 --- a/web/app/view/ReportController.js +++ b/web/app/view/ReportController.js @@ -19,6 +19,12 @@ Ext.define('Traccar.view.ReportController', { extend: 'Ext.app.ViewController', alias: 'controller.report', + requires: [ + 'Traccar.AttributeFormatter', + 'Traccar.view.ReportConfigDialog', + 'Traccar.store.ReportEventTypes' + ], + config: { listen: { controller: { @@ -30,43 +36,73 @@ Ext.define('Traccar.view.ReportController', { } }, - onReportClick: function (button) { - var reportType, deviceId, fromDate, fromTime, from, toDate, toTime, to, store, url; + onConfigureClick: function () { + var dialog = Ext.create('Traccar.view.ReportConfigDialog'); + dialog.lookupReference('eventTypeField').setHidden(this.lookupReference('reportTypeField').getValue() !== 'events'); + dialog.callingPanel = this; + dialog.lookupReference('deviceField').setValue(this.deviceId); + dialog.lookupReference('groupField').setValue(this.groupId); + if (this.eventType !== undefined) { + dialog.lookupReference('eventTypeField').setValue(this.eventType); + } else { + dialog.lookupReference('eventTypeField').setValue([Traccar.store.ReportEventTypes.allEvents]); + } + if (this.fromDate !== undefined) { + dialog.lookupReference('fromDateField').setValue(this.fromDate); + } + if (this.fromTime !== undefined) { + dialog.lookupReference('fromTimeField').setValue(this.fromTime); + } + if (this.toDate !== undefined) { + dialog.lookupReference('toDateField').setValue(this.toDate); + } + if (this.toTime !== undefined) { + dialog.lookupReference('toTimeField').setValue(this.toTime); + } + dialog.show(); + }, + updateButtons: function () { + var reportType, disabled, devices, time; reportType = this.lookupReference('reportTypeField').getValue(); + devices = (this.deviceId && this.deviceId.length !== 0) || (this.groupId && this.groupId.length !== 0); + time = this.fromDate && this.fromTime && this.toDate && this.toTime; + disabled = !reportType || !devices || !time; + this.lookupReference('showButton').setDisabled(disabled); + this.lookupReference('csvButton').setDisabled(disabled); + }, - deviceId = this.lookupReference('deviceField').getValue(); + onReportClick: function (button) { + var reportType, from, to, store, url; - fromDate = this.lookupReference('fromDateField').getValue(); - fromTime = this.lookupReference('fromTimeField').getValue(); + reportType = this.lookupReference('reportTypeField').getValue(); - if (reportType && deviceId) { + if (reportType && (this.deviceId || this.groupId)) { from = new Date( - fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDate(), - fromTime.getHours(), fromTime.getMinutes(), fromTime.getSeconds(), fromTime.getMilliseconds()); - - toDate = this.lookupReference('toDateField').getValue(); - toTime = this.lookupReference('toTimeField').getValue(); + this.fromDate.getFullYear(), this.fromDate.getMonth(), this.fromDate.getDate(), + this.fromTime.getHours(), this.fromTime.getMinutes(), this.fromTime.getSeconds(), this.fromTime.getMilliseconds()); to = new Date( - toDate.getFullYear(), toDate.getMonth(), toDate.getDate(), - toTime.getHours(), toTime.getMinutes(), toTime.getSeconds(), toTime.getMilliseconds()); + this.toDate.getFullYear(), this.toDate.getMonth(), this.toDate.getDate(), + this.toTime.getHours(), this.toTime.getMinutes(), this.toTime.getSeconds(), this.toTime.getMilliseconds()); - if (button.reference === "showButton") { + if (button.reference === 'showButton') { store = this.getView().getStore(); store.load({ params: { - deviceId: deviceId, - type: '%', + deviceId: this.deviceId, + groupId: this.groupId, + type: this.eventType, from: from.toISOString(), to: to.toISOString() } }); - } else if (button.reference === "csvButton") { + } else if (button.reference === 'csvButton') { url = this.getView().getStore().getProxy().url; this.downloadCsv(url, { - deviceId: deviceId, - type: '%', + deviceId: this.deviceId, + groupId: this.groupId, + type: this.eventType, from: from.toISOString(), to: to.toISOString() }); @@ -107,9 +143,9 @@ Ext.define('Traccar.view.ReportController', { success: function (response) { var disposition, filename, type, blob, url, downloadUrl, elementA; disposition = response.getResponseHeader('Content-Disposition'); - filename = disposition.slice(disposition.indexOf("=") + 1, disposition.length); + filename = disposition.slice(disposition.indexOf('=') + 1, disposition.length); type = response.getResponseHeader('Content-Type'); - blob = new Blob([response.responseText], { type: type }); + blob = new Blob([response.responseText], {type: type}); if (typeof window.navigator.msSaveBlob !== 'undefined') { // IE workaround window.navigator.msSaveBlob(blob, filename); @@ -117,7 +153,7 @@ Ext.define('Traccar.view.ReportController', { url = window.URL || window.webkitURL; downloadUrl = url.createObjectURL(blob); if (filename) { - elementA = document.createElement("a"); + elementA = document.createElement('a'); elementA.href = downloadUrl; elementA.download = filename; document.body.appendChild(elementA); @@ -300,6 +336,8 @@ Ext.define('Traccar.view.ReportController', { } else if (newValue === 'trips') { this.getView().reconfigure('ReportTrips', tripsColumns); } + + this.updateButtons(); } }); diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js index 01df6645d..567a3925d 100644 --- a/web/app/view/StateController.js +++ b/web/app/view/StateController.js @@ -18,6 +18,11 @@ Ext.define('Traccar.view.StateController', { extend: 'Ext.app.ViewController', alias: 'controller.state', + requires: [ + 'Traccar.AttributeFormatter', + 'Traccar.model.Attribute' + ], + config: { listen: { controller: { diff --git a/web/app/view/UsersController.js b/web/app/view/UsersController.js index 73088a40e..da7dd8f13 100644 --- a/web/app/view/UsersController.js +++ b/web/app/view/UsersController.js @@ -24,7 +24,8 @@ Ext.define('Traccar.view.UsersController', { 'Traccar.view.UserGroups', 'Traccar.view.UserGeofences', 'Traccar.view.Notifications', - 'Traccar.view.BaseWindow' + 'Traccar.view.BaseWindow', + 'Traccar.model.User' ], init: function () { diff --git a/web/l10n/en.json b/web/l10n/en.json index c662cd47c..c4a130cf0 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -61,6 +61,7 @@ "settingsTwelveHourFormat": "12-hour Format", "reportTitle": "Reports", "reportDevice": "Device", + "reportGroup": "Group", "reportFrom": "From", "reportTo": "To", "reportShow": "Show", @@ -119,6 +120,7 @@ "commandData": "Data", "commandPhoneNumber": "Phone Number", "commandMessage": "Message", + "eventAll": "All Events", "eventDeviceOnline": "Device is online", "eventDeviceOffline": "Device is offline", "eventDeviceMoving": "Device is moving", @@ -145,6 +147,8 @@ "reportEvents": "Events", "reportTrips": "Trips", "reportSummary": "Summary", + "reportConfigure": "Configure", + "reportEventTypes": "Event Types", "reportCsv": "CSV", "reportDeviceName": "Device Name", "reportAverageSpeed": "Average Speed", |