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
Tags
No related merge requests found
...@@ -37,9 +37,9 @@ export class SearchComponent implements OnInit, OnDestroy { ...@@ -37,9 +37,9 @@ export class SearchComponent implements OnInit, OnDestroy {
gitFilesAggregation?: IGitFilesAggregation; gitFilesAggregation?: IGitFilesAggregation;
private filterSelectionSubscription: Subscription = new Subscription(); private filterSelectionSubscription: Subscription = new Subscription();
private selectedRepository: string | null = null; private selectedRepositories = new Set();
private selectedUniversity: string | null = null; private selectedUniversities = new Set();
private selectedFileFormat: string | null = null; private selectedFileFormats = new Set();
public paramGroup: QueryParamGroup; public paramGroup: QueryParamGroup;
private componentDestroyed$ = new Subject<void>(); private componentDestroyed$ = new Subject<void>();
...@@ -157,18 +157,20 @@ export class SearchComponent implements OnInit, OnDestroy { ...@@ -157,18 +157,20 @@ export class SearchComponent implements OnInit, OnDestroy {
// this function is called. // this function is called.
// It updates the local filters. // It updates the local filters.
// Currently, for any category (at the moment repository and file format) // Currently, for any category (at the moment repository and file format)
// there is either one value all search results have to satisfy // there is a set of allowed values.
// (e.g. display only files from a certain repository) // If the selected item is not in the corresponding set it is added.
// or the filter is not set. // Otherwise it is removed.
// Clicking a filter value which is already being applied // If a set is empty the corresponding filter is not applied.
// results in this filter to be reset. (Does not filter by this category) // 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 { public updateSearchInfoFilter(selection: IMetadataSelection): void {
switch (selection.category) { switch (selection.category) {
case 'repository': { case 'repository': {
if (this.selectedRepository === selection.value) { if (this.selectedRepositories.has(selection.value)) {
this.selectedRepository = null; this.selectedRepositories.delete(selection.value);
} else { } else {
this.selectedRepository = selection.value; this.selectedRepositories.add(selection.value);
} }
break; break;
} }
...@@ -176,18 +178,18 @@ export class SearchComponent implements OnInit, OnDestroy { ...@@ -176,18 +178,18 @@ export class SearchComponent implements OnInit, OnDestroy {
// University seems to be a derived attribute. // University seems to be a derived attribute.
// Currently not implemented. // Currently not implemented.
alert('Filtering by university is not supported at the moment. Cause: University is not in the interface IGitFiles.'); alert('Filtering by university is not supported at the moment. Cause: University is not in the interface IGitFiles.');
/* if (this.selectedUniversity === selection.value) { /* if (this.selectedUniversities.has(selection.value)) {
this.selectedUniversity = null; this.selectedUniversities.delete(selection.value);
} else { } else {
this.selectedUniversity = selection.value; this.selectedUniversities.add(selection.value);
} */ } */
break; break;
} }
case 'fileFormat': { case 'fileFormat': {
if (this.selectedFileFormat === selection.value) { if (this.selectedFileFormats.has(selection.value)) {
this.selectedFileFormat = null; this.selectedFileFormats.delete(selection.value);
} else { } else {
this.selectedFileFormat = selection.value; this.selectedFileFormats.add(selection.value);
} }
break; break;
} }
...@@ -197,13 +199,13 @@ export class SearchComponent implements OnInit, OnDestroy { ...@@ -197,13 +199,13 @@ export class SearchComponent implements OnInit, OnDestroy {
// Checks if a given file matches the local filters. // Checks if a given file matches the local filters.
matchesSelection(file: IGitFiles): boolean { matchesSelection(file: IGitFiles): boolean {
if (this.selectedRepository && file.repository !== this.selectedRepository) { if (this.selectedRepositories.size > 0 && !this.selectedRepositories.has(file.repository)) {
return false; return false;
} }
/* if (this.selectedUniversity && file.university !== this.selectedUniversity) { /* if (this.selectedUniversities.size > 0 && !this.selectedUniversities.has(file.university)) {
return false; return false;
} */ } */
if (this.selectedFileFormat && file.fileFormat !== this.selectedFileFormat) { if (this.selectedFileFormats.size > 0 && !this.selectedFileFormats.has(file.fileFormat)) {
return false; return false;
} }
return true; 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