From 455e80513b7b9e51ac0b374c41146bd6445bfa9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 4 Sep 2014 08:56:50 +0200 Subject: [PATCH] Fixes delete link in search result, broken after recent changes to search results, Closes #749 --- src/app/controllers/dashboardNavCtrl.js | 18 ++++++++---------- src/app/controllers/search.js | 12 +++++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/app/controllers/dashboardNavCtrl.js b/src/app/controllers/dashboardNavCtrl.js index 7f32fb685c2..b6813b7ce19 100644 --- a/src/app/controllers/dashboardNavCtrl.js +++ b/src/app/controllers/dashboardNavCtrl.js @@ -16,9 +16,8 @@ function (angular, _, moment, config, store) { $scope.init = function() { $scope.db = datasourceSrv.getGrafanaDB(); - $scope.onAppEvent('save-dashboard', function() { - $scope.saveDashboard(); - }); + $scope.onAppEvent('save-dashboard', $scope.saveDashboard); + $scope.onAppEvent('delete-dashboard', $scope.deleteDashboard); $scope.onAppEvent('zoom-out', function() { $scope.zoom(2); @@ -57,10 +56,10 @@ function (angular, _, moment, config, store) { $scope.isAdmin = function() { if (!config.admin || !config.admin.password) { return true; } - if (this.passwordCache() === config.admin.password) { return true; } + if ($scope.passwordCache() === config.admin.password) { return true; } var password = window.prompt("Admin password", ""); - this.passwordCache(password); + $scope.passwordCache(password); if (password === config.admin.password) { return true; } @@ -74,7 +73,7 @@ function (angular, _, moment, config, store) { }; $scope.saveDashboard = function() { - if (!this.isAdmin()) { return false; } + if (!$scope.isAdmin()) { return false; } var clone = angular.copy($scope.dashboard); $scope.db.saveDashboard(clone) @@ -93,15 +92,14 @@ function (angular, _, moment, config, store) { }); }; - $scope.deleteDashboard = function(id, $event) { - $event.stopPropagation(); - + $scope.deleteDashboard = function(evt, options) { if (!confirm('Are you sure you want to delete dashboard?')) { return; } - if (!this.isAdmin()) { return false; } + if (!$scope.isAdmin()) { return false; } + var id = options.id; $scope.db.deleteDashboard(id).then(function(id) { alertSrv.set('Dashboard Deleted', id + ' has been deleted', 'success', 5000); }, function() { diff --git a/src/app/controllers/search.js b/src/app/controllers/search.js index 6287b3fffb9..c294c9d86f6 100644 --- a/src/app/controllers/search.js +++ b/src/app/controllers/search.js @@ -94,8 +94,7 @@ function (angular, _, config, $) { } }; - $scope.showTags = function(evt) { - evt.stopPropagation(); + $scope.showTags = function() { $scope.tagsOnly = !$scope.tagsOnly; $scope.query.query = $scope.tagsOnly ? "tags!:" : ""; $scope.giveSearchFocus = $scope.giveSearchFocus + 1; @@ -106,10 +105,14 @@ function (angular, _, config, $) { $scope.search = function() { $scope.showImport = false; $scope.selectedIndex = 0; - $scope.searchDashboards($scope.query.query); }; + $scope.deleteDashboard = function(id, evt) { + evt.stopPropagation(); + $scope.emitAppEvent('delete-dashboard', { id: id }); + }; + $scope.addMetricToCurrentDashboard = function (metricId) { $scope.dashboard.rows.push({ title: '', @@ -126,8 +129,7 @@ function (angular, _, config, $) { }); }; - $scope.toggleImport = function ($event) { - $event.stopPropagation(); + $scope.toggleImport = function () { $scope.showImport = !$scope.showImport; };