From 85f558245c1b086c43de19b77e97599ff3424465 Mon Sep 17 00:00:00 2001 From: rmroot Date: Tue, 19 Nov 2024 08:36:46 -0600 Subject: [PATCH] update button label on select kpi page --- .../company-kpi-select.component.html | 7 ++++- .../company-kpi-select.component.ts | 27 +++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/app/setup-wizard/pre-visit/company-kpi-select/company-kpi-select.component.html b/src/app/setup-wizard/pre-visit/company-kpi-select/company-kpi-select.component.html index 3fbee5e4..3187e4fe 100644 --- a/src/app/setup-wizard/pre-visit/company-kpi-select/company-kpi-select.component.html +++ b/src/app/setup-wizard/pre-visit/company-kpi-select/company-kpi-select.component.html @@ -18,7 +18,12 @@
Go Back diff --git a/src/app/setup-wizard/pre-visit/company-kpi-select/company-kpi-select.component.ts b/src/app/setup-wizard/pre-visit/company-kpi-select/company-kpi-select.component.ts index 120229b3..df5fbe7e 100644 --- a/src/app/setup-wizard/pre-visit/company-kpi-select/company-kpi-select.component.ts +++ b/src/app/setup-wizard/pre-visit/company-kpi-select/company-kpi-select.component.ts @@ -5,6 +5,7 @@ import { IdbOnSiteVisit } from 'src/app/models/onSiteVisit'; import { OnSiteVisitIdbService } from 'src/app/indexed-db/on-site-visit-idb.service'; import { KeyPerformanceIndicatorsIdbService } from 'src/app/indexed-db/key-performance-indicators-idb.service'; import { IdbKeyPerformanceIndicator } from 'src/app/models/keyPerformanceIndicator'; +import { Subscription } from 'rxjs'; @Component({ selector: 'app-company-kpi-select', @@ -15,12 +16,27 @@ export class CompanyKpiSelectComponent { faChartBar: IconDefinition = faChartBar; faChevronRight: IconDefinition = faChevronRight; faChevronLeft: IconDefinition = faChevronLeft; + + companyKpiSub: Subscription; + companyKpis: Array; + onSiteVisit: IdbOnSiteVisit; constructor(private router: Router, private onSiteVisitIdbService: OnSiteVisitIdbService, private keyPerformanceIndicatorIdbService: KeyPerformanceIndicatorsIdbService, ) { } ngOnInit() { + this.onSiteVisit = this.onSiteVisitIdbService.selectedVisit.getValue(); + this.companyKpiSub = this.keyPerformanceIndicatorIdbService.keyPerformanceIndicators.subscribe(kpis => { + let keyPerformanceIndicators: Array = this.keyPerformanceIndicatorIdbService.keyPerformanceIndicators.getValue(); + this.companyKpis = keyPerformanceIndicators.filter(kpi => { + return kpi.companyId == this.onSiteVisit.companyId + }); + }); + } + + ngOnDestroy(){ + this.companyKpiSub.unsubscribe(); } goBack() { @@ -29,15 +45,10 @@ export class CompanyKpiSelectComponent { } goToKpiDetails() { - let onSiteVisit: IdbOnSiteVisit = this.onSiteVisitIdbService.selectedVisit.getValue(); - let keyPerformanceIndicators: Array = this.keyPerformanceIndicatorIdbService.keyPerformanceIndicators.getValue(); - let companyKpis: Array = keyPerformanceIndicators.filter(kpi => { - return kpi.companyId == onSiteVisit.companyId - }); - if (companyKpis.length > 0) { - this.router.navigateByUrl('setup-wizard/pre-visit/' + onSiteVisit.guid + '/company-kpi-detail/' + companyKpis[0].guid); + if (this.companyKpis.length > 0) { + this.router.navigateByUrl('setup-wizard/pre-visit/' + this.onSiteVisit.guid + '/company-kpi-detail/' + this.companyKpis[0].guid); } else { - this.router.navigateByUrl('setup-wizard/pre-visit/' + onSiteVisit.guid + '/facility-setup'); + this.router.navigateByUrl('setup-wizard/pre-visit/' + this.onSiteVisit.guid + '/facility-setup'); } } }