import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { OrgForApplicant } from '@core/typings/organization.typing'; import { NonprofitService } from '@features/nonprofit/nonprofit.service'; import { DebounceFactory, PaginationOptions, TableDataFactory, TopLevelFilter } from '@yourcause/common'; import { I18nService } from '@yourcause/common/i18n'; import { ApplicantManagerService } from '../applicant-manager.service'; @Component({ selector: 'gc-applicant-organizations', templateUrl: './applicant-organizations.component.html', styleUrls: ['./applicant-organizations.component.scss'] }) export class ApplicantOrganizationsComponent implements OnInit { tableDataFactory: TableDataFactory; id: string; tableKey: string; topLevelFilters: TopLevelFilter[] = []; fromRoute = this.applicantManagerService.getFromRouteForProfile(); constructor ( private applicantManagerService: ApplicantManagerService, private activatedRoute: ActivatedRoute, private i18n: I18nService, private nonprofitService: NonprofitService ) { } get nonprofitRouterLink () { return this.nonprofitService.get('nonprofitProfileRouterLink'); } ngOnInit () { this.topLevelFilters = [ new TopLevelFilter( 'text', 'name', '', this.i18n.translate( 'common:textSearchByOrganization', {}, 'Search by organization' ), undefined, undefined, [{ column: 'name', filterType: 'cn' }, { column: 'orgIdentification', filterType: 'cn' }] ) ]; this.setTableDataFactory(); } setTableDataFactory () { this.id = this.activatedRoute.snapshot.parent.params.id; this.tableKey = `APPLICANT_ORGS_${this.id}`; this.tableDataFactory = DebounceFactory.createSimple( async (options: PaginationOptions) => { const result = await this.applicantManagerService.getOrgsForApplicant( +this.id, options ); return { success: true, data: { recordCount: result.recordCount, records: result.records.map((record: OrgForApplicant) => { this.setNonprofitRouterLinkMap( (record.nonprofitGuid as any) || record.id ); return record; }) } }; } ); } setNonprofitRouterLinkMap (id: number) { const appId = this.activatedRoute.parent ? this.activatedRoute.parent.snapshot.params.id : null; this.nonprofitService.setNonprofitRouterLinkMap( id, appId ); } }