From df9b799cbfd51c24158bb16ca5b37105a390a5d3 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 6 Oct 2017 09:34:00 +0500 Subject: Add quick period selector to Report Config dialog --- web/app/Application.js | 1 + web/app/store/ReportPeriods.js | 36 +++++++++++++++++++++++++++ web/app/view/dialog/ReportConfig.js | 11 ++++++++ web/app/view/dialog/ReportConfigController.js | 30 ++++++++++++++++++++++ web/l10n/en.json | 5 ++++ 5 files changed, 83 insertions(+) create mode 100644 web/app/store/ReportPeriods.js diff --git a/web/app/Application.js b/web/app/Application.js index ed9a4b60..6338506c 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -76,6 +76,7 @@ Ext.define('Traccar.Application', { 'ReportTypes', 'ReportEventTypes', 'ReportChartTypes', + 'ReportPeriods', 'Statistics', 'DeviceImages', 'Calendars', diff --git a/web/app/store/ReportPeriods.js b/web/app/store/ReportPeriods.js new file mode 100644 index 00000000..b9c19f93 --- /dev/null +++ b/web/app/store/ReportPeriods.js @@ -0,0 +1,36 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2017 Andrey Kunitsyn (andrey@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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +Ext.define('Traccar.store.ReportPeriods', { + extend: 'Ext.data.Store', + fields: ['key', 'name'], + + data: [{ + key: 'today', + name: Strings.reportToday + }, { + key: 'yesterday', + name: Strings.reportYesterday + }, { + key: 'thisWeek', + name: Strings.reportThisWeek + }, { + key: 'thisMonth', + name: Strings.reportThisMonth + }] +}); diff --git a/web/app/view/dialog/ReportConfig.js b/web/app/view/dialog/ReportConfig.js index 836b6050..cdf11e1c 100644 --- a/web/app/view/dialog/ReportConfig.js +++ b/web/app/view/dialog/ReportConfig.js @@ -102,6 +102,17 @@ Ext.define('Traccar.view.dialog.ReportConfig', { reference: 'toTimeField', value: new Date() }] + }, { + fieldLabel: Strings.reportPeriod, + xtype: 'combobox', + store: 'ReportPeriods', + editable: false, + valueField: 'key', + displayField: 'name', + queryMode: 'local', + listeners: { + change: 'onPeriodChange' + } }], buttons: [{ diff --git a/web/app/view/dialog/ReportConfigController.js b/web/app/view/dialog/ReportConfigController.js index ce66371b..2958515e 100644 --- a/web/app/view/dialog/ReportConfigController.js +++ b/web/app/view/dialog/ReportConfigController.js @@ -46,5 +46,35 @@ Ext.define('Traccar.view.dialog.ReportConfigController', { callingPanel.toTime = this.lookupReference('toTimeField').getValue(); callingPanel.updateButtons(); button.up('window').close(); + }, + + onPeriodChange: function (combobox, newValue) { + var day, first, from = new Date(), to = new Date(); + switch (newValue) { + case 'today': + to.setDate(to.getDate() + 1); + break; + case 'yesterday': + from.setDate(to.getDate() - 1); + break; + case 'thisWeek': + day = from.getDay(); + first = from.getDate() - day + (day === 0 ? -6 : 1); + from.setDate(first); + to.setDate(first + 7); + break; + case 'thisMonth': + from.setDate(1); + to.setDate(1); + to.setMonth(from.getMonth() + 1); + break; + default: + } + from.setHours(0, 0, 0, 0); + to.setHours(0, 0, 0, 0); + this.lookupReference('fromDateField').setValue(from); + this.lookupReference('fromTimeField').setValue(from); + this.lookupReference('toDateField').setValue(to); + this.lookupReference('toTimeField').setValue(to); } }); diff --git a/web/l10n/en.json b/web/l10n/en.json index c5acc496..c215a9b9 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -358,6 +358,11 @@ "reportChartType": "Chart Type", "reportShowMarkers": "Show Markers", "reportExport": "Export", + "reportPeriod": "Period", + "reportToday": "Today", + "reportYesterday": "Yesterday", + "reportThisWeek": "This Week", + "reportThisMonth": "This Month", "reportDeviceName": "Device Name", "reportAverageSpeed": "Average Speed", "reportMaximumSpeed": "Maximum Speed", -- cgit v1.2.3