1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2025-04-05 00:27:25 +00:00

Add 'last 7 days' and 'last 30 days' to report date range dropdown

This commit is contained in:
downtownallday 2021-04-07 09:25:26 -04:00
parent 3be7ba7c86
commit 87cc106574
3 changed files with 22 additions and 3 deletions

View File

@ -207,6 +207,15 @@ class DateRange {
return DateRange.wtd().map(d => DateFormatter.ymd(d)); return DateRange.wtd().map(d => DateFormatter.ymd(d));
} }
static lastXdays(n) {
var s = new Date();
s.setTime(s.getTime() - (n * 24 * 60 * 60 * 1000));
return [ s, new Date() ];
}
static lastXdays_as_ymd(n) {
return DateRange.lastXdays(n).map(d => DateFormatter.ymd(d));
}
static rangeFromType(type) { static rangeFromType(type) {
if (type == 'wtd') if (type == 'wtd')
return DateRange.wtd(); return DateRange.wtd();
@ -214,6 +223,10 @@ class DateRange {
return DateRange.mtd(); return DateRange.mtd();
else if (type == 'ytd') else if (type == 'ytd')
return DateRange.ytd(); return DateRange.ytd();
else if (type == 'last30days')
return DateRange.lastXdays(30);
else if (type == 'last7days')
return DateRange.lastXdays(7)
return null; return null;
} }
}; };

View File

@ -12,7 +12,7 @@ Vue.component('date-range-picker', {
data: function() { data: function() {
var range_type = null; var range_type = null;
var range = null; var range = null;
var default_range_type = 'mtd'; var default_range_type = 'last30days';
const recall_id_prefix = 'date-range-picker/'; const recall_id_prefix = 'date-range-picker/';
var v = null; var v = null;
@ -59,6 +59,8 @@ Vue.component('date-range-picker', {
range: range, range: range,
range_type: range_type, range_type: range_type,
options: [ options: [
{ value:'last7days', text:'Last 7 days' },
{ value:'last30days', text:'Last 30 days' },
{ value:'wtd', text:'Week-to-date' }, { value:'wtd', text:'Week-to-date' },
{ value:'mtd', text:'Month-to-date' }, { value:'mtd', text:'Month-to-date' },
{ value:'ytd', text:'Year-to-date' }, { value:'ytd', text:'Year-to-date' },
@ -151,7 +153,11 @@ Vue.component('date-range-picker', {
range_type_change: function(evt) { range_type_change: function(evt) {
// ui select callback // ui select callback
if (this.range_type == 'wtd') if (this.range_type == 'last7days')
this.range = DateRange.lastXdays_as_ymd(7);
else if (this.range_type == 'last30days')
this.range = DateRange.lastXdays_as_ymd(30);
else if (this.range_type == 'wtd')
this.range = DateRange.wtd_as_ymd(); this.range = DateRange.wtd_as_ymd();
else if (this.range_type == 'mtd') else if (this.range_type == 'mtd')
this.range = DateRange.mtd_as_ymd(); this.range = DateRange.mtd_as_ymd();

View File

@ -11,7 +11,7 @@
</b-modal> </b-modal>
<div class="d-flex align-items-end"> <div class="d-flex align-items-end">
<date-range-picker ref="date_picker" :start_range="get_start_range($route, '-mtd')" recall_id="reports-main" @change="date_change($event)"></date-range-picker> <date-range-picker ref="date_picker" :start_range="get_start_range($route, '-last30days')" recall_id="reports-main" @change="date_change($event)"></date-range-picker>
<div class="ml-auto mr-1" title="Database stats" role="button" @click="$refs.stats.show()"><b-icon icon="server" scale="1.5" aria-label="Database stats" variant="primary"></b-icon><b-icon icon="info" scale="1.5"></b-icon></div> <div class="ml-auto mr-1" title="Database stats" role="button" @click="$refs.stats.show()"><b-icon icon="server" scale="1.5" aria-label="Database stats" variant="primary"></b-icon><b-icon icon="info" scale="1.5"></b-icon></div>
</div> </div>