dashSearchView.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. define([
  2. 'angular',
  3. 'jquery'
  4. ],
  5. function (angular, $) {
  6. 'use strict';
  7. angular
  8. .module('grafana.directives')
  9. .directive('dashSearchView', function($compile) {
  10. return {
  11. restrict: 'A',
  12. link: function(scope, elem) {
  13. var editorScope;
  14. var ignoreHide;
  15. function showSearch() {
  16. if (editorScope) {
  17. editorScope.dismiss();
  18. return;
  19. }
  20. ignoreHide = true;
  21. editorScope = scope.$new();
  22. editorScope.dismiss = function() {
  23. editorScope.$destroy();
  24. elem.empty();
  25. elem.unbind();
  26. editorScope = null;
  27. };
  28. var view = $('<search class="search-container" dismiss="dismiss()"></search>');
  29. elem.append(view);
  30. $compile(elem.contents())(editorScope);
  31. setTimeout(function() {
  32. ignoreHide = false;
  33. }, 300);
  34. }
  35. function hideSearch() {
  36. if (editorScope && !ignoreHide) {
  37. editorScope.dismiss();
  38. }
  39. }
  40. scope.onAppEvent('show-dash-search', showSearch);
  41. scope.onAppEvent('hide-dash-search', hideSearch);
  42. }
  43. };
  44. });
  45. });