diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index 2c3102f1811..cc1a8644a51 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -202,8 +202,12 @@ export class BackendSrv { saveDashboard(dash, options) { options = (options || {}); - const message = options.message || ''; - return this.post('/api/dashboards/db/', {dashboard: dash, overwrite: options.overwrite === true, message}); + + return this.post('/api/dashboards/db/', { + dashboard: dash, + overwrite: options.overwrite === true, + message: options.message || '', + }); } } diff --git a/public/app/features/dashboard/all.js b/public/app/features/dashboard/all.js index 4255651d6b4..9ca6f190c63 100644 --- a/public/app/features/dashboard/all.js +++ b/public/app/features/dashboard/all.js @@ -5,8 +5,8 @@ define([ './dashboardLoaderSrv', './dashnav/dashnav', './submenu/submenu', - './saveDashboardAsCtrl', - './saveDashboardMessageCtrl', + './save_as_modal', + './save_modal', './shareModalCtrl', './shareSnapshotCtrl', './dashboard_srv', @@ -20,7 +20,6 @@ define([ './import/dash_import', './export/export_modal', './export_data/export_data_modal', - './dash_list_ctrl', './ad_hoc_filters', './row/row_ctrl', './repeat_option/repeat_option', diff --git a/public/app/features/dashboard/dash_list_ctrl.ts b/public/app/features/dashboard/dash_list_ctrl.ts deleted file mode 100644 index f08d7507e65..00000000000 --- a/public/app/features/dashboard/dash_list_ctrl.ts +++ /dev/null @@ -1,11 +0,0 @@ -/// - -import coreModule from 'app/core/core_module'; - -export class DashListCtrl { - /** @ngInject */ - constructor() { - } -} - -coreModule.controller('DashListCtrl', DashListCtrl); diff --git a/public/app/features/dashboard/dashboard_srv.ts b/public/app/features/dashboard/dashboard_srv.ts index b075af7352e..30ba7defdfd 100644 --- a/public/app/features/dashboard/dashboard_srv.ts +++ b/public/app/features/dashboard/dashboard_srv.ts @@ -65,7 +65,7 @@ export class DashboardSrv { icon: "fa-warning", altActionText: "Save As", onAltAction: () => { - this.saveDashboardAs(); + this.showSaveAsModal(); }, onConfirm: () => { this.saveDashboard({overwrite: true}, clone); @@ -102,36 +102,33 @@ export class DashboardSrv { } if (this.dash.title === 'New dashboard') { - return this.saveDashboardAs(); + return this.showSaveAsModal(); } if (this.dash.version > 0) { - return this.saveDashboardMessage(); + return this.showSaveModal(); } return this.save(this.dash.getSaveModelClone(), options); } - saveDashboardAs() { + showSaveAsModal() { var newScope = this.$rootScope.$new(); newScope.clone = this.dash.getSaveModelClone(); newScope.clone.editable = true; newScope.clone.hideControls = false; this.$rootScope.appEvent('show-modal', { - src: 'public/app/features/dashboard/partials/saveDashboardAs.html', + templateHtml: '', scope: newScope, modalClass: 'modal--narrow' }); } - saveDashboardMessage() { - var newScope = this.$rootScope.$new(); - newScope.clone = this.dash.getSaveModelClone(); - + showSaveModal() { this.$rootScope.appEvent('show-modal', { - src: 'public/app/features/dashboard/partials/saveDashboardMessage.html', - scope: newScope, + templateHtml: '"', + scope: this.$rootScope.$new(), modalClass: 'modal--narrow' }); } diff --git a/public/app/features/dashboard/dashnav/dashnav.ts b/public/app/features/dashboard/dashnav/dashnav.ts index 339e911c81d..e77c2bb3e09 100644 --- a/public/app/features/dashboard/dashnav/dashnav.ts +++ b/public/app/features/dashboard/dashnav/dashnav.ts @@ -87,8 +87,8 @@ export class DashNavCtrl { this.$rootScope.appEvent('panel-change-view', {fullscreen: false, edit: false}); } - saveDashboard(options) { - return this.dashboardSrv.saveDashboard(options); + saveDashboard() { + return this.dashboardSrv.saveDashboard(); } deleteDashboard() { @@ -126,7 +126,7 @@ export class DashNavCtrl { } saveDashboardAs() { - return this.dashboardSrv.saveDashboardAs(); + return this.dashboardSrv.showSaveAsModal(); } viewJson() { diff --git a/public/app/features/dashboard/partials/dash_list.html b/public/app/features/dashboard/partials/dash_list.html deleted file mode 100644 index 3058715e0e6..00000000000 --- a/public/app/features/dashboard/partials/dash_list.html +++ /dev/null @@ -1,10 +0,0 @@ - - - -
- -
- - diff --git a/public/app/features/dashboard/partials/graphiteImport.html b/public/app/features/dashboard/partials/graphiteImport.html deleted file mode 100644 index d23d506d17f..00000000000 --- a/public/app/features/dashboard/partials/graphiteImport.html +++ /dev/null @@ -1,35 +0,0 @@ -
- -
-

Load dashboard from Graphite-Web

- -
-
-
- Data source -
-
-
- -
-
-
- -
-
-
- - - - - - -
{{dash.name}} - -
- -
-
diff --git a/public/app/features/dashboard/partials/saveDashboardAs.html b/public/app/features/dashboard/partials/saveDashboardAs.html deleted file mode 100644 index 106f54fb85f..00000000000 --- a/public/app/features/dashboard/partials/saveDashboardAs.html +++ /dev/null @@ -1,27 +0,0 @@ - - diff --git a/public/app/features/dashboard/partials/saveDashboardMessage.html b/public/app/features/dashboard/partials/saveDashboardMessage.html deleted file mode 100644 index d3df2aa1ce3..00000000000 --- a/public/app/features/dashboard/partials/saveDashboardMessage.html +++ /dev/null @@ -1,49 +0,0 @@ - - - diff --git a/public/app/features/dashboard/saveDashboardAsCtrl.js b/public/app/features/dashboard/saveDashboardAsCtrl.js deleted file mode 100644 index 6f91591feca..00000000000 --- a/public/app/features/dashboard/saveDashboardAsCtrl.js +++ /dev/null @@ -1,39 +0,0 @@ -define([ - 'angular', -], -function (angular) { - 'use strict'; - - var module = angular.module('grafana.controllers'); - - module.controller('SaveDashboardAsCtrl', function($scope, dashboardSrv) { - - $scope.init = function() { - $scope.clone.id = null; - $scope.clone.editable = true; - $scope.clone.title = $scope.clone.title + " Copy"; - - // remove alerts - $scope.clone.rows.forEach(function(row) { - row.panels.forEach(function(panel) { - delete panel.alert; - }); - }); - - // remove auto update - delete $scope.clone.autoUpdate; - }; - - $scope.keyDown = function (evt) { - if (evt.keyCode === 13) { - $scope.saveClone(); - } - }; - - $scope.saveClone = function() { - return dashboardSrv.save($scope.clone, {overwrite: false}) - .then(function() { $scope.dismiss(); }); - }; - }); - -}); diff --git a/public/app/features/dashboard/saveDashboardMessageCtrl.js b/public/app/features/dashboard/saveDashboardMessageCtrl.js deleted file mode 100644 index 90f1c0c6c6d..00000000000 --- a/public/app/features/dashboard/saveDashboardMessageCtrl.js +++ /dev/null @@ -1,29 +0,0 @@ -define([ - 'angular', -], -function (angular) { - 'use strict'; - - var module = angular.module('grafana.controllers'); - - module.controller('SaveDashboardMessageCtrl', function($scope, dashboardSrv) { - - $scope.init = function() { - $scope.clone.message = ''; - $scope.clone.max = 64; - }; - - function saveDashboard(options) { - options.message = $scope.clone.message; - return dashboardSrv.save($scope.clone, options) - .then(function() { $scope.dismiss(); }); - } - - $scope.saveVersion = function(isValid) { - if (!isValid) { return; } - saveDashboard({overwrite: false}); - }; - }); - -}); - diff --git a/public/app/features/dashboard/save_as_modal.ts b/public/app/features/dashboard/save_as_modal.ts new file mode 100644 index 00000000000..22382f2867d --- /dev/null +++ b/public/app/features/dashboard/save_as_modal.ts @@ -0,0 +1,79 @@ +/// + +import coreModule from 'app/core/core_module'; + +const template = ` + +`; + +export class SaveDashboardAsModalCtrl { + clone: any; + dismiss: () => void; + + /** @ngInject */ + constructor(private $scope, private dashboardSrv) { + var dashboard = this.dashboardSrv.getCurrent(); + this.clone = dashboard.getSaveModelClone(); + this.clone.id = null; + this.clone.title += ' Copy'; + this.clone.editable = true; + this.clone.hideControls = false; + + // remove alerts + this.clone.rows.forEach(row => { + row.panels.forEach(panel => { + delete panel.alert; + }); + }); + + delete this.clone.autoUpdate; + } + + save() { + return this.dashboardSrv.save(this.clone).then(this.dismiss); + } + + keyDown(evt) { + if (evt.keyCode === 13) { + this.save(); + } + } +} + +export function saveDashboardAsDirective() { + return { + restrict: 'E', + template: template, + controller: SaveDashboardAsModalCtrl, + bindToController: true, + controllerAs: 'ctrl', + scope: {dismiss: "&"} + }; +} + +coreModule.directive('saveDashboardAsModal', saveDashboardAsDirective); diff --git a/public/app/features/dashboard/save_modal.ts b/public/app/features/dashboard/save_modal.ts new file mode 100644 index 00000000000..101d5ddf11f --- /dev/null +++ b/public/app/features/dashboard/save_modal.ts @@ -0,0 +1,95 @@ +/// + +import coreModule from 'app/core/core_module'; + +const template = ` + +`; + +export class SaveDashboardModalCtrl { + message: string; + max: number; + saveForm: any; + dismiss: () => void; + + /** @ngInject */ + constructor(private $scope, private dashboardSrv) { + this.message = ''; + this.max = 64; + } + + save() { + if (!this.saveForm.$valid) { + return; + } + + var dashboard = this.dashboardSrv.getCurrent(); + var saveModel = dashboard.getSaveModelClone(); + var options = {message: this.message}; + + return this.dashboardSrv.save(saveModel, options).then(this.dismiss); + } + + keyDown(evt) { + if (evt.keyCode === 13) { + this.save(); + } + } +} + +export function saveDashboardModalDirective() { + return { + restrict: 'E', + template: template, + controller: SaveDashboardModalCtrl, + bindToController: true, + controllerAs: 'ctrl', + scope: {dismiss: "&"} + }; +} + +coreModule.directive('saveDashboardModal', saveDashboardModalDirective);