import { Component, OnInit } from '@angular/core'; import { SelectItem} from "primeng/primeng"; import { LoginHistoryService } from '../shared/service/login-history.service'; import { ISelectedFilter } from '../shared/core/ISelectedFilter'; @Component({ selector: 'app-logged-time', templateUrl: './logged-time.component.html', styleUrls: ['./logged-time.component.css'] }) export class LoggedTimeComponent implements OnInit { //this variable contains data set of the charts LoggedHistoryData : any; //this variable is use for search & filter component type = "SLT"; //list of filters to provide as a input to search and filter component dateFiltersList : SelectItem[]; personFilterList : SelectItem[]; //variables to catch values from output from sarch n filter component selectedFilterList : ISelectedFilter; searchValue: string; constructor(private loginHistoryService: LoginHistoryService) { } ngOnInit() { //calling date range filters this.getDateRangeFilters(); //calling person type filters //this.getPersonTypeFilters(); //calling method to get dataset for charts this.getStaffLoggedTime(); } //call the service , send date range, person type, search value as params if any, bind the repsonse to chart dataset getStaffLoggedTime(dateRange?: string, filterBy?: string, filetersearch?: string ){ this.loginHistoryService.getStaffLoggedTime(dateRange, filterBy, filetersearch).subscribe(logData =>{ this.LoggedHistoryData = logData; }) } //this method call service for date range filters list getDateRangeFilters(){ this.loginHistoryService.getMonthYearFilters().subscribe(f =>{ //filters list as a response from service this.dateFiltersList = f; }) } //this method call service for person type filters list getPersonTypeFilters(){ this.loginHistoryService.getPersonTypeFilters().subscribe(f =>{ //filters list as a response from service this.personFilterList = f; }) } //this method get selected data from filters getSelectedFilterList(value : ISelectedFilter){ this.selectedFilterList = value; this.bindFilter(); } getSearchValue(value: string){ this.searchValue = value; this.bindFilter(); } //this method send all filter values to the service and refresh charts with the response bindFilter(){ this.getStaffLoggedTime(this.selectedFilterList.DateRange,this.selectedFilterList.PersonType, this.searchValue); } }