module.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import angular from 'angular';
  2. import _ from 'lodash';
  3. import './link_srv';
  4. function panelLinksEditor() {
  5. return {
  6. scope: {
  7. panel: '=',
  8. },
  9. restrict: 'E',
  10. controller: 'PanelLinksEditorCtrl',
  11. templateUrl: 'public/app/features/panellinks/module.html',
  12. link: function() {},
  13. };
  14. }
  15. export class PanelLinksEditorCtrl {
  16. /** @ngInject */
  17. constructor($scope, backendSrv) {
  18. $scope.panel.links = $scope.panel.links || [];
  19. $scope.addLink = function() {
  20. $scope.panel.links.push({
  21. type: 'dashboard',
  22. });
  23. };
  24. $scope.searchDashboards = function(queryStr, callback) {
  25. backendSrv.search({ query: queryStr }).then(function(hits) {
  26. const dashboards = _.map(hits, function(dash) {
  27. return dash.title;
  28. });
  29. callback(dashboards);
  30. });
  31. };
  32. $scope.dashboardChanged = function(link) {
  33. backendSrv.search({ query: link.dashboard }).then(function(hits) {
  34. const dashboard = _.find(hits, { title: link.dashboard });
  35. if (dashboard) {
  36. if (dashboard.url) {
  37. link.url = dashboard.url;
  38. } else {
  39. // To support legacy url's
  40. link.dashUri = dashboard.uri;
  41. }
  42. link.title = dashboard.title;
  43. }
  44. });
  45. };
  46. $scope.deleteLink = function(link) {
  47. $scope.panel.links = _.without($scope.panel.links, link);
  48. };
  49. }
  50. }
  51. angular
  52. .module('grafana.directives')
  53. .directive('panelLinksEditor', panelLinksEditor)
  54. .controller('PanelLinksEditorCtrl', PanelLinksEditorCtrl);