module.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. var 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. var dashboard = _.find(hits, { title: link.dashboard });
  35. if (dashboard) {
  36. link.dashUri = dashboard.uri;
  37. link.title = dashboard.title;
  38. }
  39. });
  40. };
  41. $scope.deleteLink = function(link) {
  42. $scope.panel.links = _.without($scope.panel.links, link);
  43. };
  44. }
  45. }
  46. angular
  47. .module('grafana.directives')
  48. .directive('panelLinksEditor', panelLinksEditor)
  49. .controller('PanelLinksEditorCtrl', PanelLinksEditorCtrl);