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. }
  16. export class PanelLinksEditorCtrl {
  17. /** @ngInject */
  18. constructor($scope, backendSrv) {
  19. $scope.panel.links = $scope.panel.links || [];
  20. $scope.addLink = function() {
  21. $scope.panel.links.push({
  22. type: 'dashboard',
  23. });
  24. };
  25. $scope.searchDashboards = function(queryStr, callback) {
  26. backendSrv.search({query: queryStr}).then(function(hits) {
  27. var dashboards = _.map(hits, function(dash) {
  28. return dash.title;
  29. });
  30. callback(dashboards);
  31. });
  32. };
  33. $scope.dashboardChanged = function(link) {
  34. backendSrv.search({query: link.dashboard}).then(function(hits) {
  35. var dashboard = _.find(hits, {title: link.dashboard});
  36. if (dashboard) {
  37. link.dashUri = dashboard.uri;
  38. link.title = dashboard.title;
  39. }
  40. });
  41. };
  42. $scope.deleteLink = function(link) {
  43. $scope.panel.links = _.without($scope.panel.links, link);
  44. };
  45. }
  46. }
  47. angular.module('grafana.directives').directive('panelLinksEditor', panelLinksEditor)
  48. .controller('PanelLinksEditorCtrl', PanelLinksEditorCtrl);