//Importing the libraries import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core'; import { SelectItem } from 'primeng/api'; //Importing the services import { CompanyService} from '../../shared/service/company.service'; //Importing the core classes import { IOptions } from '../../shared/core/IOptions'; import { ISelectOptionList } from '../../shared/core/ISelectOptionList'; import { ICompanyDashboard } from '../../shared/core/ICompanyDashboard'; import { IFilterKey } from '../../shared/core/IFilterKey'; @Component({ selector: 'app-company-list', templateUrl: './company-list.component.html', styleUrls: ['./company-list.component.scss'] }) export class CompanyListComponent implements OnInit { @Input() LoadData: boolean = false; @Input() OptionsObj: IOptions; @Input() noOfRecordsPerPage_selected:number; @Output() filterListOutput: EventEmitter = new EventEmitter(); @Output() filterResultsByNoOfRecordsInPaginator: EventEmitter = new EventEmitter(); cols: { field: string; header: string; width: string; }[]; documents: any; activity: SelectItem[]; companyList : ICompanyDashboard[]; companyLstFrTblRendering: any[] = []; companyOptions: IOptions; public bulkActions: any[]; selectedValues : string[] =[]; //number of records in the data list companyListCount: number = 0; filterList: ISelectOptionList[] = []; msgs : any; allCount: number = 15; /** for number of records */ noOfRecordsPerPage: any constructor(private companyService : CompanyService ) { } ngOnInit() { // debugger; // list of the activity table columns this.cols = [ // { field: 'companyid', header: '#', width: '3%' }, { field: 'companyname', header: 'Company', width: '10%' }, { field: 'contactcount', header: '# Contacts', width: '10%' }, { field: 'fullname', header: 'Main Contact', width: '10%' }, { field: 'email', header: 'Email', width: '25%' }, { field: 'statusname', header: 'Contact Status', width: '10%' } ]; //preparing parameters and options to retrieve contact list, this collection is the one accepts as the parameter in API this.companyOptions = this.OptionsObj; //calling method with options this.getCompanies(this.companyOptions); /** 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 = [{ // "Company": "Evergreen Accounting", // "Contact": "Amie Nava", // "Status": "Create plan for 2018 Income Tax Compliance Collection Form", // "Subject": "To do", // "Priority":"High", // "Created by ":"Van Le ", // "Due date": " Due today", // "Time": "3hrs" // { // "Company": "Evergreen Accounting", // "Contact": "Amie Nava", // "Status": "Create plan for 2018 Income Tax Compliance Collection Form", // "Subject": "To do", // "Priority":"High", // "Created by ":"Van Le ", // "Due date": " Due today", // "Time": "3hrs" // }] // this.activity = [ // {label:'My activity tasks', value:null} // ] } getCompanies(options: IOptions){ this.companyLstFrTblRendering = []; this.filterList = []; this.msgs = []; this.companyList = []; this.companyService.GetCompanies(options).subscribe(res=>{ this.companyList =res; this.companyListCount = res.length; this.allCount = this.companyListCount; if(this.companyListCount <1){ this.msgs.push({severity:'error', summary:'', detail:'No result found!'}); } var filterByType = this.companyList.filter(x => x.FullName); filterByType.forEach(element => { this.filterList.push({ label: 'Contact:' + element.FullName, value: 'Contact:' + element.FullName }) }); //output options list for dropdown this.filterListOutput.emit(this.filterList); this.companyLstFrTblRendering = []; this.companyList.forEach(element => { this.companyLstFrTblRendering.push({ companyid : element.CompanyId, companyname: element.CompanyName, contactcount : element.ContactCount, fullname: element.FullName, email: element.Email, statusname : element.StatusName }); }); }); //console.log(this.companyLstFrTblRendering); } 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.disableCompany(); } alert("hi maniy") //console.log(event.value); } disableCompany() { let companyIds = [] //To pass data into service this.selectedValues.forEach(element => { companyIds.push(element); }); this.selectedValues.forEach(element => { this.companyLstFrTblRendering = this.companyLstFrTblRendering.filter(function (item) { return item.companyid != element}); }); } filterCompanyListByParent(filterKeys: IFilterKey[]) { console.log("Filter Keys"); console.log(filterKeys); this.companyService.GetCompanyListWithFilter(this.companyOptions, filterKeys).subscribe( res => { this.companyList = []; this.companyList = res; this.companyListCount = res.length; this.allCount = this.companyListCount; if (res.length > 0) { //this.allCount = this.companyList[0]['AllCount']; } else { //this.allCount = 0; } if (this.companyListCount < 1) { this.msgs = []; this.msgs.push({ severity: 'error', summary: '', detail: 'No result found!' }); }else{ this.msgs = []; } this.companyLstFrTblRendering = []; this.companyList.forEach(element => { this.companyLstFrTblRendering.push({ companyid : element.CompanyId, companyname: element.CompanyName, contactcount : element.ContactCount, fullname: element.FullName, email: element.Email, statusname : element.StatusName }); }); } ); } }