Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pat-autosuggest): load more #1195

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/pat/auto-suggest/auto-suggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const parser = new Parser("autosuggest");
parser.addArgument("ajax-data-type", "JSON");
parser.addArgument("ajax-search-index", "");
parser.addArgument("ajax-url", "");
parser.addArgument("ajax-batch-size", 10);
parser.addArgument("ajax-batch-mode", "fixed", ["fixed", "batched"]);
parser.addArgument("allow-new-words", true); // Should custom tags be allowed?
parser.addArgument("max-selection-size", 0);
parser.addArgument("minimum-input-length"); // Don't restrict by default so that all results show
Expand Down Expand Up @@ -258,14 +260,28 @@ export default Base.extend({
return {
index: this.options.ajax["search-index"],
q: term, // search term
page_limit: 10,
page_limit: this.options.ajax["batch-size"],
page: page,
};
},
results: (data, page) => {
// parse the results into the format expected by Select2.
// Parse the results into the format expected by Select2.
// data must be a list of objects with keys "id" and "text"
return { results: data, page: page };

// Check, if there are more results to come.
thet marked this conversation as resolved.
Show resolved Hide resolved
// If batch-mode is fixed, we do not load more
// results. Otherwise there are maybe more results
// if the number of items is the same as the
// batch-size.
// We expect the backend to return an empty list if
// a batch page is requested where there are no
// more results.
const load_more =
this.options.ajax["batch-mode"] !== "fixed" && // no batching if fixed.
Object.keys(data).length >=
this.options.ajax["batch-size"];

return { results: data, page: page, more: load_more };
},
},
},
Expand Down