@@ -59,8 +61,8 @@
+ ng-class="{loading: service.isLoading()}"
+ ng-if="service.isLoading()">
Loading...
diff --git a/platform/features/search/src/SearchAggregator.js b/platform/features/search/src/SearchAggregator.js
index 80467dd686..4960ebd118 100644
--- a/platform/features/search/src/SearchAggregator.js
+++ b/platform/features/search/src/SearchAggregator.js
@@ -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;
}
};
diff --git a/platform/features/search/src/controllers/SearchController.js b/platform/features/search/src/controllers/SearchController.js
index 2aa1c7bf86..d79200ff48 100644
--- a/platform/features/search/src/controllers/SearchController.js
+++ b/platform/features/search/src/controllers/SearchController.js
@@ -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.