mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 17:33:23 +00:00
[Search] Responsibility change (in progress)
Attempting to move some responsibility from the search controller to the aggregator. (Committing for save before possible revert.)
This commit is contained in:
parent
232a648fbd
commit
181fb32a2a
@ -43,7 +43,8 @@
|
||||
{
|
||||
"provides": "searchService",
|
||||
"type": "aggregator",
|
||||
"implementation": "SearchAggregator.js"
|
||||
"implementation": "SearchAggregator.js",
|
||||
"depends": [ "$timeout" ]
|
||||
}
|
||||
],
|
||||
"workers": [
|
||||
|
@ -20,7 +20,9 @@
|
||||
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' (is in $scope) -->
|
||||
|
||||
<!-- Search bar input -->
|
||||
<div>
|
||||
<input class="search-input"
|
||||
@ -51,7 +53,7 @@
|
||||
<!-- Results list -->
|
||||
<div class="results">
|
||||
<mct-representation key="'search-item'"
|
||||
ng-repeat="result in results"
|
||||
ng-repeat="result in service.latestResults"
|
||||
mct-object="result.object"
|
||||
ng-model="ngModel">
|
||||
</mct-representation>
|
||||
@ -59,8 +61,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 = false,
|
||||
aggregator = {};
|
||||
|
||||
// Remove duplicate objects that have the same ID
|
||||
@ -120,10 +122,27 @@ define(
|
||||
newerResults = filterRepeats(newerResults);
|
||||
newerResults = orderByScore(newerResults);
|
||||
|
||||
// After all that is done, now replace latestMergedResults with this
|
||||
// Now replace latestMergedResults
|
||||
latestMergedResults = newerResults;
|
||||
lastMergeTimestamps = providerTimestamps;
|
||||
aggregator.latestResults = latestMergedResults;
|
||||
|
||||
// Update the loading status, and wait for latest results if needed
|
||||
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();
|
||||
loading = true;
|
||||
$timeout(waitForLatest, 50);
|
||||
} else {
|
||||
// We got the latest results now (and done loading)
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
waitForLatest();
|
||||
}
|
||||
|
||||
// For documentation, see sendQuery below.
|
||||
@ -134,6 +153,8 @@ define(
|
||||
timestamp = date.getTime();
|
||||
}
|
||||
|
||||
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);
|
||||
@ -201,6 +222,14 @@ define(
|
||||
*/
|
||||
getNumResults: function () {
|
||||
return latestMergedResults.length;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks to see if we are still waiting for the results to be
|
||||
* fully updated.
|
||||
*/
|
||||
isLoading: function () {
|
||||
return loading;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -40,10 +40,11 @@ define(function () {
|
||||
// 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;
|
||||
$scope.service = 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.
|
||||
|
||||
/*
|
||||
function update(timestamp) {
|
||||
// We are loading results
|
||||
loading = true;
|
||||
@ -69,6 +70,7 @@ define(function () {
|
||||
}
|
||||
waitForLatest();
|
||||
}
|
||||
*/
|
||||
|
||||
function search() {
|
||||
var date = new Date(),
|
||||
@ -88,9 +90,15 @@ define(function () {
|
||||
// Send the query
|
||||
searchService.sendQuery(inputText, timestamp);
|
||||
|
||||
update(timestamp);
|
||||
//update(timestamp);
|
||||
}
|
||||
|
||||
$scope.$watch("searchService.latestResults", function () {
|
||||
console.log('watcher saw')
|
||||
// Update the displayed result list
|
||||
$scope.service = searchService;
|
||||
});
|
||||
|
||||
return {
|
||||
/**
|
||||
* Search the filetree.
|
||||
@ -113,9 +121,11 @@ define(function () {
|
||||
* Checks to see if we are still waiting for the results to be
|
||||
* fully updated.
|
||||
*/
|
||||
/*
|
||||
isLoading: function () {
|
||||
return loading;
|
||||
},
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks to see if there are more search results to display.
|
||||
|
Loading…
x
Reference in New Issue
Block a user