import { Event } from '../event.model' ; export class SubFilter { filterByMonths : boolean ; monthsThreshold : number ; filterBySubPlan : boolean ; subPlanThreshold : number ; constructor ( ) { this . filterByMonths = false ; this . monthsThreshold = 5 ; this . filterBySubPlan = false ; this . subPlanThreshold = 2000 ; } byMonths ( eventList ) { const tempList = Array < Event > ( ) ; if ( this . filterByMonths ) { if ( this . monthsThreshold !== 0 ) { eventList . forEach ( ( event , index ) => { if ( ! event . didRead ) { if ( + event . months >= this . monthsThreshold && ! event . didBump ) { tempList . unshift ( event ) ; event . didBump = true ; } else { tempList . push ( event ) ; } } else { tempList . push ( event ) ; } } ) ; } } return tempList ; } bySubPlan ( eventList ) { const tempList = Array < Event > ( ) ; if ( this . filterBySubPlan ) { if ( this . subPlanThreshold !== 0 ) { eventList . forEach ( ( event , index ) => { if ( ! event . didRead ) { if ( + event . sub_plan >= this . subPlanThreshold && ! event . didBump ) { event . didBump = true ; tempList . unshift ( event ) ; } else { tempList . push ( event ) ; } } else { tempList . push ( event ) ; } } ) ; } } return tempList ; } }