DashLinksEditorCtrl.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. emptyListCta = {
  19. title: 'There are no dashboard links added yet',
  20. buttonIcon: 'gicon gicon-link',
  21. buttonTitle: 'Add Dashboard Link',
  22. infoBox: {
  23. __html: `<p>
  24. Dashboard Links allow you to place links to other dashboards and web sites directly in below the dashboard
  25. header.
  26. </p>`,
  27. },
  28. infoBoxTitle: 'What are Dashboard Links?',
  29. };
  30. /** @ngInject */
  31. constructor($scope: any, $rootScope: any) {
  32. this.iconMap = iconMap;
  33. this.dashboard.links = this.dashboard.links || [];
  34. this.mode = 'list';
  35. $scope.$on('$destroy', () => {
  36. $rootScope.appEvent('dash-links-updated');
  37. });
  38. }
  39. backToList() {
  40. this.mode = 'list';
  41. }
  42. setupNew = () => {
  43. this.mode = 'new';
  44. this.link = { type: 'dashboards', icon: 'external link' };
  45. };
  46. addLink() {
  47. this.dashboard.links.push(this.link);
  48. this.mode = 'list';
  49. this.dashboard.updateSubmenuVisibility();
  50. }
  51. editLink(link: any) {
  52. this.link = link;
  53. this.mode = 'edit';
  54. console.log(this.link);
  55. }
  56. saveLink() {
  57. this.backToList();
  58. }
  59. moveLink(index: string | number, dir: string | number) {
  60. // @ts-ignore
  61. _.move(this.dashboard.links, index, index + dir);
  62. }
  63. deleteLink(index: number) {
  64. this.dashboard.links.splice(index, 1);
  65. this.dashboard.updateSubmenuVisibility();
  66. }
  67. }
  68. function dashLinksEditor() {
  69. return {
  70. restrict: 'E',
  71. controller: DashLinksEditorCtrl,
  72. templateUrl: 'public/app/features/dashboard/components/DashLinks/editor.html',
  73. bindToController: true,
  74. controllerAs: 'ctrl',
  75. scope: {
  76. dashboard: '=',
  77. },
  78. };
  79. }
  80. angular.module('grafana.directives').directive('dashLinksEditor', dashLinksEditor);