playlist_search.ts 1.8 KB

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