//Importing the libraries import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core'; import { SelectItem } from 'primeng/api'; import { Router } from '@angular/router'; import { formatDate } from "@angular/common"; //Importing the core classes import { IOptions } from '../../shared/core/IOptions'; import { ISelectOptionList } from '../../shared/core/ISelectOptionList'; //Importing the service classes import { DashboardService } from '../../shared/service/dashboard.service'; import { IFilterKey } from '../../shared/core/IFilterKey'; @Component({ selector: 'app-leads-list', templateUrl: './leads-list.component.html', styleUrls: ['./leads-list.component.scss'] }) export class LeadsListComponent implements OnInit { @Input() LoadData: boolean = false; @Input() OptionsObj: IOptions; @Input() noOfRecordsPerPage_selected:number; @Output() filterListOutput: EventEmitter = new EventEmitter(); @Output() filterResultsByNoOfRecordsInPaginator: EventEmitter = new EventEmitter(); contactOptions: IOptions; LeadList: any[] = [] LeadLstFrTblRendering: any[] = [] cols: { field: string; header: string; width: string; }[]; documents: any; activity: SelectItem[]; public bulkActions: any[]; //get number of rows in returned data list LeadListCount: number = 0; filterList: ISelectOptionList[] = []; msgs : any; allCount: number = 15; selectedValues: string[] = []; constructor(private dashboardService: DashboardService, private router: Router) { } ngOnInit() { // list of the activity table columns this.cols = [ // { field: 'contactId', header: '#', width: '5%' }, { field: 'leadname', header: 'Lead name', width: '20%' }, { field: 'company', header: 'Company', width: '10%' }, { field: 'email', header: 'Email', width: '10%' }, { field: 'phone', header: 'Phone', width: '10%' }, { field: 'leadsource', header: 'Lead source', width: '15%' }, { field: 'subject', header: 'Subject', width: '10%' }, { field: 'leadowner', header: 'Lead owner', width: '10%' } ]; //preparing parameters and options to retrieve contact list, this collection is the one accepts as the parameter in API this.contactOptions = this.OptionsObj; //calling contact list method this.getLeadList(this.contactOptions); /** Data for bulk actions dropdown */ this.bulkActions = [ { label: 'Bulk Action', value: null }, { label: 'Copy', value: null }, { label: 'Paste', value: null }, { label: 'Delete', value: { id: 3, name: 'Delete' } }]; // this.documents = [{ // "Lead name": "Gina Ellwood ", // "Company": "WestEnd Chartered Accountants", // "Email": "sha@gmail.com", // "Phone": "--", // "Lead source": "Advertisement", // "Subject": "Labor day special ", // "Lead owner": "Van Le", // }, // { // "Lead name": "Gina Ellwood ", // "Company": "WestEnd Chartered Accountants", // "Email": "sha@gmail.com", // "Phone": "--", // "Lead source": "Advertisement", // "Subject": "Labor day special ", // "Lead owner": "Van Le", // }, // { // "Lead name": "Gina Ellwood ", // "Company": "WestEnd Chartered Accountants", // "Email": "sha@gmail.com", // "Phone": "--", // "Lead source": "Advertisement", // "Subject": "Labor day special ", // "Lead owner": "Van Le", // }, // ]; // this.activity = [ // {label:'My activity list', value:null} // ]; } /** this will call service and pass params to call the api */ getLeadList(options: IOptions) { //console.log("inside child"); this.LeadLstFrTblRendering = []; this.filterList = []; this.msgs = []; this.LeadList = []; this.dashboardService.getLeadList(options).subscribe(res => { //debugger; this.LeadList = []; this.LeadList = res; this.LeadListCount = res.length; this.allCount = this.LeadListCount; if(this.LeadListCount <1){ this.msgs.push({severity:'error', summary:'', detail:'No result found!'}); } // preparing fiter option list var filterByType = this.LeadList.filter(x => x.CompanyDetails); this.filterList = []; filterByType.forEach(element => { this.filterList.push({ label: 'Company:' + element.CompanyDetails.CompanyName, value: 'Company:' + element.CompanyDetails.CompanyName }) }); //output options list for dropdown this.filterListOutput.emit(this.filterList); //end of filter options //debugger; this.LeadList.forEach(element => { this.LeadLstFrTblRendering.push({ contactId: element.ContactDetails.ContactDetailsId, leadname: element.ContactDetails.FirstName + " " + element.ContactDetails.LastName, email: element.Email, company: element.CompanyDetails.CompanyName, phone : element.Phone, leadsource : "", subject:"", leadowner: element.Owner }); }); }); } addDays(date: Date, days: number): Date { date.setDate(date.getDate() + days); return date; } //Paginator function paginate(event) { //event.first = Index of the first record //event.rows = Number of rows to display in new page //event.page = Index of the new page //event.pageCount = Total number of pages //console.log("Page number: "+event.page); this.filterResultsByNoOfRecordsInPaginator.emit(event.page+1); } onChangeDropdown(event) { if (event.value != null) { if (event.value['name'] == 'Delete') this.deleteContacts(); } //console.log(event.value); } deleteContacts() { this.selectedValues.forEach(element => { this.LeadLstFrTblRendering = this.LeadLstFrTblRendering.filter(function (item) { return item.email != element; }); }); } filterContactListByParent(filterKeys: IFilterKey[]) { console.log("Filter Keys"); console.log(filterKeys); this.dashboardService.GetLeadsListWithFilter(this.contactOptions, filterKeys).subscribe( res => { this.LeadList = []; this.LeadList = res; this.LeadListCount = res.length; this.allCount = this.LeadListCount; if (res.length > 0) { //this.allCount = this.contactList[0]['AllCount']; } else { //this.allCount = 0; } if (this.LeadListCount < 1) { this.msgs = []; this.msgs.push({ severity: 'error', summary: '', detail: 'No result found!' }); }else{ this.msgs = []; } this.LeadLstFrTblRendering = []; this.LeadList.forEach(element => { this.LeadLstFrTblRendering.push({ contactId: element.ContactDetails.ContactDetailsId, leadname: element.ContactDetails.FirstName + " " + element.ContactDetails.LastName, email: element.Email, company: element.CompanyDetails.CompanyName, phone : element.Phone, leadsource : "", subject:"", leadowner: element.Owner }); }); } ); } }