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