@@ -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+
2326export 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 ;
0 commit comments