grafana/public/app/features/dashboard/components/DashLinks/DashLinksEditorCtrl.ts

97 lines
2.2 KiB
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import angular from 'angular';
import _ from 'lodash';
import { DashboardModel } from 'app/features/dashboard/state';
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
import { CoreEvents } from 'app/types';
2017-12-12 04:21:32 -06:00
export let iconMap = {
2017-12-20 05:33:33 -06:00
'external link': 'fa-external-link',
dashboard: 'fa-th-large',
question: 'fa-question',
info: 'fa-info',
bolt: 'fa-bolt',
doc: 'fa-file-text-o',
cloud: 'fa-cloud',
2017-12-12 04:21:32 -06:00
};
export class DashLinksEditorCtrl {
dashboard: DashboardModel;
2017-12-12 04:21:32 -06:00
iconMap: any;
mode: any;
link: any;
emptyListCta = {
title: 'There are no dashboard links added yet',
buttonIcon: 'link',
buttonTitle: 'Add Dashboard Link',
infoBox: {
__html: `<p>
Dashboard Links allow you to place links to other dashboards and web sites directly below the dashboard
header.
</p>`,
},
infoBoxTitle: 'What are Dashboard Links?',
};
2017-12-12 04:21:32 -06:00
/** @ngInject */
constructor($scope: any, $rootScope: GrafanaRootScope) {
2017-12-12 04:21:32 -06:00
this.iconMap = iconMap;
this.dashboard.links = this.dashboard.links || [];
2017-12-20 05:33:33 -06:00
this.mode = 'list';
2017-12-13 02:44:51 -06:00
2017-12-20 05:33:33 -06:00
$scope.$on('$destroy', () => {
$rootScope.appEvent(CoreEvents.dashLinksUpdated);
2017-12-13 02:44:51 -06:00
});
2017-12-12 04:21:32 -06:00
}
backToList() {
2017-12-20 05:33:33 -06:00
this.mode = 'list';
2017-12-12 04:21:32 -06:00
}
setupNew = () => {
2017-12-20 05:33:33 -06:00
this.mode = 'new';
this.link = { type: 'dashboards', icon: 'external link' };
};
2017-12-12 04:21:32 -06:00
2017-12-13 02:44:51 -06:00
addLink() {
this.dashboard.links.push(this.link);
2017-12-20 05:33:33 -06:00
this.mode = 'list';
this.dashboard.updateSubmenuVisibility();
2017-12-13 02:44:51 -06:00
}
2017-12-12 04:21:32 -06:00
editLink(link: any) {
2017-12-13 02:44:51 -06:00
this.link = link;
2017-12-20 05:33:33 -06:00
this.mode = 'edit';
2017-12-13 02:44:51 -06:00
console.log(this.link);
2017-12-12 04:21:32 -06:00
}
2017-12-12 07:05:24 -06:00
saveLink() {
this.backToList();
2017-12-12 04:21:32 -06:00
}
moveLink(index: string | number, dir: string | number) {
2019-04-15 05:11:52 -05:00
// @ts-ignore
2017-12-13 02:44:51 -06:00
_.move(this.dashboard.links, index, index + dir);
2017-12-12 04:21:32 -06:00
}
deleteLink(index: number) {
2017-12-12 04:21:32 -06:00
this.dashboard.links.splice(index, 1);
2017-12-13 02:44:51 -06:00
this.dashboard.updateSubmenuVisibility();
2017-12-12 04:21:32 -06:00
}
}
function dashLinksEditor() {
return {
2017-12-20 05:33:33 -06:00
restrict: 'E',
controller: DashLinksEditorCtrl,
templateUrl: 'public/app/features/dashboard/components/DashLinks/editor.html',
2017-12-12 04:21:32 -06:00
bindToController: true,
2017-12-20 05:33:33 -06:00
controllerAs: 'ctrl',
2017-12-12 04:21:32 -06:00
scope: {
2017-12-20 05:33:33 -06:00
dashboard: '=',
},
2017-12-12 04:21:32 -06:00
};
}
angular.module('grafana.directives').directive('dashLinksEditor', dashLinksEditor);