From ca7aa294e0524143f7a71a03db9fbc65b3e0ba6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 27 Apr 2015 17:20:32 +0200 Subject: [PATCH] Began wriing unit test for new panel repeat features, #1888 --- .../app/features/dashboard/dashboardCtrl.js | 1 + public/app/features/dashboard/dashboardSrv.js | 6 +- .../features/dashboard/dynamicDashboardSrv.js | 13 +++- .../dashboard/partials/dashboardTopNav.html | 2 +- .../features/dashboard/unsavedChangesSrv.js | 3 +- public/test/specs/dashboardSrv-specs.js | 9 +-- .../test/specs/dynamicDashboardSrv-specs.js | 65 +++++++++++++++++++ public/test/test-main.js | 1 + 8 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 public/test/specs/dynamicDashboardSrv-specs.js diff --git a/public/app/features/dashboard/dashboardCtrl.js b/public/app/features/dashboard/dashboardCtrl.js index ba86f9f5dba..41453bd77e3 100644 --- a/public/app/features/dashboard/dashboardCtrl.js +++ b/public/app/features/dashboard/dashboardCtrl.js @@ -48,6 +48,7 @@ function (angular, $, config) { // the rest of the dashboard can load templateValuesSrv.init(dashboard).finally(function() { dynamicDashboardSrv.init(dashboard); + $scope.dashboard = dashboard; $scope.dashboardMeta = dashboard.meta; $scope.dashboardViewState = dashboardViewStateSrv.create($scope); diff --git a/public/app/features/dashboard/dashboardSrv.js b/public/app/features/dashboard/dashboardSrv.js index 02d8f51fafe..afe5e7964c6 100644 --- a/public/app/features/dashboard/dashboardSrv.js +++ b/public/app/features/dashboard/dashboardSrv.js @@ -10,7 +10,7 @@ function (angular, $, kbn, _, moment) { var module = angular.module('grafana.services'); - module.factory('dashboardSrv', function(contextSrv) { + module.factory('dashboardSrv', function() { function DashboardModel (data, meta) { if (!data) { @@ -59,10 +59,6 @@ function (angular, $, kbn, _, moment) { meta.canStar = meta.canStar === false ? false : true; meta.canDelete = meta.canDelete === false ? false : true; - if (contextSrv.hasRole('Viewer')) { - meta.canSave = false; - } - if (!this.editable) { meta.canEdit = false; meta.canDelete = false; diff --git a/public/app/features/dashboard/dynamicDashboardSrv.js b/public/app/features/dashboard/dynamicDashboardSrv.js index 286eb116e25..8d099a9f6c6 100644 --- a/public/app/features/dashboard/dynamicDashboardSrv.js +++ b/public/app/features/dashboard/dynamicDashboardSrv.js @@ -8,8 +8,11 @@ function (angular, _) { var module = angular.module('grafana.services'); module.service('dynamicDashboardSrv', function() { + var self = this; this.init = function(dashboard) { + this.iteration = 0; + this.handlePanelRepeats(dashboard); this.handleRowRepeats(dashboard); }; @@ -112,6 +115,15 @@ function (angular, _) { }; + this.getRepeatPanel = function(sourcePanel, row) { + for (var i = 0; i < row.panels.length; i++) { + var panel = row.panels[i]; + if (panel.sourcePanel === sourcePanel) { + return panel; + } + } + }; + this.repeatPanel = function(panel, row, dashboard) { var variables = dashboard.templating.list; var variable = _.findWhere(variables, {name: panel.repeat.replace('$', '')}); @@ -137,7 +149,6 @@ function (angular, _) { panel.scopedVars = {}; panel.scopedVars[variable.name] = option; } - console.log('duplicatePanel'); }); }; diff --git a/public/app/features/dashboard/partials/dashboardTopNav.html b/public/app/features/dashboard/partials/dashboardTopNav.html index 6f85d6b4e02..89a6a185759 100644 --- a/public/app/features/dashboard/partials/dashboardTopNav.html +++ b/public/app/features/dashboard/partials/dashboardTopNav.html @@ -27,7 +27,7 @@
  • -
  • +