diff options
author | Stefan Giehl <stefan@matomo.org> | 2020-12-17 06:36:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-17 06:36:45 +0300 |
commit | 9e6094647e7151ba00e34ae234d4f6890ab52c2e (patch) | |
tree | 3c22529e0218fd6ff43725da25a24f4b01ee41a1 /plugins/CoreHome/angularjs/common | |
parent | 4a241a72c52ebb54df3f9fa92e6fb392d22c4cd8 (diff) |
Show an error notification in UI when given date/period combination is invalid (#16840)
* Show an error notification in UI when given date/period combination is invalid
* Adds UI test
* unify usage of date/period params from url/hash
* updates ui screenshots changed due to the lastindexof change
* use indexOf when searching for multiple values
* updates submodule
* Fix broadcast.getParamValue
* remove debug code
* Adds some simple tests
* improve ui test
* do not url decode as it breaks segmentation tests
Diffstat (limited to 'plugins/CoreHome/angularjs/common')
-rw-r--r-- | plugins/CoreHome/angularjs/common/services/piwik-url.js | 12 | ||||
-rw-r--r-- | plugins/CoreHome/angularjs/common/services/piwik.js | 10 |
2 files changed, 14 insertions, 8 deletions
diff --git a/plugins/CoreHome/angularjs/common/services/piwik-url.js b/plugins/CoreHome/angularjs/common/services/piwik-url.js index 4357a280ff..3743bf0d62 100644 --- a/plugins/CoreHome/angularjs/common/services/piwik-url.js +++ b/plugins/CoreHome/angularjs/common/services/piwik-url.js @@ -7,12 +7,12 @@ (function () { angular.module('piwikApp.service').service('piwikUrl', piwikUrl); - piwikUrl.$inject = ['$location', 'piwik', '$window']; + piwikUrl.$inject = ['$location', '$window']; /** * Similar to angulars $location but works around some limitation. Use it if you need to access search params */ - function piwikUrl($location, piwik, $window) { + function piwikUrl($location, $window) { var model = { getSearchParam: getSearchParam @@ -24,7 +24,13 @@ { var hash = $window.location.href.split('#'); if (hash && hash[1] && (new RegExp(paramName + '(\\[]|=)')).test(decodeURIComponent(hash[1]))) { - return broadcast.getValueFromHash(paramName, $window.location.href); + var valueFromHash = broadcast.getValueFromHash(paramName, $window.location.href); + + // for date, period and idsite fall back to parameter from url, if non in hash was provided + if (valueFromHash || (paramName !== 'date' && paramName !== 'period' && paramName !== 'idSite')) { + return valueFromHash; + } + } return broadcast.getValueFromUrl(paramName, $window.location.search); } diff --git a/plugins/CoreHome/angularjs/common/services/piwik.js b/plugins/CoreHome/angularjs/common/services/piwik.js index 3c0f79e400..92a82bac2e 100644 --- a/plugins/CoreHome/angularjs/common/services/piwik.js +++ b/plugins/CoreHome/angularjs/common/services/piwik.js @@ -7,9 +7,9 @@ (function () { angular.module('piwikApp.service').service('piwik', piwikService); - piwikService.$inject = ['piwikPeriods']; + piwikService.$inject = ['piwikPeriods', 'piwikUrl']; - function piwikService(piwikPeriods) { + function piwikService(piwikPeriods, piwikUrl) { var originalTitle; piwik.helper = piwikHelper; piwik.broadcast = broadcast; @@ -23,8 +23,8 @@ } function updatePeriodParamsFromUrl() { - var date = piwik.broadcast.getValueFromHash('date') || piwik.broadcast.getValueFromUrl('date'); - var period = piwik.broadcast.getValueFromHash('period') || piwik.broadcast.getValueFromUrl('period'); + var date = piwikUrl.getSearchParam('date'); + var period = piwikUrl.getSearchParam('period'); if (!isValidPeriod(period, date)) { // invalid data in URL return; @@ -54,7 +54,7 @@ function isValidPeriod(periodStr, dateStr) { try { - piwikPeriods.get(periodStr).parse(dateStr); + piwikPeriods.parse(periodStr, dateStr); return true; } catch (e) { return false; |