Skip to content

Commit 8e31574

Browse files
committed
Add Comments and a New Type
1 parent 7844861 commit 8e31574

4 files changed

Lines changed: 127 additions & 15 deletions

File tree

web-app/src/app/event/event.service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { MemberPage, filterChanges } from "./event.types";
2525
import {
2626
Attachment,
2727
Event,
28+
Filter,
2829
Form,
2930
FormField,
3031
Layer,
@@ -155,7 +156,13 @@ export class EventService {
155156
});
156157
}
157158

158-
onFiltersChanged(filter: any): void {
159+
/**
160+
* Updates List of Observations and Users when Filter Changes
161+
* @param {Filter} filter Filter Parametes
162+
* @return {void} No Return
163+
*/
164+
165+
onFiltersChanged(filter: Filter): void {
159166
const event = this.filterService.getEvent();
160167
if (!event) return;
161168

web-app/src/app/filter/filter.component.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,26 @@ export class FilterComponent implements OnInit {
104104
});
105105
}
106106

107+
/**
108+
* Fetches Users for Given Event
109+
* @param {Event} event Event to Get Users From
110+
* @return {Promise<User[]>} Returns List of Users as an Async Promise
111+
*/
112+
107113
async getUsers(event: Event): Promise<User[]> {
108114
const users = await firstValueFrom(this.eventService.getMembers(event));
109115
return users;
110116
}
111117

