Skip to content

Commit 442fc92

Browse files
refactor(LibraryService): Move ProjectFilterValues out of class (#2169)
1 parent 368a204 commit 442fc92

16 files changed

+53
-75
lines changed

src/app/curriculum/curriculum.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Subscription } from 'rxjs';
1111
import { UserService } from '../services/user.service';
1212
import { MatButtonModule } from '@angular/material/button';
1313
import { Router, RouterModule } from '@angular/router';
14+
import { ProjectFilterValues } from '../domain/projectFilterValues';
1415

1516
@Component({
1617
imports: [
@@ -23,6 +24,7 @@ import { Router, RouterModule } from '@angular/router';
2324
PublicLibraryComponent,
2425
RouterModule
2526
],
27+
providers: [ProjectFilterValues],
2628
styleUrl: './curriculum.component.scss',
2729
templateUrl: './curriculum.component.html'
2830
})
@@ -41,7 +43,6 @@ export class CurriculumComponent {
4143

4244
ngOnInit(): void {
4345
this.showMyUnits = this.userService.isTeacher();
44-
this.libraryService.initFilterValues();
4546
this.getLibraryProjects();
4647
this.subscribeNumUnitsVisible();
4748
}

src/app/domain/projectFilterValues.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ export class ProjectFilterValues {
5757
}
5858

5959
clear(): void {
60-
this.standardValue = [];
6160
this.disciplineValue = [];
62-
this.unitTypeValue = [];
63-
this.gradeLevelValue = [];
6461
this.featureValue = [];
62+
this.gradeLevelValue = [];
63+
this.publicUnitTypeValue = [];
64+
this.searchValue = '';
65+
this.standardValue = [];
66+
this.unitTypeValue = [];
6567
}
6668

6769
private matchesUnitType(project: LibraryProject): boolean {

src/app/modules/library/home-page-project-library/home-page-project-library.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import { LibraryService } from '../../../services/library.service';
33
import { ProjectFilterValues } from '../../../domain/projectFilterValues';
44

55
@Component({
6+
providers: [ProjectFilterValues],
67
selector: 'app-home-page-project-library',
78
styleUrls: ['./home-page-project-library.component.scss', '../library/library.component.scss'],
89
templateUrl: './home-page-project-library.component.html',
910
standalone: false
1011
})
1112
export class HomePageProjectLibraryComponent {
12-
protected filterValues: ProjectFilterValues = new ProjectFilterValues();
13-
1413
constructor(private libraryService: LibraryService) {
1514
libraryService.getOfficialLibraryProjects();
1615
}

src/app/modules/library/library-filters/library-filters.component.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="library-filter">
22
<div class="flex flex-row gap-1">
33
<div class="flex-auto max-w-full">
4-
<app-search-bar [value]="getFilterValues().searchValue" (update)="searchUpdated($event)" />
4+
<app-search-bar [value]="filterValues.searchValue" (update)="searchUpdated($event)" />
55
</div>
66
<button
77
mat-icon-button
@@ -15,7 +15,7 @@
1515
matBadgeDescription="Filters applied"
1616
matBadgeOverlap="true"
1717
matBadgeSize="small"
18-
[matBadgeHidden]="!getFilterValues().hasFilters()"
18+
[matBadgeHidden]="!filterValues.hasFilters()"
1919
aria-hidden="false"
2020
>filter_list</mat-icon
2121
>
@@ -25,7 +25,7 @@
2525
<div class="library-filters" [class.expand]="showFilters" [class.isSplitScreen]="isSplitScreen">
2626
<div class="notice flex justify-between">
2727
<h3 class="mat-subtitle-2" i18n>Filters</h3>
28-
@if (getFilterValues().hasFilters()) {
28+
@if (filterValues.hasFilters()) {
2929
<a href="#" (click)="!!clearFilterValues()" i18n>Clear all</a>
3030
}
3131
</div>
@@ -43,7 +43,7 @@ <h3 class="mat-subtitle-2" i18n>Filters</h3>
4343
[options]="unitTypeOptions"
4444
i18n-placeholderText
4545
placeholderText="Type"
46-
[value]="getFilterValues().unitTypeValue"
46+
[value]="filterValues.unitTypeValue"
4747
(update)="filterUpdated($event, 'unitType')"
4848
[valueProp]="'name'"
4949
[viewValueProp]="'name'"
@@ -61,7 +61,7 @@ <h3 class="mat-subtitle-2" i18n>Filters</h3>
6161
[options]="disciplineOptions"
6262
i18n-placeholderText
6363
placeholderText="Discipline"
64-
[value]="getFilterValues().disciplineValue"
64+
[value]="filterValues.disciplineValue"
6565
(update)="filterUpdated($event, 'discipline')"
6666
[valueProp]="'id'"
6767
[viewValueProp]="'name'"
@@ -79,7 +79,7 @@ <h3 class="mat-subtitle-2" i18n>Filters</h3>
7979
[options]="gradeLevelOptions"
8080
i18n-placeholderText
8181
placeholderText="Grade Level"
82-
[value]="getFilterValues().gradeLevelValue"
82+
[value]="filterValues.gradeLevelValue"
8383
(update)="filterUpdated($event, 'gradeLevel')"
8484
valueProp="grade"
8585
viewValueProp="grade"
@@ -98,7 +98,7 @@ <h3 class="mat-subtitle-2" i18n>Filters</h3>
9898
[possibleLabels]="possibleStandardLabels"
9999
i18n-placeholderText
100100
placeholderText="Standards Addressed"
101-
[value]="getFilterValues().standardValue"
101+
[value]="filterValues.standardValue"
102102
(update)="filterUpdated($event, 'standard')"
103103
[valueProp]="'id'"
104104
[viewValueProp]="'name'"
@@ -115,7 +115,7 @@ <h3 class="mat-subtitle-2" i18n>Filters</h3>
115115
[options]="featureOptions"
116116
i18n-placeholderText
117117
placeholderText="Features"
118-
[value]="getFilterValues().featureValue"
118+
[value]="filterValues.featureValue"
119119
(update)="filterUpdated($event, 'feature')"
120120
valueProp="name"
121121
viewValueProp="name"

src/app/modules/library/library-filters/library-filters.component.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { LibraryService } from '../../../services/library.service';
44
import sampleLibraryProjects from '../sampleLibraryProjects';
55
import { SimpleChange } from '@angular/core';
66
import { LibraryProject } from '../libraryProject';
7-
import { ProjectFilterValues } from '../../../domain/projectFilterValues';
87
import { MockProvider } from 'ng-mocks';
98
import { of } from 'rxjs';
9+
import { ProjectFilterValues } from '../../../domain/projectFilterValues';
1010

1111
describe('LibraryFiltersComponent', () => {
1212
let component: LibraryFiltersComponent;
@@ -22,9 +22,9 @@ describe('LibraryFiltersComponent', () => {
2222
communityLibraryProjectsSource$: of([] as LibraryProject[]),
2323
sharedLibraryProjectsSource$: of([] as LibraryProject[]),
2424
personalLibraryProjectsSource$: of([] as LibraryProject[]),
25-
filterValuesUpdated$: of(),
26-
filterValues: new ProjectFilterValues()
27-
})
25+
filterValuesUpdated$: of()
26+
}),
27+
ProjectFilterValues
2828
]
2929
});
3030
projects = sampleLibraryProjects;

src/app/modules/library/library-filters/library-filters.component.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class LibraryFiltersComponent {
4848
];
4949

5050
constructor(
51+
protected filterValues: ProjectFilterValues,
5152
private libraryService: LibraryService,
5253
private utilService: UtilService
5354
) {
@@ -143,41 +144,37 @@ export class LibraryFiltersComponent {
143144
}
144145

145146
protected searchUpdated(value: string): void {
146-
this.getFilterValues().searchValue = value.toLocaleLowerCase();
147+
this.filterValues.searchValue = value.toLocaleLowerCase();
147148
this.emitFilterValues();
148149
}
149150

150151
protected filterUpdated(value: any[], context: string = ''): void {
151152
switch (context) {
152153
case 'discipline':
153-
this.getFilterValues().disciplineValue = value;
154+
this.filterValues.disciplineValue = value;
154155
break;
155156
case 'gradeLevel':
156-
this.getFilterValues().gradeLevelValue = value;
157+
this.filterValues.gradeLevelValue = value;
157158
break;
158159
case 'standard':
159-
this.getFilterValues().standardValue = value;
160+
this.filterValues.standardValue = value;
160161
break;
161162
case 'feature':
162-
this.getFilterValues().featureValue = value;
163+
this.filterValues.featureValue = value;
163164
break;
164165
case 'unitType':
165-
this.getFilterValues().unitTypeValue = value;
166+
this.filterValues.unitTypeValue = value;
166167
break;
167168
}
168169
this.emitFilterValues();
169170
}
170171

171-
protected getFilterValues(): ProjectFilterValues {
172-
return this.libraryService.filterValues;
173-
}
174-
175172
private emitFilterValues(): void {
176173
this.libraryService.filterValuesUpdated();
177174
}
178175

179176
protected clearFilterValues(): void {
180-
this.getFilterValues().clear();
177+
this.filterValues.clear();
181178
this.emitFilterValues();
182179
}
183180
}

src/app/modules/library/library/library.component.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export abstract class LibraryComponent implements OnInit {
1818
protected showFilters: boolean = false;
1919
protected subscriptions: Subscription = new Subscription();
2020

21-
constructor(protected libraryService: LibraryService) {}
21+
constructor(
22+
protected filterValues: ProjectFilterValues,
23+
protected libraryService: LibraryService
24+
) {}
2225

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

2932
ngOnDestroy(): void {
30-
this.getFilterValues().clear();
33+
this.filterValues.clear();
3134
this.subscriptions.unsubscribe();
3235
}
3336

@@ -59,7 +62,7 @@ export abstract class LibraryComponent implements OnInit {
5962
protected filterUpdated(): void {
6063
this.filteredProjects = this.projects
6164
.map((project) => {
62-
project.visible = this.getFilterValues().matches(project);
65+
project.visible = this.filterValues.matches(project);
6366
return project;
6467
})
6568
.filter((project) => project.visible)
@@ -82,8 +85,4 @@ export abstract class LibraryComponent implements OnInit {
8285
protected countVisibleProjects(projects: LibraryProject[]): number {
8386
return projects.filter((project) => project.visible).length;
8487
}
85-
86-
private getFilterValues(): ProjectFilterValues {
87-
return this.libraryService.filterValues;
88-
}
8988
}

src/app/modules/library/official-library/official-library.component.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export class MockLibraryService {
1515
implementationModelOptions: LibraryGroup[] = [];
1616
numberOfPublicProjectsVisible = new BehaviorSubject<number>(0);
1717
getOfficialLibraryProjects() {}
18-
filterValues = new ProjectFilterValues();
1918
}
2019

2120
describe('OfficialLibraryComponent', () => {
@@ -25,7 +24,7 @@ describe('OfficialLibraryComponent', () => {
2524
TestBed.configureTestingModule({
2625
imports: [OverlayModule],
2726
declarations: [OfficialLibraryComponent],
28-
providers: [{ provide: LibraryService, useClass: MockLibraryService }],
27+
providers: [{ provide: LibraryService, useClass: MockLibraryService }, ProjectFilterValues],
2928
schemas: [NO_ERRORS_SCHEMA]
3029
}).compileComponents();
3130
}));

src/app/modules/library/official-library/official-library.component.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { BehaviorSubject } from 'rxjs';
22
import { Component, Input, ViewEncapsulation } from '@angular/core';
33
import { LibraryGroup } from '../libraryGroup';
44
import { LibraryProject } from '../libraryProject';
5-
import { LibraryService } from '../../../services/library.service';
65
import { LibraryComponent } from '../library/library.component';
76

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

22-
constructor(protected libraryService: LibraryService) {
23-
super(libraryService);
24-
}
25-
2621
ngOnInit() {
2722
super.ngOnInit();
2823
this.subscriptions.add(

src/app/modules/library/personal-library/personal-library.component.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { of } from 'rxjs';
1010
import { PersonalLibraryComponent } from './personal-library.component';
1111
import { PersonalLibraryHarness } from './personal-library.harness';
1212
import { ProjectTagService } from '../../../../assets/wise5/services/projectTagService';
13+
import { ProjectFilterValues } from '../../../domain/projectFilterValues';
1314
import { provideHttpClientTesting } from '@angular/common/http/testing';
1415
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
1516

@@ -32,6 +33,7 @@ describe('PersonalLibraryComponent', () => {
3233
providers: [
3334
ArchiveProjectService,
3435
LibraryService,
36+
ProjectFilterValues,
3537
ProjectTagService,
3638
provideHttpClient(withInterceptorsFromDi()),
3739
provideHttpClientTesting()

0 commit comments

Comments
 (0)