2017-12-20 05:33:33 -06:00
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
2019-02-04 04:19:45 -06:00
|
|
|
import { DashboardModel } from 'app/features/dashboard/state';
|
2019-10-14 03:27:47 -05:00
|
|
|
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
|
|
|
|
import { CoreEvents } from 'app/types';
|
2017-12-12 04:21:32 -06:00
|
|
|
|
2018-08-30 01:58:43 -05: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
|
|
|
};
|
|
|
|
|
2019-01-22 14:36:36 -06:00
|
|
|
export class DashLinksEditorCtrl {
|
2019-02-04 04:19:45 -06:00
|
|
|
dashboard: DashboardModel;
|
2017-12-12 04:21:32 -06:00
|
|
|
iconMap: any;
|
|
|
|
mode: any;
|
|
|
|
link: any;
|
|
|
|
|
2019-08-20 10:19:21 -05:00
|
|
|
emptyListCta = {
|
|
|
|
title: 'There are no dashboard links added yet',
|
2020-04-12 15:20:02 -05:00
|
|
|
buttonIcon: 'link',
|
2019-08-20 10:19:21 -05:00
|
|
|
buttonTitle: 'Add Dashboard Link',
|
|
|
|
infoBox: {
|
|
|
|
__html: `<p>
|
2020-02-06 12:23:38 -06:00
|
|
|
Dashboard Links allow you to place links to other dashboards and web sites directly below the dashboard
|
2019-08-20 10:19:21 -05:00
|
|
|
header.
|
|
|
|
</p>`,
|
|
|
|
},
|
|
|
|
infoBoxTitle: 'What are Dashboard Links?',
|
|
|
|
};
|
|
|
|
|
2017-12-12 04:21:32 -06:00
|
|
|
/** @ngInject */
|
2019-10-14 03:27:47 -05:00
|
|
|
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', () => {
|
2019-10-14 03:27:47 -05:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
2019-08-20 10:19:21 -05:00
|
|
|
setupNew = () => {
|
2017-12-20 05:33:33 -06:00
|
|
|
this.mode = 'new';
|
|
|
|
this.link = { type: 'dashboards', icon: 'external link' };
|
2019-08-20 10:19:21 -05:00
|
|
|
};
|
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';
|
2019-02-04 04:19:45 -06:00
|
|
|
this.dashboard.updateSubmenuVisibility();
|
2017-12-13 02:44:51 -06:00
|
|
|
}
|
2017-12-12 04:21:32 -06:00
|
|
|
|
2019-08-01 07:38:34 -05: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
|
|
|
}
|
|
|
|
|
2019-08-01 07:38:34 -05: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
|
|
|
}
|
|
|
|
|
2019-08-01 07:38:34 -05: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',
|
2019-01-22 14:36:36 -06:00
|
|
|
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
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-21 01:39:31 -06:00
|
|
|
angular.module('grafana.directives').directive('dashLinksEditor', dashLinksEditor);
|