module.js 1.4 KB

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