/** Angular Imports */ import { Component , OnInit , ViewChild } from '@angular/core' ; import { ActivatedRoute } from '@angular/router' ; import { MatPaginator } from '@angular/material/paginator' ; import { MatSort } from '@angular/material/sort' ; import { MatTableDataSource } from '@angular/material/table' ; /**
 * View Survey component.
 */ @ Component ( { selector : 'mifosx-view-survey' , templateUrl : './view-survey.component.html' , styleUrls : [ './view-survey.component.scss' ] } ) export class ViewSurveyComponent implements OnInit { /** Survey Data */ surveyData : any ; /** Data source for view surveys table. */ dataSource : MatTableDataSource < any > ; /** Columns to be displayed in list of surveys table. */ displayedColumns : string [ ] = [ 'surveyName' , 'createdBy' , 'date' , 'score' ] ; /** Paginator for list of surveys table. */ @ ViewChild ( MatPaginator , { static : true } ) paginator : MatPaginator ; /** Sorter for list of surveys table. */ @ ViewChild ( MatSort , { static : true } ) sort : MatSort ; param { ActivatedRoute } route constructor ( private route ) { this . route . data . subscribe ( ( data ) => { this . surveyData = data . clientActionData ; } ) ; } ngOnInit ( ) { this . constructSurveys ( this . surveyData ) ; } param data constructSurveys ( data ) { let surveys = [ ] ; data . forEach ( ( entry ) => { const scoreCards = entry . scorecardValues . map ( ( element ) => { return { surveyName : entry . surveyName , createdBy : entry . username , date : element . createdOn , score : element . value } ; } ) ; surveys = surveys . concat ( scoreCards ) ; } ) ; this . dataSource = new MatTableDataSource ( surveys ) ; this . dataSource . paginator = this . paginator ; this . dataSource . sort = this . sort ; } param { string } filterValue applyFilter ( filterValue ) { this . dataSource . filter = filterValue . trim ( ) . toLowerCase ( ) ; } }