editor.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import angular from "angular";
  2. import _ from "lodash";
  3. export var iconMap = {
  4. "external link": "fa-external-link",
  5. dashboard: "fa-th-large",
  6. question: "fa-question",
  7. info: "fa-info",
  8. bolt: "fa-bolt",
  9. doc: "fa-file-text-o",
  10. cloud: "fa-cloud"
  11. };
  12. export class DashLinkEditorCtrl {
  13. dashboard: any;
  14. iconMap: any;
  15. mode: any;
  16. link: any;
  17. /** @ngInject */
  18. constructor($scope, $rootScope) {
  19. this.iconMap = iconMap;
  20. this.dashboard.links = this.dashboard.links || [];
  21. this.mode = "list";
  22. $scope.$on("$destroy", () => {
  23. $rootScope.appEvent("dash-links-updated");
  24. });
  25. }
  26. backToList() {
  27. this.mode = "list";
  28. }
  29. setupNew() {
  30. this.mode = "new";
  31. this.link = { type: "dashboards", icon: "external link" };
  32. }
  33. addLink() {
  34. this.dashboard.links.push(this.link);
  35. this.mode = "list";
  36. }
  37. editLink(link) {
  38. this.link = link;
  39. this.mode = "edit";
  40. console.log(this.link);
  41. }
  42. saveLink() {
  43. this.backToList();
  44. }
  45. moveLink(index, dir) {
  46. _.move(this.dashboard.links, index, index + dir);
  47. }
  48. deleteLink(index) {
  49. this.dashboard.links.splice(index, 1);
  50. this.dashboard.updateSubmenuVisibility();
  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
  66. .module("grafana.directives")
  67. .directive("dashLinksEditor", dashLinksEditor);