2017-12-20 12:33:33 +01:00
|
|
|
import moment from 'moment';
|
|
|
|
|
import angular from 'angular';
|
|
|
|
|
import { appEvents, NavModel } from 'app/core/core';
|
|
|
|
|
import { DashboardModel } from '../dashboard_model';
|
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-12-21 08:39:31 +01:00
|
|
|
constructor(private $scope, private dashboardSrv, private $location, public playlistSrv) {
|
2017-12-20 12:33:33 +01:00
|
|
|
appEvents.on('save-dashboard', this.saveDashboard.bind(this), $scope);
|
2017-12-19 16:06:54 +01:00
|
|
|
|
|
|
|
|
if (this.dashboard.meta.isSnapshot) {
|
|
|
|
|
var meta = this.dashboard.meta;
|
2017-12-20 12:33:33 +01:00
|
|
|
this.titleTooltip = 'Created: ' + moment(meta.created).calendar();
|
2017-12-19 16:06:54 +01:00
|
|
|
if (meta.expires) {
|
2017-12-21 08:39:31 +01: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
|
|
|
}
|
2017-12-19 16:06:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleSettings() {
|
|
|
|
|
let search = this.$location.search();
|
|
|
|
|
if (search.editview) {
|
|
|
|
|
delete search.editview;
|
|
|
|
|
} else {
|
2017-12-20 12:33:33 +01:00
|
|
|
search.editview = 'settings';
|
2017-06-02 14:00:42 +02:00
|
|
|
}
|
2017-12-19 16:06:54 +01:00
|
|
|
this.$location.search(search);
|
|
|
|
|
}
|
2015-09-18 00:45:29 -07:00
|
|
|
|
2017-12-19 16:06:54 +01:00
|
|
|
close() {
|
|
|
|
|
let search = this.$location.search();
|
|
|
|
|
if (search.editview) {
|
|
|
|
|
delete search.editview;
|
2017-06-02 14:00:42 +02:00
|
|
|
}
|
2017-12-19 16:06:54 +01:00
|
|
|
if (search.fullscreen) {
|
|
|
|
|
delete search.fullscreen;
|
|
|
|
|
delete search.edit;
|
2017-08-14 18:11:35 +02:00
|
|
|
}
|
2017-12-19 16:06:54 +01:00
|
|
|
this.$location.search(search);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
starDashboard() {
|
2017-12-21 08:39:31 +01:00
|
|
|
this.dashboardSrv.starDashboard(this.dashboard.id, this.dashboard.meta.isStarred).then(newState => {
|
|
|
|
|
this.dashboard.meta.isStarred = newState;
|
|
|
|
|
});
|
2017-12-19 16:06:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shareDashboard(tabIndex) {
|
|
|
|
|
var modalScope = this.$scope.$new();
|
|
|
|
|
modalScope.tabIndex = tabIndex;
|
|
|
|
|
modalScope.dashboard = this.dashboard;
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
appEvents.emit('show-modal', {
|
|
|
|
|
src: 'public/app/features/dashboard/partials/shareModal.html',
|
|
|
|
|
scope: modalScope,
|
2017-12-19 16:06:54 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hideTooltip(evt) {
|
2017-12-20 12:33:33 +01:00
|
|
|
angular.element(evt.currentTarget).tooltip('hide');
|
2017-12-19 16:06:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveDashboard() {
|
|
|
|
|
return this.dashboardSrv.saveDashboard();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showSearch() {
|
2017-12-20 12:33:33 +01:00
|
|
|
appEvents.emit('show-dash-search');
|
2017-12-19 16:06:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addPanel() {
|
2017-12-21 08:39:31 +01:00
|
|
|
if (this.dashboard.panels.length > 0 && this.dashboard.panels[0].type === 'add-panel') {
|
2017-12-19 16:06:54 +01:00
|
|
|
this.dashboard.removePanel(this.dashboard.panels[0]);
|
|
|
|
|
return;
|
2017-10-10 17:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
2017-12-19 16:06:54 +01:00
|
|
|
this.dashboard.addPanel({
|
2017-12-20 12:33:33 +01:00
|
|
|
type: 'add-panel',
|
2017-12-19 16:06:54 +01:00
|
|
|
gridPos: { x: 0, y: 0, w: 12, h: 9 },
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'Panel Title',
|
2017-12-19 16:06:54 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
navItemClicked(navItem, evt) {
|
|
|
|
|
if (navItem.clickHandler) {
|
|
|
|
|
navItem.clickHandler();
|
|
|
|
|
evt.preventDefault();
|
2017-08-14 18:11:35 +02:00
|
|
|
}
|
2017-12-19 16:06:54 +01:00
|
|
|
}
|
2016-01-17 11:34:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function dashNavDirective() {
|
|
|
|
|
return {
|
2017-12-20 12:33:33 +01:00
|
|
|
restrict: 'E',
|
|
|
|
|
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,
|
2017-12-20 12:33:33 +01:00
|
|
|
controllerAs: 'ctrl',
|
2016-01-17 11:34:51 +01:00
|
|
|
transclude: true,
|
2017-12-20 12:33:33 +01:00
|
|
|
scope: { dashboard: '=' },
|
2016-01-17 11:34:51 +01:00
|
|
|
};
|
|
|
|
|
}
|
2013-09-13 13:52:13 -07:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
angular.module('grafana.directives').directive('dashnav', dashNavDirective);
|