mirror of
https://github.com/nasa/openmct.git
synced 2025-05-21 17:57:39 +00:00
[Search] Cleanup and documentation
This commit is contained in:
parent
3d1e1659c2
commit
9ebc04ef14
@ -30,8 +30,8 @@ define(function () {
|
|||||||
var INITIAL_LOAD_NUMBER = 20,
|
var INITIAL_LOAD_NUMBER = 20,
|
||||||
LOAD_INCREMENT = 20;
|
LOAD_INCREMENT = 20;
|
||||||
|
|
||||||
function SearchController($scope, searchService, types) {
|
function SearchController($scope, searchService) {
|
||||||
// numResults is the starting amount of results to load. Will get increased.
|
// numResults is the amount of results to display. Will get increased.
|
||||||
// fullResults holds the most recent complete searchService response object
|
// fullResults holds the most recent complete searchService response object
|
||||||
var numResults = INITIAL_LOAD_NUMBER,
|
var numResults = INITIAL_LOAD_NUMBER,
|
||||||
fullResults = {hits: []};
|
fullResults = {hits: []};
|
||||||
@ -46,7 +46,7 @@ define(function () {
|
|||||||
// ngModel.filter, the function filter defined below
|
// ngModel.filter, the function filter defined below
|
||||||
// ngModel.types, an array of type objects
|
// ngModel.types, an array of type objects
|
||||||
// ngModel.checked, a dictionary of which type filter options are checked
|
// ngModel.checked, a dictionary of which type filter options are checked
|
||||||
// ngModel.checkAll, a boolean of whether all of the types in ngModel.checked are checked
|
// ngModel.checkAll, a boolean of whether to search all types
|
||||||
// ngModel.filtersString, a string list of what filters on the results are active
|
// ngModel.filtersString, a string list of what filters on the results are active
|
||||||
$scope.results = [];
|
$scope.results = [];
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
@ -70,7 +70,7 @@ define(function () {
|
|||||||
} else {
|
} else {
|
||||||
while (newResults.length < numResults && i < hits.length) {
|
while (newResults.length < numResults && i < hits.length) {
|
||||||
// If this is of an acceptable type, add it to the list
|
// If this is of an acceptable type, add it to the list
|
||||||
if ($scope.ngModel.checked[hits[i].object.getModel().type] === true) {
|
if ($scope.ngModel.checked[hits[i].object.getModel().type]) {
|
||||||
newResults.push(fullResults.hits[i]);
|
newResults.push(fullResults.hits[i]);
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
@ -88,14 +88,12 @@ define(function () {
|
|||||||
function search(maxResults) {
|
function search(maxResults) {
|
||||||
var inputText = $scope.ngModel.input;
|
var inputText = $scope.ngModel.input;
|
||||||
|
|
||||||
// We are starting to load.
|
|
||||||
if (inputText !== '' && inputText !== undefined) {
|
if (inputText !== '' && inputText !== undefined) {
|
||||||
|
// We are starting to load.
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
}
|
|
||||||
|
// Update whether the file tree should be displayed
|
||||||
// Update whether the file tree should be displayed
|
// Hide tree only when starting search
|
||||||
// Hide tree only when starting search
|
|
||||||
if (inputText !== '' && inputText !== undefined) {
|
|
||||||
$scope.ngModel.search = true;
|
$scope.ngModel.search = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,8 +104,9 @@ define(function () {
|
|||||||
|
|
||||||
// Send the query
|
// Send the query
|
||||||
searchService.query(inputText, maxResults).then(function (result) {
|
searchService.query(inputText, maxResults).then(function (result) {
|
||||||
|
// Store all the results before splicing off the front, so that
|
||||||
|
// we can load more to display later.
|
||||||
fullResults = result;
|
fullResults = result;
|
||||||
//$scope.results = result.hits.slice(0, numResults);
|
|
||||||
$scope.results = filter(result.hits);
|
$scope.results = filter(result.hits);
|
||||||
|
|
||||||
// Update whether the file tree should be displayed
|
// Update whether the file tree should be displayed
|
||||||
|
@ -40,7 +40,7 @@ define(function () {
|
|||||||
$scope.ngModel.checkAll = true;
|
$scope.ngModel.checkAll = true;
|
||||||
$scope.ngModel.filtersString = '';
|
$scope.ngModel.filtersString = '';
|
||||||
|
|
||||||
// On initialization, fill the scope's types with type keys
|
// On initialization, fill the model's types with type keys
|
||||||
types.forEach(function (type) {
|
types.forEach(function (type) {
|
||||||
// We only want some types, the ones that are probably human readable
|
// We only want some types, the ones that are probably human readable
|
||||||
// Manually remove 'root', but not 'unknown'
|
// Manually remove 'root', but not 'unknown'
|
||||||
@ -67,7 +67,7 @@ define(function () {
|
|||||||
|
|
||||||
// Update the current filters string
|
// Update the current filters string
|
||||||
$scope.ngModel.filtersString = '';
|
$scope.ngModel.filtersString = '';
|
||||||
if ($scope.ngModel.checkAll !== true) {
|
if (!$scope.ngModel.checkAll) {
|
||||||
for (i = 0; i < $scope.ngModel.types.length; i += 1) {
|
for (i = 0; i < $scope.ngModel.types.length; i += 1) {
|
||||||
// If the type key corresponds to a checked option...
|
// If the type key corresponds to a checked option...
|
||||||
if ($scope.ngModel.checked[$scope.ngModel.types[i].key]) {
|
if ($scope.ngModel.checked[$scope.ngModel.types[i].key]) {
|
||||||
@ -94,30 +94,21 @@ define(function () {
|
|||||||
function checkAll() {
|
function checkAll() {
|
||||||
var type;
|
var type;
|
||||||
|
|
||||||
// If model's checkAll has just been checked, reset everything else
|
// Reset all the other options to original/default position
|
||||||
// to default view, and behave as if there are no filters (default)
|
for (type in $scope.ngModel.checked) {
|
||||||
if ($scope.ngModel.checkAll) {
|
$scope.ngModel.checked[type] = false;
|
||||||
// Uncheck everything else
|
|
||||||
for (type in $scope.ngModel.checked) {
|
|
||||||
$scope.ngModel.checked[type] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset filter display
|
|
||||||
$scope.ngModel.filtersString = '';
|
|
||||||
|
|
||||||
// Re-filter results
|
|
||||||
$scope.ngModel.filter();
|
|
||||||
} else {
|
|
||||||
// If model's checkAll has just been UNchecked, set filters to none
|
|
||||||
|
|
||||||
for (type in $scope.ngModel.checked) {
|
|
||||||
$scope.ngModel.checked[type] = false;
|
|
||||||
}
|
|
||||||
$scope.ngModel.filtersString = 'NONE';
|
|
||||||
|
|
||||||
// Re-filter results
|
|
||||||
$scope.ngModel.filter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change the filters string depending on checkAll status
|
||||||
|
if ($scope.ngModel.checkAll) {
|
||||||
|
// This setting will make the filters display hidden
|
||||||
|
$scope.ngModel.filtersString = '';
|
||||||
|
} else {
|
||||||
|
$scope.ngModel.filtersString = 'NONE';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-filter results
|
||||||
|
$scope.ngModel.filter();
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user