playlist_search.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ///<reference path="../../headers/common.d.ts" />
  2. import coreModule from '../../core/core_module';
  3. export class PlaylistSearchCtrl {
  4. query: any;
  5. tagsMode: boolean;
  6. searchStarted: any;
  7. /** @ngInject */
  8. constructor($timeout, private backendSrv) {
  9. this.query = {query: '', tag: [], starred: false, limit: 30};
  10. $timeout(() => {
  11. this.query.query = '';
  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);