playlist_search.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import coreModule from '../../core/core_module';
  2. export class PlaylistSearchCtrl {
  3. query: any;
  4. tagsMode: boolean;
  5. searchStarted: any;
  6. /** @ngInject */
  7. constructor($timeout, private backendSrv) {
  8. this.query = { query: '', tag: [], starred: false, limit: 30 };
  9. $timeout(() => {
  10. this.query.query = '';
  11. this.query.type = 'dash-db';
  12. this.searchDashboards();
  13. }, 100);
  14. }
  15. searchDashboards() {
  16. this.tagsMode = false;
  17. var prom: any = {};
  18. prom.promise = this.backendSrv.search(this.query).then(result => {
  19. return {
  20. dashboardResult: result,
  21. tagResult: [],
  22. };
  23. });
  24. this.searchStarted(prom);
  25. }
  26. showStarred() {
  27. this.query.starred = !this.query.starred;
  28. this.searchDashboards();
  29. }
  30. queryHasNoFilters() {
  31. return this.query.query === '' && this.query.starred === false && this.query.tag.length === 0;
  32. }
  33. filterByTag(tag, evt) {
  34. this.query.tag.push(tag);
  35. this.searchDashboards();
  36. if (evt) {
  37. evt.stopPropagation();
  38. evt.preventDefault();
  39. }
  40. }
  41. getTags() {
  42. var prom: any = {};
  43. prom.promise = this.backendSrv.get('/api/dashboards/tags').then(result => {
  44. return {
  45. dashboardResult: [],
  46. tagResult: result,
  47. };
  48. });
  49. this.searchStarted(prom);
  50. }
  51. }
  52. export function playlistSearchDirective() {
  53. return {
  54. restrict: 'E',
  55. templateUrl: 'public/app/features/playlist/partials/playlist_search.html',
  56. controller: PlaylistSearchCtrl,
  57. bindToController: true,
  58. controllerAs: 'ctrl',
  59. scope: {
  60. searchStarted: '&',
  61. },
  62. };
  63. }
  64. coreModule.directive('playlistSearch', playlistSearchDirective);