editor.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import angular from 'angular';
  2. import _ from 'lodash';
  3. import appEvents from 'app/core/app_events';
  4. export var 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 DashLinkEditorCtrl {
  14. dashboard: any;
  15. iconMap: any;
  16. mode: any;
  17. link: any;
  18. currentLink: any;
  19. /** @ngInject */
  20. constructor($scope, $rootScope) {
  21. this.iconMap = iconMap;
  22. this.dashboard.links = this.dashboard.links || [];
  23. this.mode = 'list';
  24. }
  25. backToList() {
  26. this.mode = 'list';
  27. }
  28. addLink() {
  29. this.dashboard.links.push({ type: 'dashboard', icon: 'external link' });
  30. this.dashboard.updateSubmenuVisibility();
  31. this.updated();
  32. this.mode = 'new';
  33. }
  34. editLink(index) {
  35. }
  36. saveLink() {
  37. this.updated();
  38. this.backToList();
  39. }
  40. moveLink(index, dir) {
  41. _.move(this.dashboard.links, index, index+dir);
  42. this.updated();
  43. }
  44. updated() {
  45. appEvents.emit('dash-links-updated');
  46. }
  47. deleteLink(index) {
  48. this.dashboard.links.splice(index, 1);
  49. //this.dashboard.updateSubmenuVisibility();
  50. this.updated();
  51. }
  52. }
  53. function dashLinksEditor() {
  54. return {
  55. restrict: 'E',
  56. controller: DashLinkEditorCtrl,
  57. templateUrl: 'public/app/features/dashlinks/editor.html',
  58. bindToController: true,
  59. controllerAs: 'ctrl',
  60. scope: {
  61. dashboard: "="
  62. }
  63. };
  64. }
  65. angular.module('grafana.directives').directive('dashLinksEditor', dashLinksEditor);