import { Component, OnDestroy } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { Tab } from '@yourcause/common'; import { Subscription } from 'rxjs'; @Component({ selector: 'gc-workflow-automation-view-wrapper', templateUrl: './workflow-automation-view-wrapper.component.html', styleUrls: ['./workflow-automation-view-wrapper.component.scss'] }) export class WorkflowAutomationViewWrapperComponent implements OnDestroy { routerLink: string[]; isAdvancement: boolean; isHistory: boolean; sub = new Subscription(); tabs: Tab[] = [{ label: 'Initial Assignments', labelKey: 'CONFIG:linkInitialAssignments', link: './view-initial-rules' }, { label: 'Routing', labelKey: 'common:hdrRouting', link: './view-advancement-rules' }, { label: 'Assignment History', labelKey: 'CONFIG:hdrAssignmentHistory', link: './assignment-history' }, { label: 'Routing History', labelKey: 'common:hdrRoutingHistory', link: './routing-history' }]; constructor ( private router: Router, private activatedRoute: ActivatedRoute ) { this.sub.add(this.router.events.subscribe(() => { this.setIsAdvancement(); this.setIsHistory(); })); } setIsHistory () { this.isHistory = this.activatedRoute.firstChild.snapshot.data.isAssignmentHistory || this.activatedRoute.firstChild.snapshot.data.isRoutingHistory; } setIsAdvancement () { const isAdvancement = this.activatedRoute.firstChild.snapshot.data.isAdvancement; this.setRouterLink(isAdvancement); this.isAdvancement = isAdvancement; } setRouterLink (isAdvancement: boolean) { this.routerLink = isAdvancement ? ['./advancement/new'] : ['./initial/new']; } ngOnDestroy () { this.sub.unsubscribe(); } }