diff --git a/back/methods/campaign/latest.js b/back/methods/campaign/latest.js index f1449dfec..20dda8a26 100644 --- a/back/methods/campaign/latest.js +++ b/back/methods/campaign/latest.js @@ -24,8 +24,6 @@ module.exports = Self => { const conn = Self.dataSource.connector; const minDate = new Date(); minDate.setFullYear(minDate.getFullYear() - 1); - minDate.setMonth(0); - minDate.setDate(1); const where = {dated: {gte: minDate}}; filter = mergeFilters(filter, {where}); diff --git a/modules/client/front/consumption-search-panel/index.html b/modules/client/front/consumption-search-panel/index.html index f8d633c71..fbcf24fad 100644 --- a/modules/client/front/consumption-search-panel/index.html +++ b/modules/client/front/consumption-search-panel/index.html @@ -69,12 +69,14 @@ + ng-model="filter.from" + on-change="$ctrl.onChangeDate(value)"> + ng-model="filter.to" + on-change="$ctrl.onChangeDate(value)"> diff --git a/modules/client/front/consumption-search-panel/index.js b/modules/client/front/consumption-search-panel/index.js index 099564efc..465d24afd 100644 --- a/modules/client/front/consumption-search-panel/index.js +++ b/modules/client/front/consumption-search-panel/index.js @@ -5,16 +5,34 @@ class Controller extends SearchPanel { constructor($, $element) { super($, $element); - this.getUpcomingCampaing(); + this.filter = this.$.filter; + + if (!this.dateParams) + this.getUpcomingCampaing(); + } + + get dateParams() { + if (this.$params.q) { + const params = JSON.parse(this.$params.q); + + if (params.from || params.to) + return true; + } + + return false; } getUpcomingCampaing() { this.$http.get('Campaigns/upcoming').then(res => { - const filter = this.$.filter; - filter.campaign = res.data.id; + this.filter.campaign = res.data.id; }); } + onChangeDate(value) { + if (value) + this.filter.campaign = null; + } + get campaignSelection() { return this._campaignSelection; } @@ -22,14 +40,13 @@ class Controller extends SearchPanel { set campaignSelection(value) { this._campaignSelection = value; - if (!value) return; + if (value) { + const from = new Date(value.dated); + from.setDate(from.getDate() - value.scopeDays); - const filter = this.$.filter; - const from = new Date(value.dated); - from.setDate(from.getDate() - value.scopeDays); - - filter.to = value.dated; - filter.from = from; + this.filter.to = value.dated; + this.filter.from = from; + } } } diff --git a/modules/client/front/consumption/index.js b/modules/client/front/consumption/index.js index e36e94682..af08a8871 100644 --- a/modules/client/front/consumption/index.js +++ b/modules/client/front/consumption/index.js @@ -13,6 +13,10 @@ class Controller extends Section { } }; + this.setDefaultFilter(); + } + + setDefaultFilter() { const minDate = new Date(); minDate.setHours(0, 0, 0, 0); minDate.setMonth(minDate.getMonth() - 2);