From e2f5bf166665f679bf6f91dec2d1f742f48bd380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 5 Sep 2016 13:38:25 +0200 Subject: [PATCH] feat(alerting): fixed confirm delete dashboard issue --- public/app/core/services/alert_srv.ts | 17 ++++++++--------- .../app/features/dashboard/dashnav/dashnav.ts | 15 +++++---------- public/app/partials/confirm_modal.html | 7 +++---- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/public/app/core/services/alert_srv.ts b/public/app/core/services/alert_srv.ts index 4ef329f975e..286f03db5f5 100644 --- a/public/app/core/services/alert_srv.ts +++ b/public/app/core/services/alert_srv.ts @@ -80,28 +80,27 @@ export class AlertSrv { showConfirmModal(payload) { var scope = this.$rootScope.$new(); - scope.title = payload.title; - scope.text = payload.text; - scope.text2 = payload.text2; - scope.confirmTextRequired = payload.confirmText !== undefined && payload.confirmText !== ""; - scope.onConfirm = function() { - if (!scope.confirmTextRequired || (scope.confirmTextRequired && scope.confirmTextValid)) { - payload.onConfirm(); - scope.dismiss(); - } + payload.onConfirm(); + scope.dismiss(); }; scope.updateConfirmText = function(value) { scope.confirmTextValid = payload.confirmText.toLowerCase() === value.toLowerCase(); }; + scope.title = payload.title; + scope.text = payload.text; + scope.text2 = payload.text2; + scope.confirmText = payload.confirmText; + scope.onConfirm = payload.onConfirm; scope.onAltAction = payload.onAltAction; scope.altActionText = payload.altActionText; scope.icon = payload.icon || "fa-check"; scope.yesText = payload.yesText || "Yes"; scope.noText = payload.noText || "Cancel"; + scope.confirmTextValid = scope.confirmText ? false : true; var confirmModal = this.$modal({ template: 'public/app/partials/confirm_modal.html', diff --git a/public/app/features/dashboard/dashnav/dashnav.ts b/public/app/features/dashboard/dashnav/dashnav.ts index 23e490f3e81..32a59402832 100644 --- a/public/app/features/dashboard/dashnav/dashnav.ts +++ b/public/app/features/dashboard/dashnav/dashnav.ts @@ -158,18 +158,13 @@ export class DashNavCtrl { $scope.deleteDashboard = function() { var confirmText = ""; var text2 = $scope.dashboard.title; - var alerts = 0; - - _.each($scope.dashboard.rows, row => { - _.each(row.panels, panel => { - if (panel.alerting && panel.alerting.queryRef !== '- select query -') { - alerts += 1; - }; - }); - }); + var alerts = $scope.dashboard.rows.reduce((memo, row) => { + memo += row.panels.filter(panel => panel.alert && panel.alert.enabled).length; + return memo; + }, 0); if (alerts > 0) { - confirmText = $scope.dashboard.title; + confirmText = 'DELETE'; text2 = `This dashboad contains ${alerts} alerts. Deleting this dashboad will also delete those alerts`; } diff --git a/public/app/partials/confirm_modal.html b/public/app/partials/confirm_modal.html index 85788911ff7..e0b6884618b 100644 --- a/public/app/partials/confirm_modal.html +++ b/public/app/partials/confirm_modal.html @@ -22,14 +22,13 @@ -