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
3 changes: 2 additions & 1 deletion src/app/curriculum/curriculum.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Subscription } from 'rxjs';
import { UserService } from '../services/user.service';
import { MatButtonModule } from '@angular/material/button';
import { Router, RouterModule } from '@angular/router';
import { ProjectFilterValues } from '../domain/projectFilterValues';

@Component({
imports: [
Expand All @@ -23,6 +24,7 @@ import { Router, RouterModule } from '@angular/router';
PublicLibraryComponent,
RouterModule
],
providers: [ProjectFilterValues],
styleUrl: './curriculum.component.scss',
templateUrl: './curriculum.component.html'
})
Expand All @@ -41,7 +43,6 @@ export class CurriculumComponent {

ngOnInit(): void {
this.showMyUnits = this.userService.isTeacher();
this.libraryService.initFilterValues();
this.getLibraryProjects();
this.subscribeNumUnitsVisible();
}
Expand Down
8 changes: 5 additions & 3 deletions src/app/domain/projectFilterValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ export class ProjectFilterValues {
}

clear(): void {
this.standardValue = [];
this.disciplineValue = [];
this.unitTypeValue = [];
this.gradeLevelValue = [];
this.featureValue = [];
this.gradeLevelValue = [];
this.publicUnitTypeValue = [];
this.searchValue = '';
this.standardValue = [];
this.unitTypeValue = [];
}

private matchesUnitType(project: LibraryProject): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { LibraryService } from '../../../services/library.service';
import { ProjectFilterValues } from '../../../domain/projectFilterValues';

@Component({
providers: [ProjectFilterValues],
selector: 'app-home-page-project-library',
styleUrls: ['./home-page-project-library.component.scss', '../library/library.component.scss'],
templateUrl: './home-page-project-library.component.html',
standalone: false
})
export class HomePageProjectLibraryComponent {
protected filterValues: ProjectFilterValues = new ProjectFilterValues();

constructor(private libraryService: LibraryService) {
libraryService.getOfficialLibraryProjects();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="library-filter">
<div class="flex flex-row gap-1">
<div class="flex-auto max-w-full">
<app-search-bar [value]="getFilterValues().searchValue" (update)="searchUpdated($event)" />
<app-search-bar [value]="filterValues.searchValue" (update)="searchUpdated($event)" />
</div>
<button
mat-icon-button
Expand All @@ -15,7 +15,7 @@
matBadgeDescription="Filters applied"
matBadgeOverlap="true"
matBadgeSize="small"
[matBadgeHidden]="!getFilterValues().hasFilters()"
[matBadgeHidden]="!filterValues.hasFilters()"
aria-hidden="false"
>filter_list</mat-icon
>
Expand All @@ -25,7 +25,7 @@
<div class="library-filters" [class.expand]="showFilters" [class.isSplitScreen]="isSplitScreen">
<div class="notice flex justify-between">
<h3 class="mat-subtitle-2" i18n>Filters</h3>
@if (getFilterValues().hasFilters()) {
@if (filterValues.hasFilters()) {
<a href="#" (click)="!!clearFilterValues()" i18n>Clear all</a>
}
</div>
Expand All @@ -43,7 +43,7 @@ <h3 class="mat-subtitle-2" i18n>Filters</h3>
[options]="unitTypeOptions"
i18n-placeholderText
placeholderText="Type"
[value]="getFilterValues().unitTypeValue"
[value]="filterValues.unitTypeValue"
(update)="filterUpdated($event, 'unitType')"
[valueProp]="'name'"
[viewValueProp]="'name'"
Expand All @@ -61,7 +61,7 @@ <h3 class="mat-subtitle-2" i18n>Filters</h3>
[options]="disciplineOptions"
i18n-placeholderText
placeholderText="Discipline"
[value]="getFilterValues().disciplineValue"
[value]="filterValues.disciplineValue"
(update)="filterUpdated($event, 'discipline')"
[valueProp]="'id'"
[viewValueProp]="'name'"
Expand All @@ -79,7 +79,7 @@ <h3 class="mat-subtitle-2" i18n>Filters</h3>
[options]="gradeLevelOptions"
i18n-placeholderText
placeholderText="Grade Level"
[value]="getFilterValues().gradeLevelValue"
[value]="filterValues.gradeLevelValue"
(update)="filterUpdated($event, 'gradeLevel')"
valueProp="grade"
viewValueProp="grade"
Expand All @@ -98,7 +98,7 @@ <h3 class="mat-subtitle-2" i18n>Filters</h3>
[possibleLabels]="possibleStandardLabels"
i18n-placeholderText
placeholderText="Standards Addressed"
[value]="getFilterValues().standardValue"
[value]="filterValues.standardValue"
(update)="filterUpdated($event, 'standard')"
[valueProp]="'id'"
[viewValueProp]="'name'"
Expand All @@ -115,7 +115,7 @@ <h3 class="mat-subtitle-2" i18n>Filters</h3>
[options]="featureOptions"
i18n-placeholderText
placeholderText="Features"
[value]="getFilterValues().featureValue"
[value]="filterValues.featureValue"
(update)="filterUpdated($event, 'feature')"
valueProp="name"
viewValueProp="name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { LibraryService } from '../../../services/library.service';
import sampleLibraryProjects from '../sampleLibraryProjects';
import { SimpleChange } from '@angular/core';
import { LibraryProject } from '../libraryProject';
import { ProjectFilterValues } from '../../../domain/projectFilterValues';
import { MockProvider } from 'ng-mocks';
import { of } from 'rxjs';
import { ProjectFilterValues } from '../../../domain/projectFilterValues';

describe('LibraryFiltersComponent', () => {
let component: LibraryFiltersComponent;
Expand All @@ -22,9 +22,9 @@ describe('LibraryFiltersComponent', () => {
communityLibraryProjectsSource$: of([] as LibraryProject[]),
sharedLibraryProjectsSource$: of([] as LibraryProject[]),
personalLibraryProjectsSource$: of([] as LibraryProject[]),
filterValuesUpdated$: of(),
filterValues: new ProjectFilterValues()
})
filterValuesUpdated$: of()
}),
ProjectFilterValues
]
});
projects = sampleLibraryProjects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class LibraryFiltersComponent {
];

constructor(
protected filterValues: ProjectFilterValues,
private libraryService: LibraryService,
private utilService: UtilService
) {
Expand Down Expand Up @@ -143,41 +144,37 @@ export class LibraryFiltersComponent {
}

protected searchUpdated(value: string): void {
this.getFilterValues().searchValue = value.toLocaleLowerCase();
this.filterValues.searchValue = value.toLocaleLowerCase();
this.emitFilterValues();
}

protected filterUpdated(value: any[], context: string = ''): void {
switch (context) {
case 'discipline':
this.getFilterValues().disciplineValue = value;
this.filterValues.disciplineValue = value;
break;
case 'gradeLevel':
this.getFilterValues().gradeLevelValue = value;
this.filterValues.gradeLevelValue = value;
break;
case 'standard':
this.getFilterValues().standardValue = value;
this.filterValues.standardValue = value;
break;
case 'feature':
this.getFilterValues().featureValue = value;
this.filterValues.featureValue = value;
break;
case 'unitType':
this.getFilterValues().unitTypeValue = value;
this.filterValues.unitTypeValue = value;
break;
}
this.emitFilterValues();
}

protected getFilterValues(): ProjectFilterValues {
return this.libraryService.filterValues;
}

private emitFilterValues(): void {
this.libraryService.filterValuesUpdated();
}

protected clearFilterValues(): void {
this.getFilterValues().clear();
this.filterValues.clear();
this.emitFilterValues();
}
}
13 changes: 6 additions & 7 deletions src/app/modules/library/library/library.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export abstract class LibraryComponent implements OnInit {
protected showFilters: boolean = false;
protected subscriptions: Subscription = new Subscription();

constructor(protected libraryService: LibraryService) {}
constructor(
protected filterValues: ProjectFilterValues,
protected libraryService: LibraryService
) {}

ngOnInit(): void {
this.subscriptions.add(
Expand All @@ -27,7 +30,7 @@ export abstract class LibraryComponent implements OnInit {
}

ngOnDestroy(): void {
this.getFilterValues().clear();
this.filterValues.clear();
this.subscriptions.unsubscribe();
}

Expand Down Expand Up @@ -59,7 +62,7 @@ export abstract class LibraryComponent implements OnInit {
protected filterUpdated(): void {
this.filteredProjects = this.projects
.map((project) => {
project.visible = this.getFilterValues().matches(project);
project.visible = this.filterValues.matches(project);
return project;
})
.filter((project) => project.visible)
Expand All @@ -82,8 +85,4 @@ export abstract class LibraryComponent implements OnInit {
protected countVisibleProjects(projects: LibraryProject[]): number {
return projects.filter((project) => project.visible).length;
}

private getFilterValues(): ProjectFilterValues {
return this.libraryService.filterValues;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export class MockLibraryService {
implementationModelOptions: LibraryGroup[] = [];
numberOfPublicProjectsVisible = new BehaviorSubject<number>(0);
getOfficialLibraryProjects() {}
filterValues = new ProjectFilterValues();
}

describe('OfficialLibraryComponent', () => {
Expand All @@ -25,7 +24,7 @@ describe('OfficialLibraryComponent', () => {
TestBed.configureTestingModule({
imports: [OverlayModule],
declarations: [OfficialLibraryComponent],
providers: [{ provide: LibraryService, useClass: MockLibraryService }],
providers: [{ provide: LibraryService, useClass: MockLibraryService }, ProjectFilterValues],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { BehaviorSubject } from 'rxjs';
import { Component, Input, ViewEncapsulation } from '@angular/core';
import { LibraryGroup } from '../libraryGroup';
import { LibraryProject } from '../libraryProject';
import { LibraryService } from '../../../services/library.service';
import { LibraryComponent } from '../library/library.component';

@Component({
Expand All @@ -19,10 +18,6 @@ export class OfficialLibraryComponent extends LibraryComponent {
libraryGroups: LibraryGroup[] = [];
expandedGroups: object = {};

constructor(protected libraryService: LibraryService) {
super(libraryService);
}

ngOnInit() {
super.ngOnInit();
this.subscriptions.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { of } from 'rxjs';
import { PersonalLibraryComponent } from './personal-library.component';
import { PersonalLibraryHarness } from './personal-library.harness';
import { ProjectTagService } from '../../../../assets/wise5/services/projectTagService';
import { ProjectFilterValues } from '../../../domain/projectFilterValues';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';

Expand All @@ -32,6 +33,7 @@ describe('PersonalLibraryComponent', () => {
providers: [
ArchiveProjectService,
LibraryService,
ProjectFilterValues,
ProjectTagService,
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ProjectSelectionEvent } from '../../../domain/projectSelectionEvent';
import { SelectAllItemsCheckboxComponent } from '../select-all-items-checkbox/select-all-items-checkbox.component';
import { SelectTagsComponent } from '../../../teacher/select-tags/select-tags.component';
import { Tag } from '../../../domain/tag';
import { ProjectFilterValues } from '../../../domain/projectFilterValues';

@Component({
imports: [
Expand Down Expand Up @@ -57,9 +58,10 @@ export class PersonalLibraryComponent extends LibraryComponent {

constructor(
private archiveProjectService: ArchiveProjectService,
protected filterValues: ProjectFilterValues,
protected libraryService: LibraryService
) {
super(libraryService);
super(filterValues, libraryService);
}

ngOnInit(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { PublicLibraryComponent } from './public-library.component';
import { MockProvider } from 'ng-mocks';
import { LibraryService } from '../../../services/library.service';
import { of } from 'rxjs';
import { ProjectFilterValues } from '../../../domain/projectFilterValues';
import { LibraryProject } from '../libraryProject';
import { ProjectFilterValues } from '../../../domain/projectFilterValues';

describe('PublicLibraryComponent', () => {
let component: PublicLibraryComponent;
Expand All @@ -23,9 +23,9 @@ describe('PublicLibraryComponent', () => {
officialLibraryProjectsSource$: of([
{ id: 1, name: 'P1' },
{ id: 3, name: 'P3' }
] as LibraryProject[]),
filterValues: new ProjectFilterValues()
})
] as LibraryProject[])
}),
ProjectFilterValues
]
}).compileComponents();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { ProjectFilterValues } from '../../../domain/projectFilterValues';
import { MatCheckboxHarness } from '@angular/material/checkbox/testing';
import { MatDialog } from '@angular/material/dialog';
import { LibraryService } from '../../../services/library.service';
import { MockProvider } from 'ng-mocks';

describe('PublicUnitTypeSelectorComponent', () => {
let component: PublicUnitTypeSelectorComponent;
Expand All @@ -17,11 +15,7 @@ describe('PublicUnitTypeSelectorComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [PublicUnitTypeSelectorComponent],
providers: [
MockProvider(LibraryService, {
filterValues: new ProjectFilterValues()
})
]
providers: [ProjectFilterValues]
}).compileComponents();

fixture = TestBed.createComponent(PublicUnitTypeSelectorComponent);
Expand All @@ -40,7 +34,7 @@ describe('PublicUnitTypeSelectorComponent', () => {
it('should update filterValues and emit event when checkbox is clicked', async () => {
const spy = spyOn(component.publicUnitTypeUpdatedEvent, 'emit');
await checkbox1.check();
expect(TestBed.inject(LibraryService).filterValues.publicUnitTypeValue).toEqual(['wiseTested']);
expect(TestBed.inject(ProjectFilterValues).publicUnitTypeValue).toEqual(['wiseTested']);
expect(spy).toHaveBeenCalled();
});

Expand Down
Loading