diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2018-08-09 14:24:16 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2018-08-09 14:24:16 +0300 |
commit | 2b77bb4d609dd0ec377a9edc32536f22dd4dabb2 (patch) | |
tree | 14e38fd0b07b26dbcf50dd2e25793b556d45baa7 /plugins/CoreHome | |
parent | 6112cc2ddf955b9c7183ba767e0a8acce93111ef (diff) |
Add notification when report w/ segment has no data, but segment is unprocessed (#12823)3.6.0-b4
* When a report has no data, check if it is for an unprocessed segment and display an explanatory notification.
* Remove transient notifications on reporting page change, allow datatable views to add notifications, use to display unprocessed segment message.
* Update changelog.
* Internationalize unprocessed segment message.
* Parse notification divs in dashboardWidget.js when setting widget content.
* Tweak message.
* Change PR to use different approach: throw exception when no archives found and segment is used, then detect exception in new event.
* Update changelog + document new event.
* Unfinished review changes
* more review fixes
* Do not show notification w/ custom segments.
* apply pr review
* Apply review.
* undo escaping since it was not needed & get test to pass
* Different strategy + new test.
* Fix tests.
* Update two expected screenshots.
Diffstat (limited to 'plugins/CoreHome')
6 files changed, 70 insertions, 36 deletions
diff --git a/plugins/CoreHome/CoreHome.php b/plugins/CoreHome/CoreHome.php index 4499ee37b8..76e933ae51 100644 --- a/plugins/CoreHome/CoreHome.php +++ b/plugins/CoreHome/CoreHome.php @@ -167,7 +167,6 @@ class CoreHome extends \Piwik\Plugin $jsFiles[] = "libs/jqplot/jqplot-custom.min.js"; $jsFiles[] = "plugins/CoreHome/javascripts/color_manager.js"; $jsFiles[] = "plugins/CoreHome/javascripts/notification.js"; - $jsFiles[] = "plugins/CoreHome/javascripts/notification_parser.js"; $jsFiles[] = "plugins/CoreHome/javascripts/numberFormatter.js"; $jsFiles[] = "plugins/CoreHome/javascripts/zen-mode.js"; $jsFiles[] = "plugins/CoreHome/javascripts/noreferrer.js"; @@ -237,6 +236,7 @@ class CoreHome extends \Piwik\Plugin $jsFiles[] = "plugins/CoreHome/angularjs/notification/notification.controller.js"; $jsFiles[] = "plugins/CoreHome/angularjs/notification/notification.directive.js"; + $jsFiles[] = "plugins/CoreHome/angularjs/notification/notification.service.js"; $jsFiles[] = "plugins/CoreHome/angularjs/ajax-form/ajax-form.controller.js"; $jsFiles[] = "plugins/CoreHome/angularjs/ajax-form/ajax-form.directive.js"; diff --git a/plugins/CoreHome/angularjs/notification/notification.service.js b/plugins/CoreHome/angularjs/notification/notification.service.js new file mode 100644 index 0000000000..80e23d7a80 --- /dev/null +++ b/plugins/CoreHome/angularjs/notification/notification.service.js @@ -0,0 +1,53 @@ +/*! + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +(function () { + angular.module('piwikApp').factory('notifications', NotificationFactory); + + NotificationFactory.$inject = []; + + function NotificationFactory() { + + return { + parseNotificationDivs: parseNotificationDivs, + clearTransientNotifications: clearTransientNotifications, + }; + + function parseNotificationDivs() { + var UI = require('piwik/UI'); + + var $notificationNodes = $('[data-role="notification"]'); + + $notificationNodes.each(function (index, notificationNode) { + $notificationNode = $(notificationNode); + var attributes = $notificationNode.data(); + var message = $notificationNode.html(); + + if (message) { + var notification = new UI.Notification(); + attributes.animate = false; + notification.show(message, attributes); + } + + $notificationNodes.remove(); + }); + } + + function clearTransientNotifications() { + $('[piwik-notification][type=transient]').each(function () { + var $element = angular.element(this); + $element.scope().$destroy(); + $element.remove(); + }); + } + } + + angular.module('piwikApp').run(['notifications', function (notifications) { + $(function () { + notifications.parseNotificationDivs(); + }); + }]); +})(); diff --git a/plugins/CoreHome/angularjs/reporting-page/reportingpage.controller.js b/plugins/CoreHome/angularjs/reporting-page/reportingpage.controller.js index 606f30e334..a0d38ab1e7 100644 --- a/plugins/CoreHome/angularjs/reporting-page/reportingpage.controller.js +++ b/plugins/CoreHome/angularjs/reporting-page/reportingpage.controller.js @@ -7,9 +7,9 @@ (function () { angular.module('piwikApp').controller('ReportingPageController', ReportingPageController); - ReportingPageController.$inject = ['$scope', 'piwik', '$rootScope', '$location', 'reportingPageModel', 'reportingPagesModel']; + ReportingPageController.$inject = ['$scope', 'piwik', '$rootScope', '$location', 'reportingPageModel', 'reportingPagesModel', 'notifications']; - function ReportingPageController($scope, piwik, $rootScope, $location, pageModel, pagesModel) { + function ReportingPageController($scope, piwik, $rootScope, $location, pageModel, pagesModel, notifications) { pageModel.resetPage(); $scope.pageModel = pageModel; @@ -40,6 +40,8 @@ currentCategory = category; currentSubcategory = subcategory; + notifications.clearTransientNotifications(); + if (category === 'Dashboard_Dashboard' && $.isNumeric(subcategory) && $('[piwik-dashboard]').length) { // hack to make loading of dashboards faster since all the information is already there in the // piwik-dashboard widget, we can let the piwik-dashboard widget render the page. We need to find diff --git a/plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js b/plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js index c15eb97af6..c6d2326a58 100644 --- a/plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js +++ b/plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js @@ -19,9 +19,9 @@ (function () { angular.module('piwikApp').directive('piwikWidgetLoader', piwikWidgetLoader); - piwikWidgetLoader.$inject = ['piwik', 'piwikUrl', '$http', '$compile', '$q', '$location']; + piwikWidgetLoader.$inject = ['piwik', 'piwikUrl', '$http', '$compile', '$q', '$location', 'notifications']; - function piwikWidgetLoader(piwik, piwikUrl, $http, $compile, $q, $location){ + function piwikWidgetLoader(piwik, piwikUrl, $http, $compile, $q, $location, notifications){ return { restrict: 'A', transclude: true, @@ -147,6 +147,8 @@ } $compile(currentElement)(newScope); + + notifications.parseNotificationDivs(); })['catch'](function () { if (thisChangeId !== changeCounter) { // another widget was requested meanwhile, ignore this response diff --git a/plugins/CoreHome/javascripts/notification_parser.js b/plugins/CoreHome/javascripts/notification_parser.js deleted file mode 100644 index 0747d02373..0000000000 --- a/plugins/CoreHome/javascripts/notification_parser.js +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Piwik - free/libre analytics platform - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - */ - -$(document).ready((function ($, require) { - return function () { - - var UI = require('piwik/UI'); - - var $notificationNodes = $('[data-role="notification"]'); - - $notificationNodes.each(function (index, notificationNode) { - $notificationNode = $(notificationNode); - var attributes = $notificationNode.data(); - var message = $notificationNode.html(); - - if (message) { - var notification = new UI.Notification(); - attributes.animate = false; - notification.show(message, attributes); - } - - $notificationNodes.remove(); - }); - - } - -})(jQuery, require));
\ No newline at end of file diff --git a/plugins/CoreHome/templates/_dataTable.twig b/plugins/CoreHome/templates/_dataTable.twig index cdd5905933..90864d105c 100644 --- a/plugins/CoreHome/templates/_dataTable.twig +++ b/plugins/CoreHome/templates/_dataTable.twig @@ -76,6 +76,14 @@ </div> </div> +{% if notifications is not empty and notifications|length %} + {% for notificationId, n in notifications %} + + {{ n.message|notification({'id': notificationId, 'type': n.type, 'title': n.title, 'noclear': n.hasNoClear, 'context': n.context, 'raw': n.raw}, false) }} + + {% endfor %} +{% endif %} + {% if showCardTableIsEmpty %} </div></div> {% endif %} |