diff options
author | Zoltan Flamis <flamisz@gmail.com> | 2021-04-06 04:34:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-06 04:34:56 +0300 |
commit | 2c30dc8d231af58cdf2516a413da2d86bf7d62c6 (patch) | |
tree | 787340c73c6f91d8cdba670a1cf2744027c6213f /plugins/CoreHome/angularjs/common | |
parent | 1dbd619d202d3963a45e332280bef2d5997ba3e4 (diff) |
Show notification when there is raw data but no data (#17380)
* ajax calls to check raw data and nb_visits
* show notification if there is raw data only
* using piwikApi
* disable when segment selected and add do not fetch actions
* update segment check
* move the logic into reporting-page
* show on dashboard too
* limiting API requests
* using notification instead of alert
* check if period changed
* check only if today is in daterange
* use lang file for visitor log text
* add contains today method
* add UI test for the notification
* update ui test
* use range in ui test
Diffstat (limited to 'plugins/CoreHome/angularjs/common')
-rw-r--r-- | plugins/CoreHome/angularjs/common/services/periods.js | 36 | ||||
-rw-r--r-- | plugins/CoreHome/angularjs/common/services/periods.spec.js | 31 |
2 files changed, 66 insertions, 1 deletions
diff --git a/plugins/CoreHome/angularjs/common/services/periods.js b/plugins/CoreHome/angularjs/common/services/periods.js index 8033b33962..33c5e1abcd 100644 --- a/plugins/CoreHome/angularjs/common/services/periods.js +++ b/plugins/CoreHome/angularjs/common/services/periods.js @@ -26,6 +26,7 @@ * - **getDateRange()**: returns an array w/ two elements, the first being the start * Date of the period, the second being the end Date. The dates * must be Date objects, not strings, and are inclusive. + * - **containsToday()**: returns true if the date period contains today. False if not. * - (_static_) **parse(strDate)**: creates a new instance of this period from the * value of the 'date' query parameter. * - (_static_) **getDisplayText**: returns translated text for the period, eg, 'month', @@ -64,6 +65,10 @@ getDateRange: function () { return [new Date(this.dateInPeriod.getTime()), new Date(this.dateInPeriod.getTime())]; + }, + + containsToday: function () { + return todayIsInRange(this.getDateRange()); } }; @@ -99,6 +104,10 @@ endWeek.setDate(startWeek.getDate() + 6); return [startWeek, endWeek]; + }, + + containsToday: function () { + return todayIsInRange(this.getDateRange()); } }; @@ -131,6 +140,10 @@ endMonth.setDate(0); return [startMonth, endMonth]; + }, + + containsToday: function () { + return todayIsInRange(this.getDateRange()); } }; @@ -162,6 +175,10 @@ endYear.setDate(0); return [startYear, endYear]; + }, + + containsToday: function () { + return todayIsInRange(this.getDateRange()); } }; @@ -261,6 +278,10 @@ getDateRange: function () { return [this.startDate, this.endDate]; + }, + + containsToday: function () { + return todayIsInRange(this.getDateRange()); } }; @@ -275,7 +296,8 @@ parse: parse, parseDate: parseDate, format: format, - RangePeriod: RangePeriod + RangePeriod: RangePeriod, + todayIsInRange: todayIsInRange }; function getAllLabels() { @@ -384,4 +406,16 @@ date.setMilliseconds(0); return date; } + + function todayIsInRange(dateRange) { + if (!dateRange.isArray && dateRange.length !== 2) { + return false; + } + + if (getToday() >= dateRange[0] && getToday() <= dateRange[1]) { + return true; + } + + return false; + } })(); diff --git a/plugins/CoreHome/angularjs/common/services/periods.spec.js b/plugins/CoreHome/angularjs/common/services/periods.spec.js index 7fd0271b33..1ae3a52106 100644 --- a/plugins/CoreHome/angularjs/common/services/periods.spec.js +++ b/plugins/CoreHome/angularjs/common/services/periods.spec.js @@ -124,5 +124,36 @@ Date.now = originalDateNow; }); + + it('should contains today for daterange if it contains', function() { + var day = '2021-03-10'; + + originalDateNow = Date.now; + Date.now = function() { + return clearDate(day).getTime(); + }; + + var result = piwikPeriods.parse('week', day).containsToday(); + + expect(result).to.be.true; + + Date.now = originalDateNow; + }); + + it('should not contains today for daterange if it not contains', function() { + var today = '2021-03-10'; + var day = '2021-03-17'; + + originalDateNow = Date.now; + Date.now = function() { + return clearDate(today).getTime(); + }; + + var result = piwikPeriods.parse('week', day).containsToday(); + + expect(result).to.be.false; + + Date.now = originalDateNow; + }); }); })(); |