/** Angular Imports */ import { Component , OnInit , ViewChild } from '@angular/core' ; import { MatPaginator } from '@angular/material/paginator' ; import { MatSort } from '@angular/material/sort' ; import { MatTableDataSource } from '@angular/material/table' ; import { ActivatedRoute } from '@angular/router' ; /**
 * Manage Surveys component.
 */ @ Component ( { selector : 'mifosx-manage-surveys' , templateUrl : './manage-surveys.component.html' , styleUrls : [ './manage-surveys.component.scss' ] , } ) export class ManageSurveysComponent implements OnInit { surveysData : any ; displayedColumns : string [ ] = [ 'key' , 'name' , 'description' , 'countryCode' , 'status' , 'action' ] ; dataSource : MatTableDataSource < any > ; /** Paginator for manage surveys table. */ @ ViewChild ( MatPaginator , { static : true } ) paginator : MatPaginator ; /** Sorter for manage surveys table. */ @ ViewChild ( MatSort , { static : true } ) sort : MatSort ; param { ActivatedRoute } route constructor ( private route ) { this . route . data . subscribe ( ( data ) => { this . surveysData = data . surveys ; } ) ; } param { number } validFrom param { number } validTo isActive ( validFrom , validTo ) { const curdate = new Date ( ) . getTime ( ) ; return ( curdate > validFrom && curdate < validTo ) ; } /**
     * Sets the manage surveys table. And initiates button and action sort
     */ ngOnInit ( ) { this . setSurveys ( ) ; this . dataSource . sortingDataAccessor = ( item , property ) => { switch ( property ) { case 'status' : return this . isActive ( item . validFrom , item . validTo ) ; case 'action' : return this . isActive ( item . validFrom , item . validTo ) ; default : return item [ property ] ; } } ; } /**
     * Initializes the data source, paginator and sorter for surveys table.
     */ setSurveys ( ) { this . dataSource = new MatTableDataSource ( this . surveysData ) ; this . dataSource . paginator = this . paginator ; this . dataSource . sort = this . sort ; } param { string } filterValue applyFilter ( filterValue ) { this . dataSource . filter = filterValue . trim ( ) . toLowerCase ( ) ; } }