This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit 14052f10 authored by Daniel Rainer's avatar Daniel Rainer
Browse files

Use sets for filters

Instead of filtering by a single value,
use sets for each category.
Display results iff they match any set element
in all non-empty sets.
parent 7911cfb2
Branches
No related merge requests found
......@@ -37,9 +37,9 @@ export class SearchComponent implements OnInit, OnDestroy {
gitFilesAggregation?: IGitFilesAggregation;
private filterSelectionSubscription: Subscription = new Subscription();
private selectedRepository: string | null = null;
private selectedUniversity: string | null = null;
private selectedFileFormat: string | null = null;
private selectedRepositories = new Set();
private selectedUniversities = new Set();
private selectedFileFormats = new Set();
public paramGroup: QueryParamGroup;
private componentDestroyed$ = new Subject<void>();
......@@ -157,18 +157,20 @@ export class SearchComponent implements OnInit, OnDestroy {
// this function is called.
// It updates the local filters.
// Currently, for any category (at the moment repository and file format)
// there is either one value all search results have to satisfy
// (e.g. display only files from a certain repository)
// or the filter is not set.
// Clicking a filter value which is already being applied
// results in this filter to be reset. (Does not filter by this category)
// there is a set of allowed values.
// If the selected item is not in the corresponding set it is added.
// Otherwise it is removed.
// If a set is empty the corresponding filter is not applied.
// For non-empty sets, the results which will be displayed must match one of the set's elements.
// (e.g. if the selectedRepositories set contains "foo" and "bar",
// only results from these two repos will be shown.)
public updateSearchInfoFilter(selection: IMetadataSelection): void {
switch (selection.category) {
case 'repository': {
if (this.selectedRepository === selection.value) {
this.selectedRepository = null;
if (this.selectedRepositories.has(selection.value)) {
this.selectedRepositories.delete(selection.value);
} else {
this.selectedRepository = selection.value;
this.selectedRepositories.add(selection.value);
}
break;
}
......@@ -176,18 +178,18 @@ export class SearchComponent implements OnInit, OnDestroy {
// University seems to be a derived attribute.
// Currently not implemented.
alert('Filtering by university is not supported at the moment. Cause: University is not in the interface IGitFiles.');
/* if (this.selectedUniversity === selection.value) {
this.selectedUniversity = null;
/* if (this.selectedUniversities.has(selection.value)) {
this.selectedUniversities.delete(selection.value);
} else {
this.selectedUniversity = selection.value;
this.selectedUniversities.add(selection.value);
} */
break;
}
case 'fileFormat': {
if (this.selectedFileFormat === selection.value) {
this.selectedFileFormat = null;
if (this.selectedFileFormats.has(selection.value)) {
this.selectedFileFormats.delete(selection.value);
} else {
this.selectedFileFormat = selection.value;
this.selectedFileFormats.add(selection.value);
}
break;
}
......@@ -197,13 +199,13 @@ export class SearchComponent implements OnInit, OnDestroy {
// Checks if a given file matches the local filters.
matchesSelection(file: IGitFiles): boolean {
if (this.selectedRepository && file.repository !== this.selectedRepository) {
if (this.selectedRepositories.size > 0 && !this.selectedRepositories.has(file.repository)) {
return false;
}
/* if (this.selectedUniversity && file.university !== this.selectedUniversity) {
return false;
} */
if (this.selectedFileFormat && file.fileFormat !== this.selectedFileFormat) {
/* if (this.selectedUniversities.size > 0 && !this.selectedUniversities.has(file.university)) {
return false;
} */
if (this.selectedFileFormats.size > 0 && !this.selectedFileFormats.has(file.fileFormat)) {
return false;
}
return true;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment