playlist_search.ts 1.7 KB

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