playlist_search.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.searchDashboards();
  12. }, 100);
  13. }
  14. searchDashboards() {
  15. this.tagsMode = false;
  16. var prom: any = {};
  17. prom.promise = this.backendSrv.search(this.query).then(result => {
  18. return {
  19. dashboardResult: result,
  20. tagResult: [],
  21. };
  22. });
  23. this.searchStarted(prom);
  24. }
  25. showStarred() {
  26. this.query.starred = !this.query.starred;
  27. this.searchDashboards();
  28. }
  29. queryHasNoFilters() {
  30. return this.query.query === '' && this.query.starred === false && this.query.tag.length === 0;
  31. }
  32. filterByTag(tag, evt) {
  33. this.query.tag.push(tag);
  34. this.searchDashboards();
  35. if (evt) {
  36. evt.stopPropagation();
  37. evt.preventDefault();
  38. }
  39. }
  40. getTags() {
  41. var prom: any = {};
  42. prom.promise = this.backendSrv.get('/api/dashboards/tags').then(result => {
  43. return {
  44. dashboardResult: [],
  45. tagResult: result,
  46. };
  47. });
  48. this.searchStarted(prom);
  49. }
  50. }
  51. export function playlistSearchDirective() {
  52. return {
  53. restrict: 'E',
  54. templateUrl: 'public/app/features/playlist/partials/playlist_search.html',
  55. controller: PlaylistSearchCtrl,
  56. bindToController: true,
  57. controllerAs: 'ctrl',
  58. scope: {
  59. searchStarted: '&',
  60. },
  61. };
  62. }
  63. coreModule.directive('playlistSearch', playlistSearchDirective);