Files
grafana/public/app/features/dashboard/dashnav/dashnav.ts

115 lines
2.9 KiB
TypeScript
Raw Normal View History

import moment from 'moment';
import angular from 'angular';
import {appEvents, NavModel} from 'app/core/core';
import {DashboardModel} from '../dashboard_model';
export class DashNavCtrl {
dashboard: DashboardModel;
navModel: NavModel;
titleTooltip: string;
/** @ngInject */
constructor(
private $scope,
private $rootScope,
private dashboardSrv,
private $location,
public playlistSrv) {
appEvents.on('save-dashboard', this.saveDashboard.bind(this), $scope);
if (this.dashboard.meta.isSnapshot) {
var meta = this.dashboard.meta;
this.titleTooltip = 'Created:  ' + moment(meta.created).calendar();
if (meta.expires) {
this.titleTooltip += '<br>Expires: &nbsp;' + moment(meta.expires).fromNow() + '<br>';
}
}
}
2013-09-13 13:52:13 -07:00
2017-12-08 18:15:24 +01:00
toggleSettings() {
2017-12-08 15:53:26 +01:00
let search = this.$location.search();
if (search.editview) {
delete search.editview;
} else {
search.editview = 'settings';
}
this.$location.search(search);
}
2013-09-13 13:52:13 -07:00
2017-12-09 22:45:33 +01:00
close() {
let search = this.$location.search();
if (search.editview) {
delete search.editview;
}
if (search.fullscreen) {
delete search.fullscreen;
delete search.edit;
}
this.$location.search(search);
}
starDashboard() {
this.dashboardSrv.starDashboard(this.dashboard.id, this.dashboard.meta.isStarred)
.then(newState => {
this.dashboard.meta.isStarred = newState;
});
}
shareDashboard(tabIndex) {
var modalScope = this.$scope.$new();
modalScope.tabIndex = tabIndex;
modalScope.dashboard = this.dashboard;
appEvents.emit('show-modal', {
src: 'public/app/features/dashboard/partials/shareModal.html',
scope: modalScope
});
}
2016-02-23 08:11:04 -08:00
hideTooltip(evt) {
angular.element(evt.currentTarget).tooltip('hide');
}
saveDashboard() {
return this.dashboardSrv.saveDashboard();
}
2013-09-13 13:52:13 -07:00
2017-08-14 18:11:35 +02:00
showSearch() {
this.$rootScope.appEvent('show-dash-search');
}
2017-10-10 17:57:53 +02:00
addPanel() {
2017-10-17 14:53:52 +02:00
if (this.dashboard.panels.length > 0 && this.dashboard.panels[0].type === 'add-panel') {
this.dashboard.removePanel(this.dashboard.panels[0]);
return;
}
2017-10-10 17:57:53 +02:00
this.dashboard.addPanel({
2017-10-16 09:55:55 +02:00
type: 'add-panel',
2017-10-17 14:53:52 +02:00
gridPos: {x: 0, y: 0, w: 12, h: 9},
title: 'Panel Title',
2017-10-10 17:57:53 +02:00
});
}
2017-08-14 18:11:35 +02:00
navItemClicked(navItem, evt) {
if (navItem.clickHandler) {
navItem.clickHandler();
evt.preventDefault();
}
}
}
export function dashNavDirective() {
return {
restrict: 'E',
templateUrl: 'public/app/features/dashboard/dashnav/dashnav.html',
controller: DashNavCtrl,
bindToController: true,
controllerAs: 'ctrl',
transclude: true,
scope: { dashboard: "=" }
};
}
2013-09-13 13:52:13 -07:00
angular.module('grafana.directives').directive('dashnav', dashNavDirective);