2016-10-31 22:40:53 +00:00
|
|
|
import moment from 'moment';
|
2017-01-02 09:22:09 +00:00
|
|
|
|
|
|
|
import { LivePaginator } from '../../utils';
|
2016-11-02 10:56:44 +00:00
|
|
|
import template from './queries-list.html';
|
2016-10-31 22:40:53 +00:00
|
|
|
|
|
|
|
class QueriesListCtrl {
|
2017-01-02 09:22:09 +00:00
|
|
|
constructor($location, Title, Query) {
|
2016-10-31 22:40:53 +00:00
|
|
|
const page = parseInt($location.search().page || 1, 10);
|
|
|
|
|
|
|
|
this.defaultOptions = {};
|
|
|
|
|
|
|
|
const self = this;
|
|
|
|
|
|
|
|
switch ($location.path()) {
|
|
|
|
case '/queries':
|
2016-11-27 13:49:17 +00:00
|
|
|
Title.set('Queries');
|
2016-10-31 22:40:53 +00:00
|
|
|
this.resource = Query.query;
|
|
|
|
break;
|
|
|
|
case '/queries/my':
|
2016-11-27 13:49:17 +00:00
|
|
|
Title.set('My Queries');
|
2016-10-31 22:40:53 +00:00
|
|
|
this.resource = Query.myQueries;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-02 09:22:09 +00:00
|
|
|
function queriesFetcher(requestedPage, itemsPerPage, paginator) {
|
|
|
|
$location.search('page', requestedPage);
|
|
|
|
|
2017-10-03 17:21:36 +00:00
|
|
|
const request = Object.assign(
|
|
|
|
{}, self.defaultOptions,
|
|
|
|
{ page: requestedPage, page_size: itemsPerPage },
|
|
|
|
);
|
2017-01-02 09:22:09 +00:00
|
|
|
|
|
|
|
return self.resource(request).$promise.then((data) => {
|
|
|
|
const rows = data.results.map((query) => {
|
|
|
|
query.created_at = moment(query.created_at);
|
|
|
|
query.retrieved_at = moment(query.retrieved_at);
|
|
|
|
return query;
|
|
|
|
});
|
|
|
|
|
|
|
|
paginator.updateRows(rows, data.count);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.paginator = new LivePaginator(queriesFetcher, { page });
|
|
|
|
|
2016-10-31 22:40:53 +00:00
|
|
|
this.tabs = [
|
|
|
|
{ name: 'My Queries', path: 'queries/my' },
|
|
|
|
{ path: 'queries', name: 'All Queries', isActive: path => path === '/queries' },
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-03 17:21:36 +00:00
|
|
|
export default function init(ngModule) {
|
2016-10-31 22:40:53 +00:00
|
|
|
ngModule.component('pageQueriesList', {
|
|
|
|
template,
|
|
|
|
controller: QueriesListCtrl,
|
|
|
|
});
|
|
|
|
|
|
|
|
const route = {
|
|
|
|
template: '<page-queries-list></page-queries-list>',
|
|
|
|
reloadOnSearch: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
'/queries': route,
|
|
|
|
'/queries/my': route,
|
|
|
|
};
|
|
|
|
}
|