redash/client/app/pages/queries/queries-search-results-page.js
Arik Fraimovich febe908e65 Revise drafts flow for queries:
* Draft queries are now called "Unpublished" -- felt like it better convey the feature.
* Unpublished queries won't be shown in "All Queries" for non owners, but will appear in
  search.
* You can't add unpublished queries to dashboards or alerts.
2017-01-25 16:55:39 +02:00

45 lines
1.1 KiB
JavaScript

import moment from 'moment';
import { isString } from 'underscore';
import { Paginator } from '../../utils';
import template from './queries-search-results-page.html';
function QuerySearchCtrl($location, $filter, currentUser, Events, Query) {
this.term = $location.search().q;
this.paginator = new Paginator([], { itemsPerPage: 20 });
Query.search({ q: this.term, include_drafts: true }, (results) => {
const queries = results.map((query) => {
query.created_at = moment(query.created_at);
return query;
});
this.paginator.updateRows(queries);
});
this.search = () => {
if (!isString(this.term) || this.term.trim() === '') {
this.paginator.updateRows([]);
} else {
$location.search({ q: this.term });
}
};
Events.record('search', 'query', '', { term: this.term });
}
export default function (ngModule) {
ngModule.component('queriesSearchResultsPage', {
template,
controller: QuerySearchCtrl,
});
return {
'/queries/search': {
template: '<queries-search-results-page></queries-search-results-page>',
reloadOnSearch: true,
title: 'Queries Search',
},
};
}