-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprojectFilterValues.ts
More file actions
142 lines (129 loc) · 4.31 KB
/
Copy pathprojectFilterValues.ts
File metadata and controls
142 lines (129 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { Subject } from 'rxjs';
import { LibraryProject } from '../modules/library/libraryProject';
import { Location } from '../modules/library/Location';
export class ProjectFilterValues {
disciplineValue: string[] = [];
featureValue: string[] = [];
gradeLevelValue: number[] = [];
locationValue: string[] = [];
publicUnitType?: ('wiseTested' | 'communityBuilt')[] = [];
publicUnitTypeValue?: ('wiseTested' | 'communityBuilt')[] = [];
searchValue: string = '';
standardValue: string[] = [];
unitTypeValue: string[] = [];
private updatedSource = new Subject<void>();
public updated$ = this.updatedSource.asObservable();
matches(project: LibraryProject): boolean {
return (
this.matchesSearch(project) &&
this.matchesPublicUnitType(project) &&
this.matchesStandard(project) &&
this.matchesDiscipline(project) &&
this.matchesUnitType(project) &&
this.matchesFeature(project) &&
this.matchesGradeLevel(project) &&
this.matchesLocation(project)
);
}
private matchesSearch(project: LibraryProject): boolean {
project.metadata.id = project.id;
return (
!this.searchValue ||
Object.keys(project.metadata)
.filter((prop) =>
// only check for match in specific metadata fields
['title', 'summary', 'keywords', 'features', 'standards', 'id'].includes(prop)
)
.some((prop) => {
let value = project.metadata[prop];
if (prop === 'standards') {
value = JSON.stringify(value);
}
return (
typeof value !== 'undefined' &&
value != null &&
value.toString().toLocaleLowerCase().indexOf(this.searchValue) !== -1
);
})
);
}
hasFilters(): boolean {
return (
this.standardValue.length +
this.disciplineValue.length +
this.unitTypeValue.length +
this.gradeLevelValue.length +
this.featureValue.length +
this.locationValue.length >
0
);
}
clear(): void {
this.disciplineValue = [];
this.featureValue = [];
this.gradeLevelValue = [];
this.publicUnitTypeValue = [];
this.searchValue = '';
this.standardValue = [];
this.unitTypeValue = [];
this.locationValue = [];
}
private matchesUnitType(project: LibraryProject): boolean {
const unitTypeValue =
project.metadata.unitType === 'Platform' ? 'WISE Platform' : 'Other Platform';
return this.unitTypeValue.length === 0 || this.unitTypeValue?.includes(unitTypeValue);
}
private matchesPublicUnitType(project: LibraryProject): boolean {
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 (
this.standardValue.length === 0 ||
[...commonCore, ...ngss, ...learningForJustice].some((val) =>
this.standardValue.includes(val.id)
)
);
}
private matchesLocation(project: LibraryProject): boolean {
return (
this.locationValue.length === 0 ||
project.metadata.locations
?.map((location) => Object.assign(new Location(), location))
.map((location) => location.getLocationOptions())
.flat()
.some((locationOption) => this.locationValue.includes(locationOption.name))
);
}
private matchesFeature(project: LibraryProject): boolean {
return (
this.featureValue.length === 0 ||
project.metadata.features?.some((feature) => this.featureValue.includes(feature.name))
);
}
private matchesDiscipline(project: LibraryProject): boolean {
return (
this.disciplineValue.length === 0 ||
project.metadata.disciplines?.some((discipline) =>
this.disciplineValue.includes(discipline.id)
)
);
}
private matchesGradeLevel(project: LibraryProject): boolean {
return (
this.gradeLevelValue.length === 0 ||
project.metadata.grades?.some((gradeLevel) =>
this.gradeLevelValue.includes(Number(gradeLevel))
)
);
}
emitUpdated(): void {
this.updatedSource.next();
}
}