mirror of
https://github.com/nasa/openmct.git
synced 2025-04-21 09:31:24 +00:00
[Search] Results polling in aggregator
Moved the polling for most recent results from the search controller to the search aggregator. Also changed ng-change back to ng-keyup in the search template.
This commit is contained in:
parent
5e858f73d5
commit
a3977a18f0
platform/features/search
@ -6,7 +6,7 @@
|
||||
{
|
||||
"key": "SearchController",
|
||||
"implementation": "controllers/SearchController.js",
|
||||
"depends": [ "$scope", "$timeout", "searchService" ]
|
||||
"depends": [ "$scope", "searchService" ]
|
||||
},
|
||||
{
|
||||
"key": "SearchItemController",
|
||||
@ -43,7 +43,8 @@
|
||||
{
|
||||
"provides": "searchService",
|
||||
"type": "aggregator",
|
||||
"implementation": "SearchAggregator.js"
|
||||
"implementation": "SearchAggregator.js",
|
||||
"depends": [ "$timeout" ]
|
||||
}
|
||||
],
|
||||
"workers": [
|
||||
|
@ -20,14 +20,16 @@
|
||||
at runtime from the About dialog for additional information.
|
||||
-->
|
||||
<div class="search"
|
||||
ng-controller="SearchController as controller">
|
||||
ng-controller="SearchController as controller">
|
||||
<!-- Using search service as 'service' -->
|
||||
|
||||
<!-- Search bar input -->
|
||||
<div>
|
||||
<input class="search-input"
|
||||
type="text"
|
||||
value=""
|
||||
ng-model="ngModel.input"
|
||||
ng-change="controller.search()" />
|
||||
ng-keyup="controller.search()" />
|
||||
<!--mct-control key="textfield"
|
||||
ng-model="ngModel"
|
||||
structure="{cssclass: 'search-input', size: '50px'}">
|
||||
@ -48,8 +50,8 @@
|
||||
|
||||
<!-- Loading icon -->
|
||||
<div class="load-icon"
|
||||
ng-class="{loading: controller.isLoading()}"
|
||||
ng-if="controller.isLoading()">
|
||||
ng-class="{loading: service.isLoading()}"
|
||||
ng-if="service.isLoading()">
|
||||
<span class="icon wait-spinner"></span>
|
||||
<span class="title-label">Loading...</span>
|
||||
</div>
|
||||
|
@ -40,9 +40,11 @@ define(
|
||||
* @param {SearchProvider[]} providers the search providers to be
|
||||
* aggregated
|
||||
*/
|
||||
function SearchAggregator(providers) {
|
||||
function SearchAggregator($timeout, providers) {
|
||||
var latestMergedResults = [],
|
||||
lastMergeTimestamps = [],
|
||||
lastQueryTimestamp = 0,
|
||||
loading,
|
||||
aggregator = {};
|
||||
|
||||
// Remove duplicate objects that have the same ID
|
||||
@ -126,14 +128,44 @@ define(
|
||||
aggregator.latestResults = latestMergedResults;
|
||||
}
|
||||
|
||||
// Refresh
|
||||
function refresh(callback) {
|
||||
// We are loading results
|
||||
loading = true;
|
||||
|
||||
// Get the results
|
||||
//$scope.results = searchService.getLatestResults(0, numResults);
|
||||
|
||||
// Check to make sure that these results are the latest ones
|
||||
function waitForLatest() {
|
||||
var areOld = lastMergeTimestamps.some(function(c) {return c < lastQueryTimestamp;});
|
||||
|
||||
// If any of the timestamps are older than the one we made the query with
|
||||
if (areOld) {
|
||||
// Then wait and try to update again
|
||||
updateResults();
|
||||
$timeout(waitForLatest, 50);
|
||||
} else {
|
||||
// We got the latest results now (and done loading)
|
||||
loading = false;
|
||||
//$scope.results = searchService.getLatestResults(0, numResults);
|
||||
callback(latestMergedResults);
|
||||
}
|
||||
}
|
||||
waitForLatest();
|
||||
}
|
||||
|
||||
// For documentation, see sendQuery below.
|
||||
function queryAll(inputText, timestamp) {
|
||||
function queryAll(inputText, callback, timestamp) {
|
||||
// If there's not a timestamp, make this time the timestamp
|
||||
if (!timestamp) {
|
||||
var date = new Date();
|
||||
timestamp = date.getTime();
|
||||
}
|
||||
|
||||
// Update globals
|
||||
lastQueryTimestamp = timestamp;
|
||||
|
||||
// Send the query to all the providers
|
||||
for (var i = 0; i < providers.length; i += 1) {
|
||||
providers[i].query(inputText, timestamp, DEFAULT_MAX_RESULTS, DEFUALT_TIMEOUT);
|
||||
@ -141,6 +173,9 @@ define(
|
||||
|
||||
// Update the merged results list
|
||||
updateResults();
|
||||
|
||||
// Start refresh loop
|
||||
refresh(callback);
|
||||
}
|
||||
|
||||
aggregator = {
|
||||
@ -160,7 +195,12 @@ define(
|
||||
* Updates the global latestMergedResults and lastMergeTimestamps
|
||||
* by checking the latest results of each of the providers.
|
||||
*/
|
||||
/*
|
||||
updateResults: updateResults,
|
||||
*/
|
||||
|
||||
// Maybe replaces updateResults
|
||||
refresh: refresh,
|
||||
|
||||
/**
|
||||
* Get the latest search results that have been calculated. The
|
||||
@ -185,15 +225,19 @@ define(
|
||||
* objects, which have the members id, object, and score. This
|
||||
* array is updated often.
|
||||
*/
|
||||
/*
|
||||
latestResults: latestMergedResults,
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the timestamps for each of the provider's last controbutions
|
||||
* to the latestMergedResults.
|
||||
*/
|
||||
/*
|
||||
getLatestTimestamps: function () {
|
||||
return lastMergeTimestamps;
|
||||
},
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the number of search results that have been calculated most
|
||||
@ -201,6 +245,10 @@ define(
|
||||
*/
|
||||
getNumResults: function () {
|
||||
return latestMergedResults.length;
|
||||
},
|
||||
|
||||
isLoading: function () {
|
||||
return loading;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -30,50 +30,23 @@ define(function () {
|
||||
var INITIAL_LOAD_NUMBER = 20,
|
||||
LOAD_INCREMENT = 5;
|
||||
|
||||
function SearchController($scope, $timeout, searchService) {
|
||||
function SearchController($scope, searchService) {
|
||||
// Starting amount of results to load. Will get increased.
|
||||
var numResults = INITIAL_LOAD_NUMBER,
|
||||
loading = false;
|
||||
|
||||
//$scope.results = searchService.latestResults;
|
||||
var numResults = INITIAL_LOAD_NUMBER;
|
||||
|
||||
// This allows us to directly access the search aggregator's members.
|
||||
// Most important is latestResults, which is continuously updated. This
|
||||
// means that this controller does not have to poll for results any more.
|
||||
//$scope.searchService = searchService;
|
||||
// TODO: Modify search aggregator to have a search result array which
|
||||
// is of a size that can be chosen and modified by this controller.
|
||||
$scope.service = searchService;
|
||||
|
||||
function update(timestamp) {
|
||||
// We are loading results
|
||||
loading = true;
|
||||
|
||||
// Get the results
|
||||
$scope.results = searchService.getLatestResults(0, numResults);
|
||||
|
||||
// Check to make sure that these results are the latest ones
|
||||
function waitForLatest() {
|
||||
var timestamps = searchService.getLatestTimestamps(),
|
||||
areOld = timestamps.some(function(c) {return c < timestamp;});
|
||||
|
||||
// If any of the timestamps are older than the one we made the query with
|
||||
if (areOld) {
|
||||
// Then wait and try to update again
|
||||
searchService.updateResults();
|
||||
$timeout(waitForLatest, 50);
|
||||
} else {
|
||||
// We got the latest results now (and done loading)
|
||||
loading = false;
|
||||
$scope.results = searchService.getLatestResults(0, numResults);
|
||||
}
|
||||
}
|
||||
waitForLatest();
|
||||
// Function to be passed to the search service which allows it to set the
|
||||
// search template's results list
|
||||
function setControllerResults(results) {
|
||||
$scope.results = results.slice(0, numResults);
|
||||
}
|
||||
|
||||
function search() {
|
||||
var date = new Date(),
|
||||
timestamp = date.getTime(),
|
||||
inputText = $scope.ngModel.input;
|
||||
var inputText = $scope.ngModel.input;
|
||||
|
||||
// Update whether the file tree should be displayed
|
||||
if (inputText === '') {
|
||||
@ -86,9 +59,7 @@ define(function () {
|
||||
numResults = INITIAL_LOAD_NUMBER;
|
||||
|
||||
// Send the query
|
||||
searchService.sendQuery(inputText, timestamp);
|
||||
|
||||
update(timestamp);
|
||||
searchService.sendQuery(inputText, setControllerResults);
|
||||
}
|
||||
|
||||
return {
|
||||
@ -113,9 +84,10 @@ define(function () {
|
||||
* Checks to see if we are still waiting for the results to be
|
||||
* fully updated.
|
||||
*/
|
||||
/*
|
||||
isLoading: function () {
|
||||
return loading;
|
||||
},
|
||||
return searchService.isLoading();
|
||||
},*/
|
||||
|
||||
/**
|
||||
* Checks to see if there are more search results to display.
|
||||
@ -130,7 +102,7 @@ define(function () {
|
||||
*/
|
||||
loadMore: function () {
|
||||
numResults += LOAD_INCREMENT;
|
||||
update();
|
||||
searchService.refresh(setControllerResults);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user