diff --git a/src/app/curriculum/curriculum.component.spec.ts b/src/app/curriculum/curriculum.component.spec.ts index f31bdcdf704..78372dd2a0c 100644 --- a/src/app/curriculum/curriculum.component.spec.ts +++ b/src/app/curriculum/curriculum.component.spec.ts @@ -1,4 +1,4 @@ -import { BehaviorSubject, of } from 'rxjs'; +import { of } from 'rxjs'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ConfigService } from '../services/config.service'; import { CurriculumComponent } from './curriculum.component'; @@ -6,9 +6,7 @@ import { LibraryFiltersComponent } from '../modules/library/library-filters/libr import { LibraryService } from '../services/library.service'; import { MockComponents, MockProvider, MockProviders } from 'ng-mocks'; import { PersonalLibraryComponent } from '../modules/library/personal-library/personal-library.component'; -import { ProjectFilterValues } from '../domain/projectFilterValues'; import { PublicLibraryComponent } from '../modules/library/public-library/public-library.component'; -import { User } from '../domain/user'; import { UserService } from '../services/user.service'; describe('CurriculumComponent', () => { @@ -24,7 +22,7 @@ describe('CurriculumComponent', () => { providers: [ MockProviders(ConfigService, UserService), MockProvider(LibraryService, { - projectFilterValuesSource$: of({} as ProjectFilterValues), + filterValuesUpdated$: of(), communityLibraryProjectsSource$: of([]), numberOfPublicProjectsVisible$: of(3), numberOfPersonalProjectsVisible$: of(2) diff --git a/src/app/curriculum/curriculum.component.ts b/src/app/curriculum/curriculum.component.ts index d308745f061..a70a147d7b5 100644 --- a/src/app/curriculum/curriculum.component.ts +++ b/src/app/curriculum/curriculum.component.ts @@ -38,6 +38,7 @@ export class CurriculumComponent { ngOnInit(): void { this.showMyUnits = this.userService.isTeacher(); + this.libraryService.initFilterValues(); this.getLibraryProjects(); this.subscribeNumUnitsVisible(); } diff --git a/src/app/modules/library/community-library/community-library.component.spec.ts b/src/app/modules/library/community-library/community-library.component.spec.ts index cee402fed3b..e9c3da61dce 100644 --- a/src/app/modules/library/community-library/community-library.component.spec.ts +++ b/src/app/modules/library/community-library/community-library.component.spec.ts @@ -3,19 +3,19 @@ import { CommunityLibraryComponent } from './community-library.component'; import { fakeAsyncResponse } from '../../../student/student-run-list/student-run-list.component.spec'; import { LibraryService } from '../../../services/library.service'; import { NO_ERRORS_SCHEMA } from '@angular/core'; -import { MatDialog, MatDialogModule } from '@angular/material/dialog'; -import { BehaviorSubject } from 'rxjs'; +import { MatDialogModule } from '@angular/material/dialog'; +import { BehaviorSubject, of } from 'rxjs'; import { OverlayModule } from '@angular/cdk/overlay'; +import { ProjectFilterValues } from '../../../domain/projectFilterValues'; export class MockLibraryService { implementationModelOptions = []; communityLibraryProjectsSource$ = fakeAsyncResponse([]); - projectFilterValuesSource$ = fakeAsyncResponse({ - searchValue: '', - disciplineValue: [], - standardValue: [] - }); + filterValuesUpdated$ = of(); numberOfPublicProjectsVisible = new BehaviorSubject(0); + getFilterValues() { + return new ProjectFilterValues(); + } } describe('CommunityLibraryComponent', () => { diff --git a/src/app/modules/library/home-page-project-library/home-page-project-library.component.ts b/src/app/modules/library/home-page-project-library/home-page-project-library.component.ts index 09e4e769bff..6545594a939 100644 --- a/src/app/modules/library/home-page-project-library/home-page-project-library.component.ts +++ b/src/app/modules/library/home-page-project-library/home-page-project-library.component.ts @@ -1,13 +1,16 @@ import { Component } from '@angular/core'; import { LibraryService } from '../../../services/library.service'; +import { ProjectFilterValues } from '../../../domain/projectFilterValues'; @Component({ - 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 + 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(); } diff --git a/src/app/modules/library/library-filters/library-filters.component.spec.ts b/src/app/modules/library/library-filters/library-filters.component.spec.ts index 4008e841d57..abd02502c6f 100644 --- a/src/app/modules/library/library-filters/library-filters.component.spec.ts +++ b/src/app/modules/library/library-filters/library-filters.component.spec.ts @@ -22,7 +22,7 @@ describe('LibraryFiltersComponent', () => { communityLibraryProjectsSource$: of([] as LibraryProject[]), sharedLibraryProjectsSource$: of([] as LibraryProject[]), personalLibraryProjectsSource$: of([] as LibraryProject[]), - projectFilterValuesSource$: of({} as ProjectFilterValues), + filterValuesUpdated$: of(), getFilterValues: () => new ProjectFilterValues() }) ] @@ -45,14 +45,14 @@ describe('LibraryFiltersComponent', () => { expect(component['disciplineOptions'].length).toBe(2); }); - it('should call LibraryService.setFilterValues when the search value changes', waitForAsync(() => { - const libraryServiceFilterValuesSpy = spyOn(TestBed.get(LibraryService), 'setFilterValues'); + it('should call LibraryService.filterValuesUpdated when the search value changes', waitForAsync(() => { + const libraryServiceFilterValuesSpy = spyOn(TestBed.get(LibraryService), 'filterValuesUpdated'); component['searchUpdated']('photo'); expect(libraryServiceFilterValuesSpy).toHaveBeenCalled(); })); - it('should call LibraryService.setFilterValues when a filter value changes', waitForAsync(() => { - const libraryServiceFilterValuesSpy = spyOn(TestBed.get(LibraryService), 'setFilterValues'); + it('should call LibraryService.filterValuesUpdated when a filter value changes', waitForAsync(() => { + const libraryServiceFilterValuesSpy = spyOn(TestBed.get(LibraryService), 'filterValuesUpdated'); component['filterUpdated'](['Earth Sciences', 'Physical Sciences'], 'discipline'); expect(libraryServiceFilterValuesSpy).toHaveBeenCalled(); })); diff --git a/src/app/modules/library/library-filters/library-filters.component.ts b/src/app/modules/library/library-filters/library-filters.component.ts index b481b36f855..6da8ae732f6 100644 --- a/src/app/modules/library/library-filters/library-filters.component.ts +++ b/src/app/modules/library/library-filters/library-filters.component.ts @@ -33,7 +33,7 @@ export class LibraryFiltersComponent { private communityProjects: LibraryProject[] = []; protected disciplineOptions: Discipline[] = []; protected featureOptions: Feature[] = []; - protected filterValues: ProjectFilterValues = new ProjectFilterValues(); + protected filterValues: ProjectFilterValues; protected gradeLevelOptions: GradeLevel[] = []; @Input() showAdvancedFilteringOptions: boolean = true; @Input() isSplitScreen: boolean = false; @@ -52,6 +52,7 @@ export class LibraryFiltersComponent { private libraryService: LibraryService, private utilService: UtilService ) { + this.filterValues = this.libraryService.getFilterValues(); libraryService.officialLibraryProjectsSource$.subscribe((projects: LibraryProject[]) => { this.libraryProjects = projects; this.populateFilterOptions(); @@ -170,7 +171,7 @@ export class LibraryFiltersComponent { } private emitFilterValues(): void { - this.libraryService.setFilterValues(this.filterValues); + this.libraryService.filterValuesUpdated(); } protected clearFilterValues(): void { diff --git a/src/app/modules/library/library/library.component.ts b/src/app/modules/library/library/library.component.ts index 16aeab4ebd6..1ef4a1ad608 100644 --- a/src/app/modules/library/library/library.component.ts +++ b/src/app/modules/library/library/library.component.ts @@ -1,4 +1,4 @@ -import { OnInit, QueryList, ViewChildren, Directive } from '@angular/core'; +import { OnInit, QueryList, ViewChildren, Directive, Input } from '@angular/core'; import { ProjectFilterValues } from '../../../domain/projectFilterValues'; import { LibraryService } from '../../../services/library.service'; import { LibraryProject } from '../libraryProject'; @@ -9,7 +9,7 @@ import { MatDialog } from '@angular/material/dialog'; @Directive() export abstract class LibraryComponent implements OnInit { protected filteredProjects: LibraryProject[] = []; - protected filterValues: ProjectFilterValues = new ProjectFilterValues(); + protected filterValues: ProjectFilterValues; protected highIndex: number = 0; protected lowIndex: number = 0; protected pageSizeOptions: number[] = [12, 24, 48, 96]; @@ -26,10 +26,9 @@ export abstract class LibraryComponent implements OnInit { ) {} ngOnInit(): void { + this.filterValues = this.libraryService.getFilterValues(); this.subscriptions.add( - this.libraryService.projectFilterValuesSource$.subscribe((projectFilterValues) => - this.filterUpdated(projectFilterValues) - ) + this.libraryService.filterValuesUpdated$.subscribe(() => this.filterUpdated()) ); } @@ -63,10 +62,7 @@ export abstract class LibraryComponent implements OnInit { return this.lowIndex <= index && index < this.highIndex; } - protected filterUpdated(filterValues: ProjectFilterValues = null): void { - if (filterValues) { - this.filterValues = filterValues; - } + protected filterUpdated(): void { this.filteredProjects = this.projects .map((project) => { project.visible = this.filterValues.matches(project); diff --git a/src/app/modules/library/official-library/official-library.component.spec.ts b/src/app/modules/library/official-library/official-library.component.spec.ts index 6676a58cf91..fa802b25cd7 100644 --- a/src/app/modules/library/official-library/official-library.component.spec.ts +++ b/src/app/modules/library/official-library/official-library.component.spec.ts @@ -4,21 +4,21 @@ import { fakeAsyncResponse } from '../../../student/student-run-list/student-run import { LibraryService } from '../../../services/library.service'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { LibraryGroup } from '../libraryGroup'; -import { MatDialog, MatDialogModule } from '@angular/material/dialog'; -import { BehaviorSubject } from 'rxjs'; +import { MatDialogModule } from '@angular/material/dialog'; +import { BehaviorSubject, of } from 'rxjs'; import { OverlayModule } from '@angular/cdk/overlay'; +import { ProjectFilterValues } from '../../../domain/projectFilterValues'; export class MockLibraryService { libraryGroupsSource$ = fakeAsyncResponse({}); officialLibraryProjectsSource$ = fakeAsyncResponse([]); - projectFilterValuesSource$ = fakeAsyncResponse({ - searchValue: '', - disciplineValue: [], - standardValue: [] - }); + filterValuesUpdated$ = of(); implementationModelOptions: LibraryGroup[] = []; numberOfPublicProjectsVisible = new BehaviorSubject(0); getOfficialLibraryProjects() {} + getFilterValues() { + return new ProjectFilterValues(); + } } describe('OfficialLibraryComponent', () => { diff --git a/src/app/modules/library/personal-library/personal-library.component.spec.ts b/src/app/modules/library/personal-library/personal-library.component.spec.ts index 53527109df1..9b456089c0f 100644 --- a/src/app/modules/library/personal-library/personal-library.component.spec.ts +++ b/src/app/modules/library/personal-library/personal-library.component.spec.ts @@ -1,30 +1,18 @@ import { ArchiveProjectResponse } from '../../../domain/archiveProjectResponse'; -import { ArchiveProjectsButtonComponent } from '../../../teacher/archive-projects-button/archive-projects-button.component'; import { ArchiveProjectService } from '../../../services/archive-project.service'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { fakeAsyncResponse } from '../../../student/student-run-list/student-run-list.component.spec'; -import { FormsModule } from '@angular/forms'; import { HttpClient, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; import { LibraryProject } from '../libraryProject'; -import { LibraryProjectComponent } from '../library-project/library-project.component'; import { LibraryService } from '../../../services/library.service'; -import { MatCheckboxModule } from '@angular/material/checkbox'; -import { MatDialogModule } from '@angular/material/dialog'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatOptionModule } from '@angular/material/core'; -import { MatPaginatorModule } from '@angular/material/paginator'; -import { MatSelectModule } from '@angular/material/select'; -import { MatSnackBarModule } from '@angular/material/snack-bar'; import { of } from 'rxjs'; -import { OverlayModule } from '@angular/cdk/overlay'; import { PersonalLibraryComponent } from './personal-library.component'; import { PersonalLibraryHarness } from './personal-library.harness'; -import { ProjectFilterValues } from '../../../domain/projectFilterValues'; import { ProjectTagService } from '../../../../assets/wise5/services/projectTagService'; import { provideHttpClientTesting } from '@angular/common/http/testing'; -import { SelectAllItemsCheckboxComponent } from '../select-all-items-checkbox/select-all-items-checkbox.component'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; +import { ProjectFilterValues } from '../../../domain/projectFilterValues'; const archivedTag = { id: 1, text: 'archived', color: null }; let archiveProjectService: ArchiveProjectService; @@ -41,22 +29,7 @@ const projectId5 = 5; describe('PersonalLibraryComponent', () => { beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ - imports: [ - ArchiveProjectsButtonComponent, - BrowserAnimationsModule, - FormsModule, - LibraryProjectComponent, - MatCheckboxModule, - MatDialogModule, - MatFormFieldModule, - MatOptionModule, - MatPaginatorModule, - MatSelectModule, - MatSnackBarModule, - OverlayModule, - PersonalLibraryComponent, - SelectAllItemsCheckboxComponent - ], + imports: [BrowserAnimationsModule, PersonalLibraryComponent], providers: [ ArchiveProjectService, LibraryService, @@ -70,6 +43,9 @@ describe('PersonalLibraryComponent', () => { beforeEach(async () => { fixture = TestBed.createComponent(PersonalLibraryComponent); component = fixture.componentInstance; + spyOn(TestBed.inject(LibraryService), 'getFilterValues').and.returnValue( + new ProjectFilterValues() + ); setUpFiveProjects(); archiveProjectService = TestBed.inject(ArchiveProjectService); http = TestBed.inject(HttpClient); @@ -264,17 +240,7 @@ function projectsAreSelected_performSearch_allProjectsAreUnselected() { it('unselects all projects', async () => { await (await harness.getSelectAllCheckbox()).check(); expect(await harness.getSelectedProjectIds()).toEqual([projectId5, projectId4, projectId3]); - component.filterUpdated( - Object.assign(new ProjectFilterValues(), { - disciplineValue: [], - featureValue: [], - gradeLevelValue: [], - publicUnitTypeValue: [], - searchValue: 'world', - standardValue: [], - unitTypeValue: [] - }) - ); + component.filterUpdated(); expect(await harness.getSelectedProjectIds()).toEqual([]); }); }); diff --git a/src/app/modules/library/personal-library/personal-library.component.ts b/src/app/modules/library/personal-library/personal-library.component.ts index ae349b2b311..b7c6650b244 100644 --- a/src/app/modules/library/personal-library/personal-library.component.ts +++ b/src/app/modules/library/personal-library/personal-library.component.ts @@ -16,7 +16,6 @@ import { MatPaginatorModule, PageEvent } from '@angular/material/paginator'; import { MatRadioModule } from '@angular/material/radio'; import { MatSelectModule } from '@angular/material/select'; import { Project } from '../../../domain/project'; -import { ProjectFilterValues } from '../../../domain/projectFilterValues'; 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'; @@ -129,8 +128,8 @@ export class PersonalLibraryComponent extends LibraryComponent { return PersonalLibraryDetailsComponent; } - public filterUpdated(filterValues: ProjectFilterValues = null): void { - super.filterUpdated(filterValues); + public filterUpdated(): void { + super.filterUpdated(); this.filteredProjects = this.filteredProjects.filter( (project) => project.hasTagWithText('archived') == this.showArchivedView ); diff --git a/src/app/modules/library/public-library/public-library.component.html b/src/app/modules/library/public-library/public-library.component.html index 6b794aee694..c53d4d1ec48 100644 --- a/src/app/modules/library/public-library/public-library.component.html +++ b/src/app/modules/library/public-library/public-library.component.html @@ -1,9 +1,6 @@
- + { imports: [PublicLibraryComponent], providers: [ MockProvider(LibraryService, { - projectFilterValuesSource$: of(new ProjectFilterValues()), + filterValuesUpdated$: of(), communityLibraryProjectsSource$: of([ { id: 1, name: 'P1' }, { id: 2, name: 'P2' } @@ -23,7 +23,8 @@ describe('PublicLibraryComponent', () => { officialLibraryProjectsSource$: of([ { id: 1, name: 'P1' }, { id: 3, name: 'P3' } - ] as LibraryProject[]) + ] as LibraryProject[]), + getFilterValues: () => new ProjectFilterValues() }) ] }).compileComponents(); diff --git a/src/app/modules/library/public-library/public-library.component.ts b/src/app/modules/library/public-library/public-library.component.ts index 416a006f5fd..a1e537048ca 100644 --- a/src/app/modules/library/public-library/public-library.component.ts +++ b/src/app/modules/library/public-library/public-library.component.ts @@ -6,7 +6,6 @@ import { LibraryProject } from '../libraryProject'; import { LibraryProjectComponent } from '../library-project/library-project.component'; import { MatDividerModule } from '@angular/material/divider'; import { MatPaginatorModule } from '@angular/material/paginator'; -import { ProjectFilterValues } from '../../../domain/projectFilterValues'; import { PublicUnitTypeSelectorComponent } from '../public-unit-type-selector/public-unit-type-selector.component'; @Component({ @@ -70,14 +69,6 @@ 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 getNumVisiblePersonalOrPublicProjects(): BehaviorSubject { return this.libraryService.numberOfPublicProjectsVisible; } diff --git a/src/app/modules/library/public-unit-type-selector/public-unit-type-selector.component.spec.ts b/src/app/modules/library/public-unit-type-selector/public-unit-type-selector.component.spec.ts index 3d699ab4f77..4780ce7ec79 100644 --- a/src/app/modules/library/public-unit-type-selector/public-unit-type-selector.component.spec.ts +++ b/src/app/modules/library/public-unit-type-selector/public-unit-type-selector.component.spec.ts @@ -5,6 +5,8 @@ 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; @@ -14,15 +16,16 @@ describe('PublicUnitTypeSelectorComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [PublicUnitTypeSelectorComponent] + imports: [PublicUnitTypeSelectorComponent], + providers: [MockProvider(LibraryService)] }).compileComponents(); fixture = TestBed.createComponent(PublicUnitTypeSelectorComponent); loader = TestbedHarnessEnvironment.loader(fixture); component = fixture.componentInstance; - component.filterValues = { + spyOn(TestBed.inject(LibraryService), 'getFilterValues').and.returnValue({ publicUnitTypeValue: [] - } as ProjectFilterValues; + } as ProjectFilterValues); fixture.detectChanges(); [checkbox1, checkbox2] = await loader.getAllHarnesses(MatCheckboxHarness); }); @@ -36,7 +39,9 @@ describe('PublicUnitTypeSelectorComponent', () => { it('should update filterValues and emit event when checkbox is clicked', async () => { const spy = spyOn(component.publicUnitTypeUpdatedEvent, 'emit'); await checkbox1.check(); - expect(component.filterValues.publicUnitTypeValue).toEqual(['wiseTested']); + expect(TestBed.inject(LibraryService).getFilterValues().publicUnitTypeValue).toEqual([ + 'wiseTested' + ]); expect(spy).toHaveBeenCalled(); }); diff --git a/src/app/modules/library/public-unit-type-selector/public-unit-type-selector.component.ts b/src/app/modules/library/public-unit-type-selector/public-unit-type-selector.component.ts index 347de1703c2..67771cd474b 100644 --- a/src/app/modules/library/public-unit-type-selector/public-unit-type-selector.component.ts +++ b/src/app/modules/library/public-unit-type-selector/public-unit-type-selector.component.ts @@ -1,4 +1,4 @@ -import { Component, Directive, EventEmitter, Input, Output } from '@angular/core'; +import { Component, Directive, EventEmitter, Output } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { ProjectFilterValues } from '../../../domain/projectFilterValues'; @@ -12,6 +12,7 @@ import { } from '@angular/material/dialog'; import { RouterLink } from '@angular/router'; import { MatIconModule } from '@angular/material/icon'; +import { LibraryService } from '../../../services/library.service'; @Component({ imports: [FormsModule, MatCheckboxModule, MatIconModule], @@ -27,12 +28,19 @@ import { MatIconModule } from '@angular/material/icon'; }) export class PublicUnitTypeSelectorComponent { protected communityBuilt: boolean; - @Input() filterValues: ProjectFilterValues; + protected filterValues: ProjectFilterValues; @Output() publicUnitTypeUpdatedEvent: EventEmitter = new EventEmitter(); protected wiseTested: boolean; - constructor(private dialog: MatDialog) {} + constructor( + private dialog: MatDialog, + private libraryService: LibraryService + ) {} + + ngOnInit(): void { + this.filterValues = this.libraryService.getFilterValues(); + } protected updatePublicUnitType(): void { this.filterValues.publicUnitTypeValue = []; @@ -42,7 +50,7 @@ export class PublicUnitTypeSelectorComponent { if (this.communityBuilt) { this.filterValues.publicUnitTypeValue.push('communityBuilt'); } - this.publicUnitTypeUpdatedEvent.emit(this.filterValues); + this.publicUnitTypeUpdatedEvent.emit(); } protected showInfo(type: 'community' | 'official'): void { diff --git a/src/app/modules/library/teacher-project-library/teacher-project-library.component.spec.ts b/src/app/modules/library/teacher-project-library/teacher-project-library.component.spec.ts index 621112fadaa..bc5fb680af1 100644 --- a/src/app/modules/library/teacher-project-library/teacher-project-library.component.spec.ts +++ b/src/app/modules/library/teacher-project-library/teacher-project-library.component.spec.ts @@ -5,6 +5,7 @@ import { NO_ERRORS_SCHEMA } from '@angular/core'; import { RouterTestingModule } from '@angular/router/testing'; import { LibraryService } from '../../../services/library.service'; import { defer } from 'rxjs'; +import { ProjectFilterValues } from '../../../domain/projectFilterValues'; export function fakeAsyncResponse(data: T) { return defer(() => Promise.resolve(data)); @@ -18,6 +19,10 @@ export class MockLibraryService { getCommunityLibraryProjects() {} getPersonalLibraryProjects() {} getSharedLibraryProjects() {} + getFilterValues() { + return new ProjectFilterValues(); + } + initFilterValues() {} } describe('TeacherProjectLibraryComponent', () => { diff --git a/src/app/modules/library/teacher-project-library/teacher-project-library.component.ts b/src/app/modules/library/teacher-project-library/teacher-project-library.component.ts index fc327f8d316..5f993ba3978 100644 --- a/src/app/modules/library/teacher-project-library/teacher-project-library.component.ts +++ b/src/app/modules/library/teacher-project-library/teacher-project-library.component.ts @@ -27,6 +27,7 @@ export class TeacherProjectLibraryComponent implements OnInit { ) {} ngOnInit() { + this.libraryService.initFilterValues(); this.libraryService.numberOfPublicProjectsVisible$.subscribe((num) => { this.tabs[0].numVisible = num; }); diff --git a/src/app/services/library.service.ts b/src/app/services/library.service.ts index 1ed4a898459..19b25db62e8 100644 --- a/src/app/services/library.service.ts +++ b/src/app/services/library.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { Observable, BehaviorSubject } from 'rxjs'; +import { Observable, BehaviorSubject, Subject } from 'rxjs'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { LibraryGroup } from '../modules/library/libraryGroup'; import { LibraryProject } from '../modules/library/libraryProject'; @@ -11,6 +11,9 @@ import { Router } from '@angular/router'; export class LibraryService { private libraryGroupsUrl = '/api/project/library'; private communityProjectsUrl = '/api/project/community'; + private filterValues: ProjectFilterValues = new ProjectFilterValues(); + private filterValuesUpdatedSource = new Subject(); + public filterValuesUpdated$ = this.filterValuesUpdatedSource.asObservable(); private personalProjectsUrl = '/api/project/personal'; private sharedProjectsUrl = '/api/project/shared'; private copyProjectUrl = '/api/project/copy'; @@ -26,10 +29,6 @@ export class LibraryService { public personalLibraryProjectsSource$ = this.personalLibraryProjectsSource.asObservable(); private sharedLibraryProjectsSource = new BehaviorSubject([]); public sharedLibraryProjectsSource$ = this.sharedLibraryProjectsSource.asObservable(); - private projectFilterValuesSource = new BehaviorSubject( - new ProjectFilterValues() - ); - public projectFilterValuesSource$ = this.projectFilterValuesSource.asObservable(); private newProjectSource = new BehaviorSubject(null); public newProjectSource$ = this.newProjectSource.asObservable(); public numberOfPublicProjectsVisible = new BehaviorSubject(0); @@ -132,12 +131,8 @@ export class LibraryService { return this.http.post(this.copyProjectUrl, body, { headers: headers }); } - setFilterValues(projectFilterValues: ProjectFilterValues) { - this.projectFilterValuesSource.next(projectFilterValues); - } - - getFilterValues(): ProjectFilterValues { - return this.projectFilterValuesSource.value; + filterValuesUpdated(): void { + this.filterValuesUpdatedSource.next(); } addPersonalLibraryProject(project: LibraryProject) { @@ -163,6 +158,14 @@ export class LibraryService { this.communityLibraryProjectsSource.next([]); this.personalLibraryProjectsSource.next([]); this.sharedLibraryProjectsSource.next([]); - this.projectFilterValuesSource.next(new ProjectFilterValues()); + this.filterValuesUpdatedSource.next(); + } + + getFilterValues(): ProjectFilterValues { + return this.filterValues; + } + + initFilterValues(): void { + this.filterValues = new ProjectFilterValues(); } } diff --git a/src/messages.xlf b/src/messages.xlf index b3c113cd105..0e5f86826e4 100644 --- a/src/messages.xlf +++ b/src/messages.xlf @@ -2369,14 +2369,14 @@ Click "Cancel" to keep the invalid JSON open so you can fix it.Public () src/app/curriculum/curriculum.component.ts - 72 + 73 My Units () src/app/curriculum/curriculum.component.ts - 76 + 77 @@ -5871,7 +5871,7 @@ Click "Cancel" to keep the invalid JSON open so you can fix it.NGSS src/app/modules/library/library-filters/library-filters.component.ts - 111 + 112 src/app/modules/library/library-project-details/library-project-details.component.ts @@ -5882,7 +5882,7 @@ Click "Cancel" to keep the invalid JSON open so you can fix it.Common Core src/app/modules/library/library-filters/library-filters.component.ts - 112 + 113 src/app/modules/library/library-project-details/library-project-details.component.ts @@ -5893,7 +5893,7 @@ Click "Cancel" to keep the invalid JSON open so you can fix it.Learning For Justice src/app/modules/library/library-filters/library-filters.component.ts - 113 + 114 src/app/modules/library/library-project-details/library-project-details.component.ts @@ -6338,14 +6338,14 @@ Click "Cancel" to keep the invalid JSON open so you can fix it. src/app/modules/library/public-library/public-library.component.html - 23,27 + 20,24 Select all units src/app/modules/library/personal-library/personal-library.component.ts - 56 + 55