112-
setFilteredValues(events: Event[], eUsers: User[], eForms: Form[]) {
118+
/**
119+
* Resets Filter When Event is Selected
120+
* @param {Event[]} events List of Events
121+
* @param {User[]} eUsers Users in the Event
122+
* @param {Form[]} eForms Forms in the Event
123+
* @return {void} No Return
124+
*/
125+
126+
setFilteredValues(events: Event[], eUsers: User[], eForms: Form[]): void {
113127
this.events = events;
114128

115129
this.filteredEvents = this.eventControl.valueChanges.pipe(
@@ -190,6 +204,12 @@ export class FilterComponent implements OnInit {
190204
);
191205
}
192206

207+
/**
208+
* Resets Filter When Event is Selected
209+
* @param {MatAutocompleteSelectedEvent} event The Event from the Autocomplete SelectBox
210+
* @return {Promise<void>} No Return
211+
*/
212+
193213
async onSelectEvent(event: MatAutocompleteSelectedEvent): Promise<void> {
194214
this.selectedTeams = [];
195215
this.selectedUsers = [];
@@ -286,6 +306,11 @@ export class FilterComponent implements OnInit {
286306
return option.label === value.label;
287307
};
288308

309+
/**
310+
* Filters Observation List using the FilterService
311+
* @return {void} No Return
312+
*/
313+
289314
onFilter(): void {
290315
var options: IntervalOptions = {};
291316
if (this.intervalChoice.filter === "custom") {

web-app/src/app/filter/filter.service.ts

Lines changed: 88 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ import {
1515
Changes,
1616
Form,
1717
FormProperties,
18+
SearchInterval,
1819
} from "./filter.types";
20+
import { filterChanges } from "../event/event.types";
1921

2022
@Injectable({
2123
providedIn: "root",
2224
})
25+
2326
export class FilterService {
2427
event: Event = null;
2528
teamsById: TeamById = {};
@@ -93,7 +96,13 @@ export class FilterService {
9396
this.listeners = this.listeners.filter((l: any) => l !== listener);
9497
}
9598

96-
setFilter(filter: Filter) {
99+
/**
100+
* Updates the Observation Filter With the Selected Items
101+
* @param {Filter} filter Contains the Selected Filter Values
102+
* @return {void} No Return
103+
*/
104+
105+
setFilter(filter: Filter): void {
97106
var eventChanged = null;
98107
var teamsChanged = null;
99108
var usersChanged = null;
@@ -156,7 +165,13 @@ export class FilterService {
156165
this.filterChanged(changed);
157166
}
158167

159-
setEvent(newEvent: Event) {
168+
/**
169+
* Updates the Event Selected
170+
* @param {Event} newEvent the new Event Selection
171+
* @return {filterChanges} a List of events added/removed from the list
172+
*/
173+
174+
setEvent(newEvent: Event): filterChanges {
160175
if (!newEvent && this.event) {
161176
this.event = null;
162177

@@ -187,7 +202,13 @@ export class FilterService {
187202
return this.event;
188203
}
189204

190-
setUsers(newUsers: User[]) {
205+
/**
206+
* Updates the List of Users in the Selected Event
207+
* @param {User[]} newUser the new List of Users that are in the events
208+
* @return {filterChanges} a List of users added and removed from the list
209+
*/
210+
211+
setUsers(newUsers: User[]): filterChanges {
191212
var added = [];
192213
var removed = [];
193214

@@ -208,7 +229,13 @@ export class FilterService {
208229
};
209230
}
210231

211-
setForms(newForms: Form[]) {
232+
/**
233+
* Updates the List of Forms in the Selected Event
234+
* @param {Form[]} newForms the new List of Forms that are in the events
235+
* @return {filterChanges} a List of forms added and removed from the list
236+
*/
237+
238+
setForms(newForms: Form[]): filterChanges {
212239
var added = [];
213240
var removed = [];
214241

@@ -229,7 +256,13 @@ export class FilterService {
229256
};
230257
}
231258

232-
setTeams(newTeams: Team[]) {
259+
/**
260+
* Updates the List of Teams in the Selected Event
261+
* @param {Team[]} newTeams the new List of Teams that are in the events
262+
* @return {filterChanges} a List of teams added and removed from the list
263+
*/
264+
265+
setTeams(newTeams: Team[]): filterChanges {
233266
var added = [];
234267
var removed = [];
235268

@@ -279,7 +312,13 @@ export class FilterService {
279312
return this.interval;
280313
}
281314

282-
setTimeInterval(newInterval: Interval) {
315+
/**
316+
* Sets the Time Interval if a change was made
317+
* @param {Interval} newInterval Contains the Selected Interval Type and Custom Information
318+
* @return {boolean} If a change was made, returns True, else False
319+
*/
320+
321+
setTimeInterval(newInterval: Interval): boolean {
283322
if (newInterval.choice.filter === "custom") {
284323
if (
285324
this.interval.options?.startDate &&
@@ -297,7 +336,13 @@ export class FilterService {
297336
return true;
298337
}
299338

300-
observationInFilter(o: Observation) {
339+
/**
340+
* Checks to see if the ID is within the list of filters Users
341+
* @param {Observation} o The Current Observation
342+
* @return {boolean} Returns True if Observation is Allowed, or False if Not
343+
*/
344+
345+
observationInFilter(o: Observation): boolean {
301346
if (!this.isObservationInTimeFilter(o)) return false;
302347

303348
if (!this.isUserInTeamFilter(o.userId)) return false;
@@ -322,21 +367,39 @@ export class FilterService {
322367
return true;
323368
}
324369

325-
isUserInList(observationUserId: string) {
370+
/**
371+
* Checks to see if the ID is within the list of filters Users
372+
* @param {string} observationUserId Observations User ID
373+
* @return {boolean} Returns True if Observation is Allowed, or False if Not
374+
*/
375+
376+
isUserInList(observationUserId: string): boolean {
326377
if (this.users.length <= 0) return true;
327378
return this.users.findIndex((u) => u.id === observationUserId) >= 0;
328379
}
329380

330-
hasFormInList(observationForms: FormProperties[]) {
381+
/**
382+
* Checks Incoming Observation to see if it has Forms within the Filter List
383+
* @param {FormProperties[]} observationForms The Current Observations Forms
384+
* @return {boolean} Returns True if Observation is Allowed, or False if Not
385+
*/
386+
387+
hasFormInList(observationForms: FormProperties[]): boolean {
331388
if (this.forms.length <= 0) return true;
332389
var intersection = this.forms
333390
.map((x) => x.id)
334391
.filter((fID) => observationForms.map((y) => y.formId).includes(fID));
335392
return intersection.length > 0;
336393
}
337394

338-
isObservationInTimeFilter(o: Observation) {
339-
var time = this.formatInterval(this.interval);
395+
/**
396+
* Checks Incoming Observation to Make Sure it is Within the Time Constraints
397+
* @param {Observation} o The Current Observation
398+
* @return {boolean} Returns True if Observation is Allowed, or False if Not
399+
*/
400+
401+
isObservationInTimeFilter(o: Observation): boolean {
402+
var time: SearchInterval = this.formatInterval(this.interval);
340403
if (time) {
341404
var properties = o.properties;
342405
if (time?.start && time?.end) {
@@ -350,14 +413,26 @@ export class FilterService {
350413
return true;
351414
}
352415

353-
isUserInTeamFilter(userId: string) {
416+
/**
417+
* Checks to see if the declared username is filtered Team selections
418+
* @param {string} userId the unique ID of the User who Created the Observation
419+
* @return {boolean} Returns True if Observation is Allowed, or False if Not
420+
*/
421+
422+
isUserInTeamFilter(userId: string): boolean {
354423
if (Object.keys(this.teamsById).length === 0) return true;
355424
return Object.values(this.teamsById).some((team: Team) =>
356425
team.userIds.includes(userId)
357426
);
358427
}
359428

360-
formatInterval(interval: Interval) {
429+
/**
430+
* Calculates and Returns the Start and End Time for Selected Interval
431+
* @param {Interval} interval Contains the Selected Interval Type and Custom Information
432+
* @return {SearchInterval} A Start and End Value to Compare DateTimes to
433+
*/
434+
435+
formatInterval(interval: Interval): SearchInterval {
361436
if (!interval) return null;
362437
var choice = interval.choice;
363438
var options = interval.options;

web-app/src/app/filter/filter.types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ export type IntervalOptions = {
8383
localTime?: Boolean;
8484
};
8585

86+
export type SearchInterval = {
87+
start: string;
88+
end: string;
89+
}
90+
8691
export type Interval = {
8792
choice?: FilterChoice;
8893
options?: IntervalOptions;

0 commit comments

Comments
 (0)