in public/src/js/models/collections/latest-articles.js [22:96]
constructor(options) {
super();
var opts = this.opts = options || {};
var pageSize = CONST.searchPageSize || 25,
showingDrafts = opts.showingDrafts;
this.articles = ko.observableArray();
this.message = ko.observable();
this.term = ko.observable(parseQueryParams().q || '');
this.term.subscribe(() => this.search());
this.autocompleteValue = ko.observable({
query: '',
param: 'section'
});
this.autocompleteValue.subscribe(() => this.search());
this.lastSearch = ko.observable({});
this.page = ko.observable(1);
this.totalPages = ko.observable(1);
this.title = ko.computed(() => {
var lastSearch = this.lastSearch(),
title = 'latest';
if (lastSearch && lastSearch.filter) {
title += ' in ' + lastSearch.filter;
}
return title;
}, this);
this.listenOn(mediator, 'set:article:to:visited', this.setArticleToVisited);
this[debounceSym] = debounce((opts = {}) => {
if (!opts.noFlushFirst) {
this.flush('searching...');
}
var request = {
isDraft: showingDrafts(),
page: this.page(),
pageSize: pageSize,
filter: this.autocompleteValue().query,
filterType: this.autocompleteValue().param,
isPoll: opts.isPoll
};
var term = this.term();
// If term contains slashes, assume it's an article id (and first convert it to a path)
if (this.isTermAnItem()) {
term = urlAbsPath(term);
this.term(term);
request.article = term;
} else {
request.term = term;
}
return capi.fetchLatest(request);
}, CONST.searchDebounceMs);
this.showNext = ko.pureComputed(function () {
return this.totalPages() > this.page();
}, this);
this.showPrev = ko.pureComputed(function () {
return this.page() > 1;
}, this);
this.showTop = ko.pureComputed(function () {
return this.page() > 2;
}, this);
this.errorCount = 0;
}