Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions src/app/domain/projectFilterValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ export class ProjectFilterValues {
unitTypeValue: string[] = [];

matches(project: LibraryProject): boolean {
return this.matchesSearch(project) && (!this.hasFilters() || this.matchesFilter(project));
return (
this.matchesSearch(project) &&
this.matchesPublicUnitType(project) &&
this.matchesStandard(project) &&
this.matchesDiscipline(project) &&
this.matchesUnitType(project) &&
this.matchesFeature(project) &&
this.matchesGradeLevel(project)
);
}

private matchesSearch(project: LibraryProject): boolean {
Expand All @@ -36,25 +44,14 @@ export class ProjectFilterValues {
})
);
}
private matchesFilter(project: LibraryProject): boolean {
return (
this.matchesPublicUnitType(project) ||
this.matchesStandard(project) ||
this.matchesDiscipline(project) ||
this.matchesUnitType(project) ||
this.matchesFeature(project) ||
this.matchesGradeLevel(project)
);
}

hasFilters(): boolean {
return (
this.standardValue.length +
this.disciplineValue.length +
this.unitTypeValue.length +
this.gradeLevelValue.length +
this.featureValue.length +
(this.publicUnitTypeValue?.length ?? 0) >
this.featureValue.length >
0
);
}
Expand All @@ -65,39 +62,44 @@ export class ProjectFilterValues {
this.unitTypeValue = [];
this.gradeLevelValue = [];
this.featureValue = [];
this.publicUnitTypeValue = [];
}

private matchesUnitType(project: LibraryProject): boolean {
const unitTypeValue =
project.metadata.unitType === 'Platform' ? 'WISE Platform' : 'Other Platform';
return this.unitTypeValue?.includes(unitTypeValue);
return this.unitTypeValue.length === 0 || this.unitTypeValue?.includes(unitTypeValue);
}

private matchesPublicUnitType(project: LibraryProject): boolean {
return this.publicUnitTypeValue?.includes(project.metadata.publicUnitType);
return (
this.publicUnitTypeValue?.length === 0 ||
this.publicUnitTypeValue?.includes(project.metadata.publicUnitType)
);
}

private matchesStandard(project: LibraryProject): boolean {
const standards = project.metadata.standards;
const commonCore = standards?.commonCore ?? [];
const ngss = standards?.ngss ?? [];
const learningForJustice = standards?.learningForJustice ?? [];
return [...commonCore, ...ngss, ...learningForJustice].some((val) =>
this.standardValue.includes(val.id)
return (
this.standardValue.length === 0 ||
[...commonCore, ...ngss, ...learningForJustice].some((val) =>
this.standardValue.includes(val.id)
)
);
}

private matchesFeature(project: LibraryProject): boolean {
return (
this.featureValue.length > 0 &&
project.metadata.features?.some((feature) => this.featureValue.includes(feature.id))
this.featureValue.length === 0 ||
project.metadata.features?.some((feature) => this.featureValue.includes(feature.name))
);
}

private matchesDiscipline(project: LibraryProject): boolean {
return (
this.disciplineValue.length > 0 &&
this.disciplineValue.length === 0 ||
project.metadata.disciplines?.some((discipline) =>
this.disciplineValue.includes(discipline.id)
)
Expand All @@ -106,7 +108,7 @@ export class ProjectFilterValues {

private matchesGradeLevel(project: LibraryProject): boolean {
return (
this.gradeLevelValue.length > 0 &&
this.gradeLevelValue.length === 0 ||
project.metadata.grades?.some((gradeLevel) =>
this.gradeLevelValue.includes(Number(gradeLevel))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="flex flex-col items-center lg:justify-between lg:flex-row gap-1">
<public-unit-type-selector
[filterValues]="filterValues"
(publicUnitTypeUpdatedEvent)="filterUpdated()"
(publicUnitTypeUpdatedEvent)="filterUpdated($event)"
/>
<mat-paginator
class="self-end"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CommonModule } from '@angular/common';
import { LibraryProjectComponent } from '../library-project/library-project.component';
import { PublicUnitTypeSelectorComponent } from '../public-unit-type-selector/public-unit-type-selector.component';
import { LibraryProject } from '../libraryProject';
import { ProjectFilterValues } from '../../../domain/projectFilterValues';

@Component({
imports: [
Expand Down Expand Up @@ -70,6 +71,14 @@ export class PublicLibraryComponent extends LibraryComponent {
}, []);
}

protected filterUpdated(filterValues: ProjectFilterValues = null): void {
if (filterValues) {
// this check is required the very first time when filterValues is null
filterValues.publicUnitTypeValue = this.filterValues.publicUnitTypeValue;
}
super.filterUpdated(filterValues);
}

protected emitNumberOfProjectsVisible(numProjectsVisible: number = null): void {
// do nothing. this value is not used in the public library
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import { MatIconModule } from '@angular/material/icon';
export class PublicUnitTypeSelectorComponent {
protected communityBuilt: boolean;
@Input() filterValues: ProjectFilterValues;
@Output() publicUnitTypeUpdatedEvent: EventEmitter<void> = new EventEmitter<void>();
@Output() publicUnitTypeUpdatedEvent: EventEmitter<ProjectFilterValues> =
new EventEmitter<ProjectFilterValues>();
protected wiseTested: boolean;

constructor(private dialog: MatDialog) {}
Expand All @@ -41,7 +42,7 @@ export class PublicUnitTypeSelectorComponent {
if (this.communityBuilt) {
this.filterValues.publicUnitTypeValue.push('communityBuilt');
}
this.publicUnitTypeUpdatedEvent.emit();
this.publicUnitTypeUpdatedEvent.emit(this.filterValues);
}

protected showInfo(type: 'community' | 'official'): void {
Expand Down
Loading