2013-09-13 15:52:13 -05:00
|
|
|
define([
|
|
|
|
'angular',
|
2014-08-07 07:35:19 -05:00
|
|
|
'lodash',
|
2014-07-30 03:52:02 -05:00
|
|
|
'config',
|
2014-08-16 06:13:26 -05:00
|
|
|
'store',
|
2014-06-13 06:50:09 -05:00
|
|
|
'filesaver'
|
2013-09-13 15:52:13 -05:00
|
|
|
],
|
2015-03-28 11:53:52 -05:00
|
|
|
function (angular, _) {
|
2013-09-13 15:52:13 -05:00
|
|
|
'use strict';
|
|
|
|
|
2014-07-28 11:11:52 -05:00
|
|
|
var module = angular.module('grafana.controllers');
|
2013-09-13 15:52:13 -05:00
|
|
|
|
2015-03-28 11:53:52 -05:00
|
|
|
module.controller('DashboardNavCtrl', function($scope, $rootScope, alertSrv, $location, playlistSrv, backendSrv, $timeout) {
|
2013-09-13 15:52:13 -05:00
|
|
|
|
|
|
|
$scope.init = function() {
|
2014-09-04 01:56:50 -05:00
|
|
|
$scope.onAppEvent('save-dashboard', $scope.saveDashboard);
|
|
|
|
$scope.onAppEvent('delete-dashboard', $scope.deleteDashboard);
|
2013-09-13 15:52:13 -05:00
|
|
|
};
|
|
|
|
|
2015-02-01 08:45:11 -06:00
|
|
|
$scope.openEditView = function(editview) {
|
|
|
|
var search = _.extend($location.search(), {editview: editview});
|
|
|
|
$location.search(search);
|
2013-09-13 15:52:13 -05:00
|
|
|
};
|
|
|
|
|
2015-02-02 04:32:00 -06:00
|
|
|
$scope.starDashboard = function() {
|
|
|
|
if ($scope.dashboardMeta.isStarred) {
|
2015-02-28 02:46:37 -06:00
|
|
|
backendSrv.delete('/api/user/stars/dashboard/' + $scope.dashboard.id).then(function() {
|
2015-03-13 03:52:59 -05:00
|
|
|
$scope.dashboardMeta.isStarred = false;
|
2015-02-02 04:32:00 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
2015-02-28 02:46:37 -06:00
|
|
|
backendSrv.post('/api/user/stars/dashboard/' + $scope.dashboard.id).then(function() {
|
2015-02-02 04:32:00 -06:00
|
|
|
$scope.dashboardMeta.isStarred = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-02 02:45:45 -06:00
|
|
|
$scope.shareDashboard = function() {
|
|
|
|
$scope.appEvent('show-modal', {
|
2015-03-29 07:30:03 -05:00
|
|
|
src: './app/features/dashboard/partials/shareModal.html',
|
2015-02-02 02:45:45 -06:00
|
|
|
scope: $scope.$new(),
|
|
|
|
});
|
2014-06-11 13:22:05 -05:00
|
|
|
};
|
|
|
|
|
2014-08-26 09:42:15 -05:00
|
|
|
$scope.openSearch = function() {
|
2015-02-17 11:20:47 -06:00
|
|
|
$scope.appEvent('show-dash-search');
|
2014-08-26 09:42:15 -05:00
|
|
|
};
|
|
|
|
|
2015-02-18 08:17:31 -06:00
|
|
|
$scope.dashboardTitleAction = function() {
|
|
|
|
$scope.appEvent('hide-dash-editor');
|
2015-03-12 08:01:06 -05:00
|
|
|
$scope.exitFullscreen();
|
2015-02-18 08:17:31 -06:00
|
|
|
};
|
|
|
|
|
2015-03-02 15:24:01 -06:00
|
|
|
$scope.saveDashboard = function(options) {
|
2014-08-03 05:07:50 -05:00
|
|
|
var clone = angular.copy($scope.dashboard);
|
2014-02-01 03:51:35 -06:00
|
|
|
|
2015-03-02 15:24:01 -06:00
|
|
|
backendSrv.saveDashboard(clone, options).then(function(data) {
|
|
|
|
$scope.dashboard.version = data.version;
|
2015-02-28 02:46:37 -06:00
|
|
|
$scope.appEvent('dashboard-saved', $scope.dashboard);
|
2014-02-01 03:51:35 -06:00
|
|
|
|
2015-02-28 02:46:37 -06:00
|
|
|
var dashboardUrl = '/dashboard/db/' + data.slug;
|
2014-06-10 14:32:38 -05:00
|
|
|
|
2015-02-28 02:46:37 -06:00
|
|
|
if (dashboardUrl !== $location.path()) {
|
|
|
|
$location.url(dashboardUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.appEvent('alert-success', ['Dashboard saved', 'Saved as ' + clone.title]);
|
2015-03-02 15:24:01 -06:00
|
|
|
}, $scope.handleSaveDashError);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.handleSaveDashError = function(err) {
|
2015-03-03 03:20:52 -06:00
|
|
|
if (err.data && err.data.status === "version-mismatch") {
|
2015-03-02 15:24:01 -06:00
|
|
|
err.isHandled = true;
|
|
|
|
|
|
|
|
$scope.appEvent('confirm-modal', {
|
|
|
|
title: 'Someone else has updated this dashboard!',
|
2015-03-05 13:04:54 -06:00
|
|
|
text: "Would you still like to save this dashboard?",
|
|
|
|
yesText: "Save & Overwrite",
|
2015-03-02 15:24:01 -06:00
|
|
|
icon: "fa-warning",
|
|
|
|
onConfirm: function() {
|
|
|
|
$scope.saveDashboard({overwrite: true});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-03 03:20:52 -06:00
|
|
|
if (err.data && err.data.status === "name-exists") {
|
2015-03-02 15:24:01 -06:00
|
|
|
err.isHandled = true;
|
|
|
|
|
|
|
|
$scope.appEvent('confirm-modal', {
|
|
|
|
title: 'Another dashboard with the same name exists',
|
2015-03-05 13:04:54 -06:00
|
|
|
text: "Would you still like to save this dashboard?",
|
|
|
|
yesText: "Save & Overwrite",
|
2015-03-02 15:24:01 -06:00
|
|
|
icon: "fa-warning",
|
|
|
|
onConfirm: function() {
|
|
|
|
$scope.saveDashboard({overwrite: true});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-09-13 15:52:13 -05:00
|
|
|
};
|
|
|
|
|
2015-02-07 13:25:53 -06:00
|
|
|
$scope.deleteDashboard = function() {
|
2014-11-10 08:01:30 -06:00
|
|
|
$scope.appEvent('confirm-modal', {
|
2015-03-05 13:04:54 -06:00
|
|
|
title: 'Do you want to delete dashboard ' + $scope.dashboard.title + '?',
|
2015-03-05 14:02:25 -06:00
|
|
|
icon: 'fa-trash',
|
|
|
|
yesText: 'Delete',
|
2014-11-10 08:01:30 -06:00
|
|
|
onConfirm: function() {
|
2015-02-07 13:25:53 -06:00
|
|
|
$scope.deleteDashboardConfirmed();
|
2014-11-10 08:01:30 -06:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-02-07 13:25:53 -06:00
|
|
|
$scope.deleteDashboardConfirmed = function() {
|
2015-02-28 02:46:37 -06:00
|
|
|
backendSrv.delete('/api/dashboards/db/' + $scope.dashboardMeta.slug).then(function() {
|
2015-02-07 13:25:53 -06:00
|
|
|
$scope.appEvent('alert-success', ['Dashboard Deleted', $scope.dashboard.title + ' has been deleted']);
|
2015-02-28 02:46:37 -06:00
|
|
|
$location.url('/');
|
2014-06-12 10:40:37 -05:00
|
|
|
});
|
2013-09-13 15:52:13 -05:00
|
|
|
};
|
2014-06-13 06:50:09 -05:00
|
|
|
|
2015-03-06 03:01:18 -06:00
|
|
|
$scope.saveDashboardAs = function() {
|
2015-02-18 03:44:36 -06:00
|
|
|
var newScope = $rootScope.$new();
|
|
|
|
newScope.clone = angular.copy($scope.dashboard);
|
|
|
|
|
|
|
|
$scope.appEvent('show-modal', {
|
2015-03-06 03:01:18 -06:00
|
|
|
src: './app/features/dashboard/partials/saveDashboardAs.html',
|
2015-02-18 03:44:36 -06:00
|
|
|
scope: newScope,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-06-13 06:50:09 -05:00
|
|
|
$scope.exportDashboard = function() {
|
|
|
|
var blob = new Blob([angular.toJson($scope.dashboard, true)], { type: "application/json;charset=utf-8" });
|
|
|
|
window.saveAs(blob, $scope.dashboard.title + '-' + new Date().getTime());
|
|
|
|
};
|
2013-09-13 15:52:13 -05:00
|
|
|
|
2015-03-20 18:16:59 -05:00
|
|
|
$scope.snapshot = function() {
|
|
|
|
$scope.dashboard.snapshot = true;
|
|
|
|
$rootScope.$broadcast('refresh');
|
|
|
|
|
|
|
|
$timeout(function() {
|
|
|
|
$scope.exportDashboard();
|
|
|
|
$scope.dashboard.snapshot = false;
|
|
|
|
$scope.appEvent('dashboard-snapshot-cleanup');
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-08-28 05:44:01 -05:00
|
|
|
$scope.editJson = function() {
|
2014-09-24 09:26:39 -05:00
|
|
|
$scope.appEvent('show-json-editor', { object: $scope.dashboard });
|
2014-08-28 05:44:01 -05:00
|
|
|
};
|
|
|
|
|
2014-03-08 09:27:01 -06:00
|
|
|
$scope.stopPlaylist = function() {
|
|
|
|
playlistSrv.stop(1);
|
2014-03-07 12:24:45 -06:00
|
|
|
};
|
|
|
|
|
2013-09-13 15:52:13 -05:00
|
|
|
});
|
|
|
|
|
2013-10-07 01:04:37 -05:00
|
|
|
});
|