2016-01-17 11:34:51 +01:00
|
|
|
///<reference path="../../../headers/common.d.ts" />
|
2013-09-13 13:52:13 -07:00
|
|
|
|
2016-01-17 11:34:51 +01:00
|
|
|
import _ from 'lodash';
|
|
|
|
import moment from 'moment';
|
|
|
|
import angular from 'angular';
|
2017-06-02 14:00:42 +02:00
|
|
|
import {appEvents, NavModel} from 'app/core/core';
|
|
|
|
import {DashboardModel} from '../model';
|
2016-05-17 10:29:57 +02:00
|
|
|
import {DashboardExporter} from '../export/exporter';
|
2016-04-14 17:31:34 -04:00
|
|
|
|
2016-01-17 11:34:51 +01:00
|
|
|
export class DashNavCtrl {
|
2017-06-02 14:00:42 +02:00
|
|
|
dashboard: DashboardModel;
|
|
|
|
navModel: NavModel;
|
|
|
|
titleTooltip: string;
|
2016-01-17 11:34:51 +01:00
|
|
|
|
|
|
|
/** @ngInject */
|
2017-06-02 14:00:42 +02:00
|
|
|
constructor(
|
|
|
|
private $scope,
|
|
|
|
private $rootScope,
|
|
|
|
private dashboardSrv,
|
|
|
|
private $location,
|
|
|
|
private playlistSrv,
|
|
|
|
private backendSrv,
|
|
|
|
private $timeout,
|
|
|
|
private datasourceSrv,
|
2017-06-16 09:47:21 -04:00
|
|
|
private navModelSrv,
|
|
|
|
private contextSrv) {
|
2017-06-02 14:00:42 +02:00
|
|
|
this.navModel = navModelSrv.getDashboardNav(this.dashboard, this);
|
|
|
|
|
|
|
|
appEvents.on('save-dashboard', this.saveDashboard.bind(this), $scope);
|
|
|
|
appEvents.on('delete-dashboard', this.deleteDashboard.bind(this), $scope);
|
|
|
|
|
|
|
|
if (this.dashboard.meta.isSnapshot) {
|
|
|
|
var meta = this.dashboard.meta;
|
|
|
|
this.titleTooltip = 'Created: ' + moment(meta.created).calendar();
|
2016-01-17 11:34:51 +01:00
|
|
|
if (meta.expires) {
|
2017-06-02 14:00:42 +02:00
|
|
|
this.titleTooltip += '<br>Expires: ' + moment(meta.expires).fromNow() + '<br>';
|
2016-01-17 11:34:51 +01:00
|
|
|
}
|
|
|
|
}
|
2017-06-02 14:00:42 +02:00
|
|
|
}
|
2013-09-13 13:52:13 -07:00
|
|
|
|
2017-06-16 09:47:21 -04:00
|
|
|
toggleSideMenu() {
|
|
|
|
this.contextSrv.toggleSideMenu();
|
|
|
|
}
|
|
|
|
|
2017-06-02 14:00:42 +02:00
|
|
|
openEditView(editview) {
|
|
|
|
var search = _.extend(this.$location.search(), {editview: editview});
|
|
|
|
this.$location.search(search);
|
|
|
|
}
|
2013-09-13 13:52:13 -07:00
|
|
|
|
2017-06-02 14:00:42 +02:00
|
|
|
showHelpModal() {
|
|
|
|
appEvents.emit('show-modal', {templateHtml: '<help-modal></help-modal>'});
|
|
|
|
}
|
2016-11-03 15:14:44 +01:00
|
|
|
|
2017-06-02 14:00:42 +02:00
|
|
|
starDashboard() {
|
|
|
|
if (this.dashboard.meta.isStarred) {
|
|
|
|
return this.backendSrv.delete('/api/user/stars/dashboard/' + this.dashboard.id).then(() => {
|
|
|
|
this.dashboard.meta.isStarred = false;
|
2015-02-02 11:32:00 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-02 14:00:42 +02:00
|
|
|
this.backendSrv.post('/api/user/stars/dashboard/' + this.dashboard.id).then(() => {
|
|
|
|
this.dashboard.meta.isStarred = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
shareDashboard(tabIndex) {
|
|
|
|
var modalScope = this.$scope.$new();
|
2016-01-29 11:48:57 -05:00
|
|
|
modalScope.tabIndex = tabIndex;
|
2017-06-02 14:00:42 +02:00
|
|
|
modalScope.dashboard = this.dashboard;
|
2016-01-29 11:48:57 -05:00
|
|
|
|
2017-06-02 14:00:42 +02:00
|
|
|
appEvents.emit('show-modal', {
|
2016-02-01 18:19:02 +01:00
|
|
|
src: 'public/app/features/dashboard/partials/shareModal.html',
|
2016-01-29 11:48:57 -05:00
|
|
|
scope: modalScope
|
2015-02-02 09:45:45 +01:00
|
|
|
});
|
2017-06-02 14:00:42 +02:00
|
|
|
}
|
2016-02-23 08:11:04 -08:00
|
|
|
|
2017-06-02 14:00:42 +02:00
|
|
|
hideTooltip(evt) {
|
2015-09-21 11:29:14 +02:00
|
|
|
angular.element(evt.currentTarget).tooltip('hide');
|
2017-06-02 14:00:42 +02:00
|
|
|
}
|
2015-09-18 00:45:29 -07:00
|
|
|
|
2017-06-02 14:00:42 +02:00
|
|
|
makeEditable() {
|
|
|
|
this.dashboard.editable = true;
|
2015-12-15 08:41:16 +01:00
|
|
|
|
2017-06-02 14:00:42 +02:00
|
|
|
return this.dashboardSrv.saveDashboard({makeEditable: true, overwrite: false}).then(() => {
|
2016-01-17 11:34:51 +01:00
|
|
|
// force refresh whole page
|
2015-12-15 08:41:16 +01:00
|
|
|
window.location.href = window.location.href;
|
2016-10-14 13:06:29 +02:00
|
|
|
});
|
2017-06-02 14:00:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exitFullscreen() {
|
|
|
|
this.$rootScope.appEvent('panel-change-view', {fullscreen: false, edit: false});
|
|
|
|
}
|
2015-12-15 08:41:16 +01:00
|
|
|
|
2017-06-05 14:56:11 +02:00
|
|
|
saveDashboard() {
|
|
|
|
return this.dashboardSrv.saveDashboard();
|
2017-06-02 14:00:42 +02:00
|
|
|
}
|
2013-09-13 13:52:13 -07:00
|
|
|
|
2017-06-02 14:00:42 +02:00
|
|
|
deleteDashboard() {
|
2016-05-16 11:32:08 +02:00
|
|
|
var confirmText = "";
|
2017-06-02 14:00:42 +02:00
|
|
|
var text2 = this.dashboard.title;
|
|
|
|
var alerts = this.dashboard.rows.reduce((memo, row) => {
|
2016-09-30 17:37:47 +02:00
|
|
|
memo += row.panels.filter(panel => panel.alert).length;
|
2016-09-05 13:38:25 +02:00
|
|
|
return memo;
|
|
|
|
}, 0);
|
2016-05-16 11:32:08 +02:00
|
|
|
|
|
|
|
if (alerts > 0) {
|
2016-09-05 13:38:25 +02:00
|
|
|
confirmText = 'DELETE';
|
2017-06-06 00:47:25 +02:00
|
|
|
text2 = `This dashboard contains ${alerts} alerts. Deleting this dashboad will also delete those alerts`;
|
2016-05-16 11:32:08 +02:00
|
|
|
}
|
|
|
|
|
2017-06-02 14:00:42 +02:00
|
|
|
appEvents.emit('confirm-modal', {
|
2016-03-12 10:13:49 +01:00
|
|
|
title: 'Delete',
|
|
|
|
text: 'Do you want to delete this dashboard?',
|
2016-05-16 11:32:08 +02:00
|
|
|
text2: text2,
|
2015-03-05 21:02:25 +01:00
|
|
|
icon: 'fa-trash',
|
2016-05-16 11:32:08 +02:00
|
|
|
confirmText: confirmText,
|
2015-03-05 21:02:25 +01:00
|
|
|
yesText: 'Delete',
|
2017-06-02 14:00:42 +02:00
|
|
|
onConfirm: () => {
|
|
|
|
this.dashboard.meta.canSave = false;
|
|
|
|
this.deleteDashboardConfirmed();
|
2014-11-10 15:01:30 +01:00
|
|
|
}
|
|
|
|
});
|
2017-06-02 14:00:42 +02:00
|
|
|
}
|
2014-11-10 15:01:30 +01:00
|
|
|
|
2017-06-02 14:00:42 +02:00
|
|
|
deleteDashboardConfirmed() {
|
|
|
|
this.backendSrv.delete('/api/dashboards/db/' + this.dashboard.meta.slug).then(() => {
|
|
|
|
appEvents.emit('alert-success', ['Dashboard Deleted', this.dashboard.title + ' has been deleted']);
|
|
|
|
this.$location.url('/');
|
2014-06-12 17:40:37 +02:00
|
|
|
});
|
2017-06-02 14:00:42 +02:00
|
|
|
}
|
2014-06-13 13:50:09 +02:00
|
|
|
|
2017-06-02 14:00:42 +02:00
|
|
|
saveDashboardAs() {
|
2017-06-05 14:56:11 +02:00
|
|
|
return this.dashboardSrv.showSaveAsModal();
|
2017-06-02 14:00:42 +02:00
|
|
|
}
|
2015-02-18 10:44:36 +01:00
|
|
|
|
2017-06-02 14:00:42 +02:00
|
|
|
viewJson() {
|
|
|
|
var clone = this.dashboard.getSaveModelClone();
|
2016-05-18 15:53:13 +02:00
|
|
|
var html = angular.toJson(clone, true);
|
2016-08-10 21:23:58 +03:00
|
|
|
var uri = "data:application/json;charset=utf-8," + encodeURIComponent(html);
|
2016-05-18 15:53:13 +02:00
|
|
|
var newWindow = window.open(uri);
|
2017-06-02 14:00:42 +02:00
|
|
|
}
|
2017-06-01 23:32:33 +02:00
|
|
|
|
2017-06-23 16:00:26 -04:00
|
|
|
onFolderChange(folderId) {
|
|
|
|
this.dashboard.folderId = folderId;
|
2017-06-01 23:32:33 +02:00
|
|
|
}
|
2016-01-17 11:34:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function dashNavDirective() {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
2016-02-01 18:19:02 +01:00
|
|
|
templateUrl: 'public/app/features/dashboard/dashnav/dashnav.html',
|
2016-01-17 11:34:51 +01:00
|
|
|
controller: DashNavCtrl,
|
2017-06-02 14:00:42 +02:00
|
|
|
bindToController: true,
|
|
|
|
controllerAs: 'ctrl',
|
2016-01-17 11:34:51 +01:00
|
|
|
transclude: true,
|
2017-06-02 14:00:42 +02:00
|
|
|
scope: { dashboard: "=" }
|
2016-01-17 11:34:51 +01:00
|
|
|
};
|
|
|
|
}
|
2013-09-13 13:52:13 -07:00
|
|
|
|
2016-01-17 11:34:51 +01:00
|
|
|
angular.module('grafana.directives').directive('dashnav', dashNavDirective);
|