[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:
slhale 2015-08-17 11:17:02 -07:00
parent 7b4934ec55
commit 6d660d48ca

View File

@ -57,12 +57,18 @@ define(function () {
var newResults = [],
i = 0;
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]);
// If checkAll is checked, search everything no matter what the other
// checkboxes' statuses are. Otherwise filter the search by types.
if ($scope.ngModel.checkAll) {
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;
@ -111,19 +117,14 @@ define(function () {
i;
// Update all-checked status
$scope.ngModel.checkAll = true;
for (type in $scope.ngModel.checked) {
if (!$scope.ngModel.checked[type]) {
$scope.ngModel.checkAll = false;
} else {
if ($scope.filtersString === '') {
$scope.filtersString += type;
} else {
$scope.filtersString += ', ' + type;
}
if ($scope.ngModel.checkAll) {
for (type in $scope.ngModel.checked) {
if ($scope.ngModel.checked[type]) {
$scope.ngModel.checkAll = false;
}
}
}
// Update the current filters string
$scope.filtersString = '';
if ($scope.ngModel.checkAll !== true) {
@ -149,12 +150,43 @@ define(function () {
$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
types.forEach(function (type) {
// We only want some types, the ones that are probably human readable
if (type.key && type.name) {
$scope.types.push(type);
$scope.ngModel.checked[type.key] = true;
$scope.ngModel.checked[type.key] = false;
}
});
$scope.ngModel.checkAll = true;
@ -206,24 +238,18 @@ define(function () {
},
/**
* Updates the status of the checked options, including 'check-all'.
* Updates the filtersString with which options are checked, if
* check-all is not true. Re-filters the search restuls.
* Updates the status of the checked options. Updates the filtersString
* with which options are checked. Re-filters the search results after.
* Not intended to be called by checkAll when it is toggled.
*/
updateOptions: updateOptions,
/**
* Checks or un-checks all of the filter options depending on the
* value of ngModel.checkAll, then calls updateOptions.
* Handles the search and filter options for when checkAll has been
* toggled. This is a special case, compared to the other search
* menu options, so is intended to be called instead of updateOptions.
*/
checkAll: function () {
var type;
for (type in $scope.ngModel.checked) {
$scope.ngModel.checked[type] = $scope.ngModel.checkAll;
}
updateOptions();
}
checkAll: checkAll
};
}
return SearchController;