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