mirror of
https://github.com/nasa/openmct.git
synced 2025-02-10 12:51:42 +00:00
[Search] Throttle search
Use the throttle service to throttle search calls from the search controller. #91.
This commit is contained in:
parent
5230bdfc6b
commit
e045ce223b
@ -13,7 +13,7 @@
|
||||
{
|
||||
"key": "SearchController",
|
||||
"implementation": "controllers/SearchController.js",
|
||||
"depends": [ "$scope", "searchService" ]
|
||||
"depends": [ "$scope", "searchService", "throttle" ]
|
||||
},
|
||||
{
|
||||
"key": "SearchMenuController",
|
||||
|
@ -30,7 +30,7 @@ define(function () {
|
||||
var INITIAL_LOAD_NUMBER = 20,
|
||||
LOAD_INCREMENT = 20;
|
||||
|
||||
function SearchController($scope, searchService) {
|
||||
function SearchController($scope, searchService, throttle) {
|
||||
// numResults is the amount of results to display. Will get increased.
|
||||
// fullResults holds the most recent complete searchService response object
|
||||
var numResults = INITIAL_LOAD_NUMBER,
|
||||
@ -88,15 +88,6 @@ define(function () {
|
||||
function search(maxResults) {
|
||||
var inputText = $scope.ngModel.input;
|
||||
|
||||
if (inputText !== '' && inputText !== undefined) {
|
||||
// We are starting to load.
|
||||
$scope.loading = true;
|
||||
|
||||
// Update whether the file tree should be displayed
|
||||
// Hide tree only when starting search
|
||||
$scope.ngModel.search = true;
|
||||
}
|
||||
|
||||
if (!maxResults) {
|
||||
// Reset 'load more'
|
||||
numResults = INITIAL_LOAD_NUMBER;
|
||||
@ -129,7 +120,21 @@ define(function () {
|
||||
* that this function should return. If not provided, search
|
||||
* service default will be used.
|
||||
*/
|
||||
search: search,
|
||||
search: function (maxResults) {
|
||||
// Show that we are loading before starting the throttled function
|
||||
// so that the user knows the input was detected.
|
||||
if ($scope.ngModel.input !== '' && $scope.ngModel.input !== undefined) {
|
||||
// We are starting to load.
|
||||
$scope.loading = true;
|
||||
|
||||
// Update whether the file tree should be displayed
|
||||
// Hide tree only when starting search
|
||||
$scope.ngModel.search = true;
|
||||
}
|
||||
|
||||
// Call a throttled search
|
||||
return throttle(search)(maxResults);
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks to see if there are more search results to display. If the answer is
|
||||
|
Loading…
x
Reference in New Issue
Block a user