mirror of
https://github.com/nasa/openmct.git
synced 2024-12-19 13:17:53 +00:00
[Search] Update loadMore
The controller's loadMore function now sends new queries to the search service if the controller's full results list does not have enough results in it to load more.
This commit is contained in:
parent
695582b30f
commit
1cd6685b36
@ -83,15 +83,19 @@ define(
|
||||
}
|
||||
|
||||
// For documentation, see sendQuery below.
|
||||
function queryAll(inputText) {
|
||||
function queryAll(inputText, maxResults) {
|
||||
var i,
|
||||
timestamp = Date.now(),
|
||||
resultPromises = [];
|
||||
|
||||
if (!maxResults) {
|
||||
maxResults = DEFAULT_MAX_RESULTS;
|
||||
}
|
||||
|
||||
// Send the query to all the providers
|
||||
for (i = 0; i < providers.length; i += 1) {
|
||||
resultPromises.push(
|
||||
providers[i].query(inputText, timestamp, DEFAULT_MAX_RESULTS, DEFUALT_TIMEOUT)
|
||||
providers[i].query(inputText, timestamp, maxResults, DEFUALT_TIMEOUT)
|
||||
);
|
||||
}
|
||||
|
||||
@ -127,6 +131,9 @@ define(
|
||||
* {hits: domainObject[], total: number}
|
||||
*
|
||||
* @param inputText The text input that is the query.
|
||||
* @param maxResults (optional) The maximum number of results
|
||||
* that this function should return. If not provided, a
|
||||
* default of 100 will be used.
|
||||
*/
|
||||
query: queryAll
|
||||
};
|
||||
|
@ -34,9 +34,9 @@ define(function () {
|
||||
// Starting amount of results to load. Will get increased.
|
||||
var numResults = INITIAL_LOAD_NUMBER,
|
||||
loading = false,
|
||||
fullResults = [];
|
||||
fullResults = {hits: []};
|
||||
|
||||
function search() {
|
||||
function search(maxResults) {
|
||||
var inputText = $scope.ngModel.input;
|
||||
|
||||
// We are starting to load.
|
||||
@ -49,12 +49,14 @@ define(function () {
|
||||
$scope.ngModel.search = true;
|
||||
}
|
||||
|
||||
// Reset 'load more'
|
||||
numResults = INITIAL_LOAD_NUMBER;
|
||||
if (!maxResults) {
|
||||
// Reset 'load more'
|
||||
numResults = INITIAL_LOAD_NUMBER;
|
||||
}
|
||||
|
||||
// Send the query
|
||||
searchService.query(inputText).then(function (result) {
|
||||
fullResults = result.hits;
|
||||
searchService.query(inputText, maxResults).then(function (result) {
|
||||
fullResults = result;
|
||||
$scope.results = result.hits.slice(0, numResults);
|
||||
|
||||
// Now we are done loading.
|
||||
@ -66,6 +68,10 @@ define(function () {
|
||||
/**
|
||||
* Search the filetree.
|
||||
* Assumes that any search text will be in ngModel.input
|
||||
*
|
||||
* @param maxResults (optional) The maximum number of results
|
||||
* that this function should return. If not provided, search
|
||||
* service default will be used.
|
||||
*/
|
||||
search: search,
|
||||
|
||||
@ -81,8 +87,7 @@ define(function () {
|
||||
* Checks to see if there are more search results to display.
|
||||
*/
|
||||
areMore: function () {
|
||||
return numResults < fullResults.length;
|
||||
// TODO: See loadMore() todo.
|
||||
return numResults < fullResults.total;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -91,9 +96,13 @@ define(function () {
|
||||
*/
|
||||
loadMore: function () {
|
||||
numResults += LOAD_INCREMENT;
|
||||
$scope.results = fullResults.slice(0, numResults);
|
||||
// TODO: Let load more see if total > fullResults.length, and then
|
||||
// if so, resend a query.
|
||||
|
||||
if (numResults > fullResults.hits.length && fullResults.hits.length < fullResults.total) {
|
||||
// Resend the query if we are out of items to display, but there are more to get
|
||||
search(numResults);
|
||||
} else {
|
||||
$scope.results = fullResults.hits.slice(0, numResults);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user