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

81 lines
1.6 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';
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;
/** @ngInject */
constructor($scope, $rootScope) {
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('dash-links-updated');
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
}
2017-12-13 02:44:51 -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
2017-12-13 02:44:51 -06:00
editLink(link) {
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, dir) {
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) {
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);