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/view/dialog/ReportConfig.js | 11 ++++++++++ web/app/view/dialog/ReportConfigController.js | 30 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'web/app/view/dialog') 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); } }); -- cgit v1.2.3 From 45e76cdd0fd2ad2d29cb7cfce17bcf543d96fd60 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 6 Oct 2017 12:53:13 +0500 Subject: Hide date selectors for predefined periods --- web/app/store/ReportPeriods.js | 9 +++++++++ web/app/view/ReportController.js | 3 +++ web/app/view/dialog/ReportConfig.js | 5 +++++ web/app/view/dialog/ReportConfigController.js | 18 ++++++++++++++++++ web/l10n/en.json | 3 +++ 5 files changed, 38 insertions(+) (limited to 'web/app/view/dialog') diff --git a/web/app/store/ReportPeriods.js b/web/app/store/ReportPeriods.js index b9c19f93..542fdce9 100644 --- a/web/app/store/ReportPeriods.js +++ b/web/app/store/ReportPeriods.js @@ -21,6 +21,9 @@ Ext.define('Traccar.store.ReportPeriods', { fields: ['key', 'name'], data: [{ + key: 'custom', + name: Strings.reportCustom + }, { key: 'today', name: Strings.reportToday }, { @@ -29,8 +32,14 @@ Ext.define('Traccar.store.ReportPeriods', { }, { key: 'thisWeek', name: Strings.reportThisWeek + }, { + key: 'previousWeek', + name: Strings.reportPreviousWeek }, { key: 'thisMonth', name: Strings.reportThisMonth + }, { + key: 'previousMonth', + name: Strings.reportPreviousMonth }] }); diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js index 6d984de7..80e56ba4 100644 --- a/web/app/view/ReportController.js +++ b/web/app/view/ReportController.js @@ -128,6 +128,9 @@ Ext.define('Traccar.view.ReportController', { if (this.toTime !== undefined) { dialog.lookupReference('toTimeField').setValue(this.toTime); } + if (this.period !== undefined) { + dialog.lookupReference('periodField').setValue(this.period); + } dialog.show(); }, diff --git a/web/app/view/dialog/ReportConfig.js b/web/app/view/dialog/ReportConfig.js index cdf11e1c..67080bf5 100644 --- a/web/app/view/dialog/ReportConfig.js +++ b/web/app/view/dialog/ReportConfig.js @@ -75,6 +75,8 @@ Ext.define('Traccar.view.dialog.ReportConfig', { }, { xtype: 'fieldcontainer', layout: 'vbox', + reference: 'fromContainer', + hidden: true, fieldLabel: Strings.reportFrom, items: [{ xtype: 'datefield', @@ -90,6 +92,8 @@ Ext.define('Traccar.view.dialog.ReportConfig', { }, { xtype: 'fieldcontainer', layout: 'vbox', + reference: 'toContainer', + hidden: true, fieldLabel: Strings.reportTo, items: [{ xtype: 'datefield', @@ -104,6 +108,7 @@ Ext.define('Traccar.view.dialog.ReportConfig', { }] }, { fieldLabel: Strings.reportPeriod, + reference: 'periodField', xtype: 'combobox', store: 'ReportPeriods', editable: false, diff --git a/web/app/view/dialog/ReportConfigController.js b/web/app/view/dialog/ReportConfigController.js index 2958515e..17699b98 100644 --- a/web/app/view/dialog/ReportConfigController.js +++ b/web/app/view/dialog/ReportConfigController.js @@ -44,6 +44,7 @@ Ext.define('Traccar.view.dialog.ReportConfigController', { callingPanel.fromTime = this.lookupReference('fromTimeField').getValue(); callingPanel.toDate = this.lookupReference('toDateField').getValue(); callingPanel.toTime = this.lookupReference('toTimeField').getValue(); + callingPanel.period = this.lookupReference('periodField').getValue(); callingPanel.updateButtons(); button.up('window').close(); }, @@ -51,6 +52,10 @@ Ext.define('Traccar.view.dialog.ReportConfigController', { onPeriodChange: function (combobox, newValue) { var day, first, from = new Date(), to = new Date(); switch (newValue) { + case 'custom': + this.lookupReference('fromContainer').setHidden(false); + this.lookupReference('toContainer').setHidden(false); + return; case 'today': to.setDate(to.getDate() + 1); break; @@ -63,11 +68,22 @@ Ext.define('Traccar.view.dialog.ReportConfigController', { from.setDate(first); to.setDate(first + 7); break; + case 'previousWeek': + day = from.getDay(); + first = from.getDate() - day + (day === 0 ? -6 : 1); + from.setDate(first - 7); + to.setDate(first); + break; case 'thisMonth': from.setDate(1); to.setDate(1); to.setMonth(from.getMonth() + 1); break; + case 'previousMonth': + from.setDate(1); + from.setMonth(from.getMonth() - 1); + to.setDate(1); + break; default: } from.setHours(0, 0, 0, 0); @@ -76,5 +92,7 @@ Ext.define('Traccar.view.dialog.ReportConfigController', { this.lookupReference('fromTimeField').setValue(from); this.lookupReference('toDateField').setValue(to); this.lookupReference('toTimeField').setValue(to); + this.lookupReference('fromContainer').setHidden(true); + this.lookupReference('toContainer').setHidden(true); } }); diff --git a/web/l10n/en.json b/web/l10n/en.json index c215a9b9..4ef0d423 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -359,10 +359,13 @@ "reportShowMarkers": "Show Markers", "reportExport": "Export", "reportPeriod": "Period", + "reportCustom": "Custom", "reportToday": "Today", "reportYesterday": "Yesterday", "reportThisWeek": "This Week", + "reportPreviousWeek": "Previous Week", "reportThisMonth": "This Month", + "reportPreviousMonth": "Previous Month", "reportDeviceName": "Device Name", "reportAverageSpeed": "Average Speed", "reportMaximumSpeed": "Maximum Speed", -- cgit v1.2.3 From 8023ed43765dccafebcbb332ab320bc4fc4bb682 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 6 Oct 2017 14:58:59 +0500 Subject: Move period selector before from field --- web/app/view/dialog/ReportConfig.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'web/app/view/dialog') diff --git a/web/app/view/dialog/ReportConfig.js b/web/app/view/dialog/ReportConfig.js index 67080bf5..35cc95b4 100644 --- a/web/app/view/dialog/ReportConfig.js +++ b/web/app/view/dialog/ReportConfig.js @@ -72,6 +72,18 @@ Ext.define('Traccar.view.dialog.ReportConfig', { inputValue: true, uncheckedValue: false, value: false + }, { + fieldLabel: Strings.reportPeriod, + reference: 'periodField', + xtype: 'combobox', + store: 'ReportPeriods', + editable: false, + valueField: 'key', + displayField: 'name', + queryMode: 'local', + listeners: { + change: 'onPeriodChange' + } }, { xtype: 'fieldcontainer', layout: 'vbox', @@ -106,18 +118,6 @@ Ext.define('Traccar.view.dialog.ReportConfig', { reference: 'toTimeField', value: new Date() }] - }, { - fieldLabel: Strings.reportPeriod, - reference: 'periodField', - xtype: 'combobox', - store: 'ReportPeriods', - editable: false, - valueField: 'key', - displayField: 'name', - queryMode: 'local', - listeners: { - change: 'onPeriodChange' - } }], buttons: [{ -- cgit v1.2.3 From 8e4efa28702b6386dcfd20ba98fe8fa42b9682ed Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 6 Oct 2017 19:57:57 +0500 Subject: Optimize switch and conditions --- web/app/view/dialog/ReportConfigController.js | 87 ++++++++++++++------------- 1 file changed, 44 insertions(+), 43 deletions(-) (limited to 'web/app/view/dialog') diff --git a/web/app/view/dialog/ReportConfigController.js b/web/app/view/dialog/ReportConfigController.js index 17699b98..6d029428 100644 --- a/web/app/view/dialog/ReportConfigController.js +++ b/web/app/view/dialog/ReportConfigController.js @@ -50,49 +50,50 @@ Ext.define('Traccar.view.dialog.ReportConfigController', { }, onPeriodChange: function (combobox, newValue) { - var day, first, from = new Date(), to = new Date(); - switch (newValue) { - case 'custom': - this.lookupReference('fromContainer').setHidden(false); - this.lookupReference('toContainer').setHidden(false); - return; - 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 'previousWeek': - day = from.getDay(); - first = from.getDate() - day + (day === 0 ? -6 : 1); - from.setDate(first - 7); - to.setDate(first); - break; - case 'thisMonth': - from.setDate(1); - to.setDate(1); - to.setMonth(from.getMonth() + 1); - break; - case 'previousMonth': - from.setDate(1); - from.setMonth(from.getMonth() - 1); - to.setDate(1); - break; - default: + var day, first, from, to, custom = newValue === 'custom'; + this.lookupReference('fromContainer').setHidden(!custom); + this.lookupReference('toContainer').setHidden(!custom); + if (!custom) { + 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 'previousWeek': + day = from.getDay(); + first = from.getDate() - day + (day === 0 ? -6 : 1); + from.setDate(first - 7); + to.setDate(first); + break; + case 'thisMonth': + from.setDate(1); + to.setDate(1); + to.setMonth(from.getMonth() + 1); + break; + case 'previousMonth': + from.setDate(1); + from.setMonth(from.getMonth() - 1); + to.setDate(1); + break; + default: + break; + } + 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); } - 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); - this.lookupReference('fromContainer').setHidden(true); - this.lookupReference('toContainer').setHidden(true); } }); -- cgit v1.2.3