From b5f8e6d90c97a3608e041f957ade0001356c395a Mon Sep 17 00:00:00 2001 From: shale Date: Tue, 21 Jul 2015 16:21:23 -0700 Subject: [PATCH] [Search] Updating searchbar Updating the searchbar to be again more similar to the search view. It now has a 'load more' button, but it is not clickable for some reason. In progress. --- .../commonUI/browse/res/templates/browse.html | 4 +- platform/features/search/bundle.json | 2 +- .../search/res/templates/searchbar.html | 7 ++ .../src/controllers/SearchbarController.js | 74 +++++++++++++++++-- 4 files changed, 76 insertions(+), 11 deletions(-) diff --git a/platform/commonUI/browse/res/templates/browse.html b/platform/commonUI/browse/res/templates/browse.html index f2f0d4baa5..aa4816a882 100644 --- a/platform/commonUI/browse/res/templates/browse.html +++ b/platform/commonUI/browse/res/templates/browse.html @@ -28,11 +28,11 @@ > - +
+ + +
+ +
\ No newline at end of file diff --git a/platform/features/search/src/controllers/SearchbarController.js b/platform/features/search/src/controllers/SearchbarController.js index 1a48a9c793..5fa81793a5 100644 --- a/platform/features/search/src/controllers/SearchbarController.js +++ b/platform/features/search/src/controllers/SearchbarController.js @@ -27,23 +27,81 @@ define(function () { "use strict"; - function SearchbarController($scope, searchService) { + var INITIAL_LOAD_NUMBER = 20, + LOAD_INCREMENT = 5; + + function SearchbarController($scope, $timeout, searchService) { + // Starting amount of results to load. Will get increased. + var numResults = INITIAL_LOAD_NUMBER; + + function update(timestamp) { + // 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, 100); + } else { + // We got the latest results now + $scope.results = searchService.getLatestResults(0, numResults); + } + } + waitForLatest(); + } + + function search(inputID) { + var date = new Date(), + timestamp = date.getTime(); + + // Reset 'load more' + numResults = INITIAL_LOAD_NUMBER; + + // Send the query + searchService.sendQuery(inputID, timestamp); + + update(timestamp); + } return { - // Search the database using the user input of id "searchinput" - search: function (inputID) { - searchService.query(inputID).then(function (c) { - $scope.results = c; - }); - }, + /** + * Search the filetree. + * + * @param inputID The name of the ID property of the html text + * input where this funcion should find the search term. + */ + search: search, - // Check to see if there are any search results to display. + /** + * Checks to see if there are any search results to display. + */ areResults: function () { if ($scope.results) { return $scope.results.length > 0; } else { return false; } + }, + + /** + * Checks to see if there are more search results to display. + */ + areMore: function () { + return numResults < searchService.getNumResults(); + }, + + /** + * Increases the number of search results to display, and then + * load them. + */ + loadMore: function () { + numResults += LOAD_INCREMENT; + update(); } }; }