grafana/public/app/features/playlist/playlist_search.ts

78 lines
1.6 KiB
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import coreModule from '../../core/core_module';
export class PlaylistSearchCtrl {
query: any;
tagsMode: boolean;
searchStarted: any;
/** @ngInject */
constructor($timeout, private backendSrv) {
2017-12-20 05:33:33 -06:00
this.query = { query: '', tag: [], starred: false, limit: 30 };
$timeout(() => {
2017-12-20 05:33:33 -06:00
this.query.query = '';
this.searchDashboards();
}, 100);
}
searchDashboards() {
this.tagsMode = false;
var prom: any = {};
prom.promise = this.backendSrv.search(this.query).then(result => {
return {
dashboardResult: result,
2017-12-20 05:33:33 -06:00
tagResult: [],
};
});
this.searchStarted(prom);
}
2016-01-28 15:43:54 -06:00
showStarred() {
this.query.starred = !this.query.starred;
this.searchDashboards();
}
2016-01-28 15:43:54 -06:00
queryHasNoFilters() {
return this.query.query === '' && this.query.starred === false && this.query.tag.length === 0;
}
filterByTag(tag, evt) {
this.query.tag.push(tag);
this.searchDashboards();
if (evt) {
evt.stopPropagation();
evt.preventDefault();
}
}
getTags() {
var prom: any = {};
2017-12-20 05:33:33 -06:00
prom.promise = this.backendSrv.get('/api/dashboards/tags').then(result => {
return {
dashboardResult: [],
2017-12-20 05:33:33 -06:00
tagResult: result,
};
});
this.searchStarted(prom);
}
}
export function playlistSearchDirective() {
return {
2017-12-20 05:33:33 -06:00
restrict: 'E',
templateUrl: 'public/app/features/playlist/partials/playlist_search.html',
controller: PlaylistSearchCtrl,
bindToController: true,
2017-12-20 05:33:33 -06:00
controllerAs: 'ctrl',
scope: {
2017-12-20 05:33:33 -06:00
searchStarted: '&',
},
};
}
2017-12-20 05:33:33 -06:00
coreModule.directive('playlistSearch', playlistSearchDirective);