diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2016-03-08 04:56:14 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2016-03-09 23:34:28 +0300 |
commit | 7f0fdeae8be84f2c80151e960eb02a5652bc1cbd (patch) | |
tree | f95096b26489a8ff953a751745679ed1a60fb144 /plugins/Dashboard | |
parent | 3b37fe84dd01822e48eb815a18b28ac474de96a2 (diff) |
fix many ui tests
Diffstat (limited to 'plugins/Dashboard')
4 files changed, 56 insertions, 41 deletions
diff --git a/plugins/Dashboard/angularjs/dashboard/dashboard.directive.js b/plugins/Dashboard/angularjs/dashboard/dashboard.directive.js index 9af79047f7..60031e80d3 100644 --- a/plugins/Dashboard/angularjs/dashboard/dashboard.directive.js +++ b/plugins/Dashboard/angularjs/dashboard/dashboard.directive.js @@ -52,7 +52,10 @@ } function fetchDashboard(dashboardId) { - $('#dashboardWidgetsArea').innerHTML =''; + var dashboardElement = $('#dashboardWidgetsArea'); + dashboardElement.dashboard('destroyWidgets'); + dashboardElement.empty(); + globalAjaxQueue.abort(); var getDashboard = dashboardsModel.getDashboard(dashboardId); var getLayout = dashboardsModel.getDashboardLayout(dashboardId); @@ -87,9 +90,10 @@ fetchDashboard(scope.dashboardid); - function onLocationChange(event, url1, url2) + function onLocationChange(event, newUrl, oldUrl) { - if (url1 !== url2) { + if (newUrl !== oldUrl && newUrl.indexOf('category=Dashboard_Dashboard') === -1) { + // we remove the dashboard only if we no longer show a dashboard. clearDashboard(); } } diff --git a/plugins/Dashboard/javascripts/dashboard.js b/plugins/Dashboard/javascripts/dashboard.js index 196196ea5b..582ad1b79a 100644 --- a/plugins/Dashboard/javascripts/dashboard.js +++ b/plugins/Dashboard/javascripts/dashboard.js @@ -27,6 +27,7 @@ function createDashboard() { function (id) { angular.element(document).injector().invoke(function ($location, reportingMenuModel, dashboardsModel) { dashboardsModel.reloadAllDashboards().then(function () { + $('#dashboardWidgetsArea').dashboard('loadDashboard', id); $('#dashboardWidgetsArea').dashboard('rebuildMenu'); }); diff --git a/plugins/Dashboard/javascripts/dashboardObject.js b/plugins/Dashboard/javascripts/dashboardObject.js index b1da76c099..3bdd50662c 100644 --- a/plugins/Dashboard/javascripts/dashboardObject.js +++ b/plugins/Dashboard/javascripts/dashboardObject.js @@ -70,26 +70,32 @@ destroy: function () { $(dashboardElement).remove(); dashboardElement = null; - var widgets = $('[widgetId]'); - for (var i = 0; i < widgets.length; i++) { - $(widgets[i]).dashboardWidget('destroy'); - } + destroyWidgets(); }, + destroyWidgets: destroyWidgets, + /** * Load dashboard with the given id * * @param {int} dashboardIdToLoad */ loadDashboard: function (dashboardIdToLoad) { + $(dashboardElement).empty(); dashboardName = ''; dashboardLayout = null; dashboardId = dashboardIdToLoad; - var element = $('[piwik-dashboard]'); - var scope = angular.element(element).scope(); - scope.fetchDashboard(dashboardIdToLoad); + if (piwikHelper.isAngularRenderingThePage()) { + angular.element(document).injector().invoke(function ($location) { + $location.search('subcategory', '' + dashboardIdToLoad); + }); + } else { + var element = $('[piwik-dashboard]'); + var scope = angular.element(element).scope(); + scope.fetchDashboard(dashboardIdToLoad); + } return this; }, @@ -178,12 +184,30 @@ }, rebuildMenu: rebuildMenu, - /** * Removes the current dashboard */ removeDashboard: function () { - removeDashboard(); + if (dashboardId == 1) { + return; // dashboard with id 1 should never be deleted, as it is the default + } + + var ajaxRequest = new ajaxHelper(); + ajaxRequest.setLoadingElement(); + ajaxRequest.addParams({ + module: 'Dashboard', + action: 'removeDashboard', + idDashboard: dashboardId + }, 'get'); + ajaxRequest.setCallback( + function () { + methods.loadDashboard.apply(this, [1]); + rebuildMenu(); + } + ); + ajaxRequest.withTokenInUrl(); + ajaxRequest.setFormat('html'); + ajaxRequest.send(true); }, /** @@ -201,6 +225,14 @@ } }; + function destroyWidgets() + { + var widgets = $('[widgetId]'); + for (var i = 0; i < widgets.length; i++) { + $(widgets[i]).dashboardWidget('destroy'); + } + } + function removeNonExistingWidgets(availableWidgets, layout) { var existingModuleAction = {}; @@ -490,7 +522,7 @@ */ function rebuildMenu() { - if ($('[piwik-reporting-menu]').length) { + if (piwikHelper.isAngularRenderingThePage()) { // dashboard in reporting page (regular Piwik UI) angular.element(document).injector().invoke(function (reportingMenuModel) { reportingMenuModel.reloadMenuItems(); @@ -541,7 +573,6 @@ methods.loadDashboard.apply(_self, [idDashboard]); $(this).closest('li').addClass('active'); - }); }; @@ -611,32 +642,6 @@ } /** - * Removes the current dashboard - */ - function removeDashboard() { - if (dashboardId == 1) { - return; // dashboard with id 1 should never be deleted, as it is the default - } - - var ajaxRequest = new ajaxHelper(); - ajaxRequest.setLoadingElement(); - ajaxRequest.addParams({ - module: 'Dashboard', - action: 'removeDashboard', - idDashboard: dashboardId - }, 'get'); - ajaxRequest.setCallback( - function () { - rebuildMenu(); - methods.loadDashboard.apply(this, [1]); - } - ); - ajaxRequest.withTokenInUrl(); - ajaxRequest.setFormat('html'); - ajaxRequest.send(true); - } - - /** * Make plugin methods available */ $.fn.dashboard = function (method) { diff --git a/plugins/Dashboard/javascripts/dashboardWidget.js b/plugins/Dashboard/javascripts/dashboardWidget.js index 29f0a3a794..b3e78dcea3 100755 --- a/plugins/Dashboard/javascripts/dashboardWidget.js +++ b/plugins/Dashboard/javascripts/dashboardWidget.js @@ -121,7 +121,12 @@ var $widgetContent = $('.widgetContent', currentWidget); $widgetContent.html(loadedContent); - piwikHelper.compileAngularComponents($widgetContent); + + if (currentWidget.parents('body').size()) { + // there might be race conditions, eg widget might be just refreshed while whole dashboard is also + // removed from DOM + piwikHelper.compileAngularComponents($widgetContent); + } $widgetContent.removeClass('loading'); $widgetContent.trigger('widget:create', [self]); } |