DashLinksEditorCtrl.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import angular from 'angular';
  2. import _ from 'lodash';
  3. import { DashboardModel } from 'app/features/dashboard/state';
  4. export let iconMap = {
  5. 'external link': 'fa-external-link',
  6. dashboard: 'fa-th-large',
  7. question: 'fa-question',
  8. info: 'fa-info',
  9. bolt: 'fa-bolt',
  10. doc: 'fa-file-text-o',
  11. cloud: 'fa-cloud',
  12. };
  13. export class DashLinksEditorCtrl {
  14. dashboard: DashboardModel;
  15. iconMap: any;
  16. mode: any;
  17. link: any;
  18. /** @ngInject */
  19. constructor($scope, $rootScope) {
  20. this.iconMap = iconMap;
  21. this.dashboard.links = this.dashboard.links || [];
  22. this.mode = 'list';
  23. $scope.$on('$destroy', () => {
  24. $rootScope.appEvent('dash-links-updated');
  25. });
  26. }
  27. backToList() {
  28. this.mode = 'list';
  29. }
  30. setupNew() {
  31. this.mode = 'new';
  32. this.link = { type: 'dashboards', icon: 'external link' };
  33. }
  34. addLink() {
  35. this.dashboard.links.push(this.link);
  36. this.mode = 'list';
  37. this.dashboard.updateSubmenuVisibility();
  38. }
  39. editLink(link) {
  40. this.link = link;
  41. this.mode = 'edit';
  42. console.log(this.link);
  43. }
  44. saveLink() {
  45. this.backToList();
  46. }
  47. moveLink(index, dir) {
  48. // @ts-ignore
  49. _.move(this.dashboard.links, index, index + dir);
  50. }
  51. deleteLink(index) {
  52. this.dashboard.links.splice(index, 1);
  53. this.dashboard.updateSubmenuVisibility();
  54. }
  55. }
  56. function dashLinksEditor() {
  57. return {
  58. restrict: 'E',
  59. controller: DashLinksEditorCtrl,
  60. templateUrl: 'public/app/features/dashboard/components/DashLinks/editor.html',
  61. bindToController: true,
  62. controllerAs: 'ctrl',
  63. scope: {
  64. dashboard: '=',
  65. },
  66. };
  67. }
  68. angular.module('grafana.directives').directive('dashLinksEditor', dashLinksEditor);