Commit 30645a6d by Torkel Ödegaard

refactor(alerting): initial step for seperating alerting and dash model, #6273

parent 4c26c55f
......@@ -252,7 +252,7 @@ func NotificationTest(c *middleware.Context, dto dtos.NotificationTestCommand) R
return ApiSuccess("Test notification sent")
}
//POST /api/:alertId/pause
//POST /api/alerts/:alertId/pause
func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response {
cmd := models.PauseAlertCommand{
OrgId: c.OrgId,
......
///<reference path="../../headers/common.d.ts" />
import config from 'app/core/config';
import angular from 'angular';
import moment from 'moment';
import _ from 'lodash';
import coreModule from 'app/core/core_module';
export class AlertingSrv {
dashboard: any;
alerts: any[];
init(dashboard, alerts) {
this.dashboard = dashboard;
this.alerts = alerts || [];
}
}
coreModule.service('alertingSrv', AlertingSrv);
define([
'./dashboard_ctrl',
'./alerting_srv',
'./dashboardLoaderSrv',
'./dashnav/dashnav',
'./submenu/submenu',
......
......@@ -16,6 +16,7 @@ export class DashboardCtrl {
dashboardKeybindings,
timeSrv,
variableSrv,
alertingSrv,
dashboardSrv,
unsavedChangesSrv,
dynamicDashboardSrv,
......@@ -43,6 +44,7 @@ export class DashboardCtrl {
// init services
timeSrv.init(dashboard);
alertingSrv.init(dashboard, data.alerts);
// template values service needs to initialize completely before
// the rest of the dashboard can load
......
......@@ -9,7 +9,7 @@ import {DashboardExporter} from '../export/exporter';
export class DashNavCtrl {
/** @ngInject */
constructor($scope, $rootScope, alertSrv, $location, playlistSrv, backendSrv, $timeout, datasourceSrv) {
constructor($scope, $rootScope, dashboardSrv, $location, playlistSrv, backendSrv, $timeout, datasourceSrv) {
$scope.init = function() {
$scope.onAppEvent('save-dashboard', $scope.saveDashboard);
......@@ -71,88 +71,14 @@ export class DashNavCtrl {
$scope.makeEditable = function() {
$scope.dashboard.editable = true;
var clone = $scope.dashboard.getSaveModelClone();
backendSrv.saveDashboard(clone, {overwrite: false}).then(function(data) {
$scope.dashboard.version = data.version;
$scope.appEvent('dashboard-saved', $scope.dashboard);
$scope.appEvent('alert-success', ['Dashboard saved', 'Saved as ' + clone.title]);
return dashboardSrv.saveDashboard({makeEditable: true, overwrite: false}).then(function() {
// force refresh whole page
window.location.href = window.location.href;
}, $scope.handleSaveDashError);
});
};
$scope.saveDashboard = function(options) {
if ($scope.dashboardMeta.canSave === false) {
return;
}
var clone = $scope.dashboard.getSaveModelClone();
backendSrv.saveDashboard(clone, options).then(function(data) {
$scope.dashboard.version = data.version;
$scope.appEvent('dashboard-saved', $scope.dashboard);
var dashboardUrl = '/dashboard/db/' + data.slug;
if (dashboardUrl !== $location.path()) {
$location.url(dashboardUrl);
}
$scope.appEvent('alert-success', ['Dashboard saved', 'Saved as ' + clone.title]);
}, $scope.handleSaveDashError);
};
$scope.handleSaveDashError = function(err) {
if (err.data && err.data.status === "version-mismatch") {
err.isHandled = true;
$scope.appEvent('confirm-modal', {
title: 'Conflict',
text: 'Someone else has updated this dashboard.',
text2: 'Would you still like to save this dashboard?',
yesText: "Save & Overwrite",
icon: "fa-warning",
onConfirm: function() {
$scope.saveDashboard({overwrite: true});
}
});
}
if (err.data && err.data.status === "name-exists") {
err.isHandled = true;
$scope.appEvent('confirm-modal', {
title: 'Conflict',
text: 'Dashboard with the same name exists.',
text2: 'Would you still like to save this dashboard?',
yesText: "Save & Overwrite",
icon: "fa-warning",
onConfirm: function() {
$scope.saveDashboard({overwrite: true});
}
});
}
if (err.data && err.data.status === "plugin-dashboard") {
err.isHandled = true;
$scope.appEvent('confirm-modal', {
title: 'Plugin Dashboard',
text: err.data.message,
text2: 'Your changes will be lost when you update the plugin. Use Save As to create custom version.',
yesText: "Overwrite",
icon: "fa-warning",
altActionText: "Save As",
onAltAction: function() {
$scope.saveDashboardAs();
},
onConfirm: function() {
$scope.saveDashboard({overwrite: true});
}
});
}
return dashboardSrv.saveDashboard(options);
};
$scope.deleteDashboard = function() {
......@@ -189,16 +115,7 @@ export class DashNavCtrl {
};
$scope.saveDashboardAs = function() {
var newScope = $rootScope.$new();
newScope.clone = $scope.dashboard.getSaveModelClone();
newScope.clone.editable = true;
newScope.clone.hideControls = false;
$scope.appEvent('show-modal', {
src: 'public/app/features/dashboard/partials/saveDashboardAs.html',
scope: newScope,
modalClass: 'modal--narrow'
});
return dashboardSrv.saveDashboardAs();
};
$scope.viewJson = function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment