2016-01-17 04:34:51 -06:00
|
|
|
import _ from 'lodash';
|
|
|
|
import moment from 'moment';
|
|
|
|
import angular from 'angular';
|
2017-06-02 07:00:42 -05:00
|
|
|
import {appEvents, NavModel} from 'app/core/core';
|
2017-10-12 13:02:07 -05:00
|
|
|
import {DashboardModel} from '../dashboard_model';
|
2016-04-14 16:31:34 -05:00
|
|
|
|
2016-01-17 04:34:51 -06:00
|
|
|
export class DashNavCtrl {
|
2017-06-02 07:00:42 -05:00
|
|
|
dashboard: DashboardModel;
|
|
|
|
navModel: NavModel;
|
|
|
|
titleTooltip: string;
|
2016-01-17 04:34:51 -06:00
|
|
|
|
|
|
|
/** @ngInject */
|
2017-06-02 07:00:42 -05:00
|
|
|
constructor(
|
|
|
|
private $scope,
|
|
|
|
private $rootScope,
|
|
|
|
private dashboardSrv,
|
|
|
|
private $location,
|
|
|
|
private backendSrv,
|
2017-10-24 03:43:48 -05:00
|
|
|
public playlistSrv,
|
2017-09-21 09:40:18 -05:00
|
|
|
navModelSrv) {
|
2017-06-02 07:00:42 -05: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 04:34:51 -06:00
|
|
|
if (meta.expires) {
|
2017-06-02 07:00:42 -05:00
|
|
|
this.titleTooltip += '<br>Expires: ' + moment(meta.expires).fromNow() + '<br>';
|
2016-01-17 04:34:51 -06:00
|
|
|
}
|
|
|
|
}
|
2017-06-02 07:00:42 -05:00
|
|
|
}
|
2013-09-13 15:52:13 -05:00
|
|
|
|
2017-12-08 08:53:26 -06:00
|
|
|
openSettings() {
|
|
|
|
let search = this.$location.search();
|
|
|
|
if (search.editview) {
|
|
|
|
delete search.editview;
|
|
|
|
} else {
|
|
|
|
search.editview = 'settings';
|
|
|
|
}
|
2017-06-02 07:00:42 -05:00
|
|
|
this.$location.search(search);
|
|
|
|
}
|
2013-09-13 15:52:13 -05:00
|
|
|
|
2017-06-02 07:00:42 -05:00
|
|
|
starDashboard() {
|
2017-11-15 08:01:44 -06:00
|
|
|
this.dashboardSrv.starDashboard(this.dashboard.id, this.dashboard.meta.isStarred)
|
|
|
|
.then(newState => {
|
|
|
|
this.dashboard.meta.isStarred = newState;
|
2017-06-02 07:00:42 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
shareDashboard(tabIndex) {
|
|
|
|
var modalScope = this.$scope.$new();
|
2016-01-29 10:48:57 -06:00
|
|
|
modalScope.tabIndex = tabIndex;
|
2017-06-02 07:00:42 -05:00
|
|
|
modalScope.dashboard = this.dashboard;
|
2016-01-29 10:48:57 -06:00
|
|
|
|
2017-06-02 07:00:42 -05:00
|
|
|
appEvents.emit('show-modal', {
|
2016-02-01 11:19:02 -06:00
|
|
|
src: 'public/app/features/dashboard/partials/shareModal.html',
|
2016-01-29 10:48:57 -06:00
|
|
|
scope: modalScope
|
2015-02-02 02:45:45 -06:00
|
|
|
});
|
2017-06-02 07:00:42 -05:00
|
|
|
}
|
2016-02-23 10:11:04 -06:00
|
|
|
|
2017-06-02 07:00:42 -05:00
|
|
|
hideTooltip(evt) {
|
2015-09-21 04:29:14 -05:00
|
|
|
angular.element(evt.currentTarget).tooltip('hide');
|
2017-06-02 07:00:42 -05:00
|
|
|
}
|
2015-09-18 02:45:29 -05:00
|
|
|
|
2017-06-02 07:00:42 -05:00
|
|
|
makeEditable() {
|
|
|
|
this.dashboard.editable = true;
|
2015-12-15 01:41:16 -06:00
|
|
|
|
2017-06-02 07:00:42 -05:00
|
|
|
return this.dashboardSrv.saveDashboard({makeEditable: true, overwrite: false}).then(() => {
|
2016-01-17 04:34:51 -06:00
|
|
|
// force refresh whole page
|
2015-12-15 01:41:16 -06:00
|
|
|
window.location.href = window.location.href;
|
2016-10-14 06:06:29 -05:00
|
|
|
});
|
2017-06-02 07:00:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
exitFullscreen() {
|
|
|
|
this.$rootScope.appEvent('panel-change-view', {fullscreen: false, edit: false});
|
|
|
|
}
|
2015-12-15 01:41:16 -06:00
|
|
|
|
2017-06-05 07:56:11 -05:00
|
|
|
saveDashboard() {
|
|
|
|
return this.dashboardSrv.saveDashboard();
|
2017-06-02 07:00:42 -05:00
|
|
|
}
|
2013-09-13 15:52:13 -05:00
|
|
|
|
2017-06-02 07:00:42 -05:00
|
|
|
deleteDashboard() {
|
2017-10-11 09:08:56 -05:00
|
|
|
var confirmText = '';
|
2017-06-02 07:00:42 -05:00
|
|
|
var text2 = this.dashboard.title;
|
2017-10-11 09:08:56 -05:00
|
|
|
|
|
|
|
const alerts = _.sumBy(this.dashboard.panels, panel => {
|
|
|
|
return panel.alert ? 1 : 0;
|
|
|
|
});
|
2016-05-16 04:32:08 -05:00
|
|
|
|
|
|
|
if (alerts > 0) {
|
2016-09-05 06:38:25 -05:00
|
|
|
confirmText = 'DELETE';
|
2017-10-11 09:08:56 -05:00
|
|
|
text2 = `This dashboard contains ${alerts} alerts. Deleting this dashboard will also delete those alerts`;
|
2016-05-16 04:32:08 -05:00
|
|
|
}
|
|
|
|
|
2017-06-02 07:00:42 -05:00
|
|
|
appEvents.emit('confirm-modal', {
|
2016-03-12 03:13:49 -06:00
|
|
|
title: 'Delete',
|
|
|
|
text: 'Do you want to delete this dashboard?',
|
2016-05-16 04:32:08 -05:00
|
|
|
text2: text2,
|
2015-03-05 14:02:25 -06:00
|
|
|
icon: 'fa-trash',
|
2016-05-16 04:32:08 -05:00
|
|
|
confirmText: confirmText,
|
2015-03-05 14:02:25 -06:00
|
|
|
yesText: 'Delete',
|
2017-06-02 07:00:42 -05:00
|
|
|
onConfirm: () => {
|
|
|
|
this.dashboard.meta.canSave = false;
|
|
|
|
this.deleteDashboardConfirmed();
|
2014-11-10 08:01:30 -06:00
|
|
|
}
|
|
|
|
});
|
2017-06-02 07:00:42 -05:00
|
|
|
}
|
2014-11-10 08:01:30 -06:00
|
|
|
|
2017-06-02 07:00:42 -05: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 10:40:37 -05:00
|
|
|
});
|
2017-06-02 07:00:42 -05:00
|
|
|
}
|
2014-06-13 06:50:09 -05:00
|
|
|
|
2017-06-02 07:00:42 -05:00
|
|
|
saveDashboardAs() {
|
2017-06-05 07:56:11 -05:00
|
|
|
return this.dashboardSrv.showSaveAsModal();
|
2017-06-02 07:00:42 -05:00
|
|
|
}
|
2015-02-18 03:44:36 -06:00
|
|
|
|
2017-06-02 07:00:42 -05:00
|
|
|
viewJson() {
|
|
|
|
var clone = this.dashboard.getSaveModelClone();
|
2017-08-08 04:26:16 -05:00
|
|
|
|
|
|
|
this.$rootScope.appEvent('show-json-editor', {
|
|
|
|
object: clone,
|
|
|
|
});
|
2017-06-02 07:00:42 -05:00
|
|
|
}
|
2017-06-01 16:32:33 -05:00
|
|
|
|
2017-06-23 15:00:26 -05:00
|
|
|
onFolderChange(folderId) {
|
|
|
|
this.dashboard.folderId = folderId;
|
2017-06-01 16:32:33 -05:00
|
|
|
}
|
2017-08-14 11:11:35 -05:00
|
|
|
|
|
|
|
showSearch() {
|
|
|
|
this.$rootScope.appEvent('show-dash-search');
|
|
|
|
}
|
|
|
|
|
2017-10-10 10:57:53 -05:00
|
|
|
addPanel() {
|
2017-10-17 07:53:52 -05:00
|
|
|
if (this.dashboard.panels.length > 0 && this.dashboard.panels[0].type === 'add-panel') {
|
2017-10-16 03:58:08 -05:00
|
|
|
this.dashboard.removePanel(this.dashboard.panels[0]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-10 10:57:53 -05:00
|
|
|
this.dashboard.addPanel({
|
2017-10-16 02:55:55 -05:00
|
|
|
type: 'add-panel',
|
2017-10-17 07:53:52 -05:00
|
|
|
gridPos: {x: 0, y: 0, w: 12, h: 9},
|
2017-12-01 13:11:55 -06:00
|
|
|
title: 'Panel Title',
|
2017-10-10 10:57:53 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-14 11:11:35 -05:00
|
|
|
navItemClicked(navItem, evt) {
|
|
|
|
if (navItem.clickHandler) {
|
|
|
|
navItem.clickHandler();
|
|
|
|
evt.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
2016-01-17 04:34:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
export function dashNavDirective() {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
2016-02-01 11:19:02 -06:00
|
|
|
templateUrl: 'public/app/features/dashboard/dashnav/dashnav.html',
|
2016-01-17 04:34:51 -06:00
|
|
|
controller: DashNavCtrl,
|
2017-06-02 07:00:42 -05:00
|
|
|
bindToController: true,
|
|
|
|
controllerAs: 'ctrl',
|
2016-01-17 04:34:51 -06:00
|
|
|
transclude: true,
|
2017-06-02 07:00:42 -05:00
|
|
|
scope: { dashboard: "=" }
|
2016-01-17 04:34:51 -06:00
|
|
|
};
|
|
|
|
}
|
2013-09-13 15:52:13 -05:00
|
|
|
|
2016-01-17 04:34:51 -06:00
|
|
|
angular.module('grafana.directives').directive('dashnav', dashNavDirective);
|