mirror of
https://github.com/nasa/openmct.git
synced 2024-12-24 07:16:39 +00:00
[Search] Change default search menu
The search menu now opens to having none of the types checked, but 'ALL' checked. Checking anything besides 'ALL' unchecks 'ALL' and begins filtering search by type.
This commit is contained in:
parent
7b4934ec55
commit
6d660d48ca
@ -57,12 +57,18 @@ define(function () {
|
|||||||
var newResults = [],
|
var newResults = [],
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
while (newResults.length < numResults && i < hits.length) {
|
// If checkAll is checked, search everything no matter what the other
|
||||||
// If this is of an acceptable type, add it to the list
|
// checkboxes' statuses are. Otherwise filter the search by types.
|
||||||
if ($scope.ngModel.checked[hits[i].object.getModel().type] === true) {
|
if ($scope.ngModel.checkAll) {
|
||||||
newResults.push(fullResults.hits[i]);
|
newResults = fullResults.hits.slice(0, numResults);
|
||||||
|
} else {
|
||||||
|
while (newResults.length < numResults && i < hits.length) {
|
||||||
|
// If this is of an acceptable type, add it to the list
|
||||||
|
if ($scope.ngModel.checked[hits[i].object.getModel().type] === true) {
|
||||||
|
newResults.push(fullResults.hits[i]);
|
||||||
|
}
|
||||||
|
i += 1;
|
||||||
}
|
}
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newResults;
|
return newResults;
|
||||||
@ -111,19 +117,14 @@ define(function () {
|
|||||||
i;
|
i;
|
||||||
|
|
||||||
// Update all-checked status
|
// Update all-checked status
|
||||||
$scope.ngModel.checkAll = true;
|
if ($scope.ngModel.checkAll) {
|
||||||
for (type in $scope.ngModel.checked) {
|
for (type in $scope.ngModel.checked) {
|
||||||
if (!$scope.ngModel.checked[type]) {
|
if ($scope.ngModel.checked[type]) {
|
||||||
$scope.ngModel.checkAll = false;
|
$scope.ngModel.checkAll = false;
|
||||||
} else {
|
}
|
||||||
if ($scope.filtersString === '') {
|
|
||||||
$scope.filtersString += type;
|
|
||||||
} else {
|
|
||||||
$scope.filtersString += ', ' + type;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the current filters string
|
// Update the current filters string
|
||||||
$scope.filtersString = '';
|
$scope.filtersString = '';
|
||||||
if ($scope.ngModel.checkAll !== true) {
|
if ($scope.ngModel.checkAll !== true) {
|
||||||
@ -149,12 +150,43 @@ define(function () {
|
|||||||
$scope.results = filter(fullResults.hits);
|
$scope.results = filter(fullResults.hits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For documentation, see checkAll below
|
||||||
|
function checkAll() {
|
||||||
|
var type;
|
||||||
|
|
||||||
|
// If model's checkAll has just been checked, reset everything else
|
||||||
|
// to default view, and behave as if there are no filters (default)
|
||||||
|
if ($scope.ngModel.checkAll) {
|
||||||
|
// Uncheck everything else
|
||||||
|
for (type in $scope.ngModel.checked) {
|
||||||
|
$scope.ngModel.checked[type] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset filter display
|
||||||
|
$scope.filtersString = '';
|
||||||
|
|
||||||
|
// Re-filter results
|
||||||
|
$scope.results = filter(fullResults.hits);
|
||||||
|
} 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.filtersString = 'NONE';
|
||||||
|
|
||||||
|
// Re-filter results
|
||||||
|
$scope.results = filter(fullResults.hits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// On initialization, fill the scope's types with type keys
|
// On initialization, fill the scope'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
|
||||||
if (type.key && type.name) {
|
if (type.key && type.name) {
|
||||||
$scope.types.push(type);
|
$scope.types.push(type);
|
||||||
$scope.ngModel.checked[type.key] = true;
|
$scope.ngModel.checked[type.key] = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$scope.ngModel.checkAll = true;
|
$scope.ngModel.checkAll = true;
|
||||||
@ -206,24 +238,18 @@ define(function () {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the status of the checked options, including 'check-all'.
|
* Updates the status of the checked options. Updates the filtersString
|
||||||
* Updates the filtersString with which options are checked, if
|
* with which options are checked. Re-filters the search results after.
|
||||||
* check-all is not true. Re-filters the search restuls.
|
* Not intended to be called by checkAll when it is toggled.
|
||||||
*/
|
*/
|
||||||
updateOptions: updateOptions,
|
updateOptions: updateOptions,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks or un-checks all of the filter options depending on the
|
* Handles the search and filter options for when checkAll has been
|
||||||
* value of ngModel.checkAll, then calls updateOptions.
|
* toggled. This is a special case, compared to the other search
|
||||||
|
* menu options, so is intended to be called instead of updateOptions.
|
||||||
*/
|
*/
|
||||||
checkAll: function () {
|
checkAll: checkAll
|
||||||
var type;
|
|
||||||
for (type in $scope.ngModel.checked) {
|
|
||||||
$scope.ngModel.checked[type] = $scope.ngModel.checkAll;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateOptions();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return SearchController;
|
return SearchController;
|
||||||
|
Loading…
Reference in New Issue
Block a user