import { Component, OnDestroy, OnInit } from '@angular/core'; import { NavigationEnd, Router } from '@angular/router'; import { AppInsightsSessionService } from '@core/services/app-insights-session.service'; import { AppShellService } from '@core/services/app-shell.service'; import { AuthService } from '@core/services/auth.service'; import { BannerService } from '@core/services/banner.service'; import { CardPageTypes, CardsService } from '@core/services/cards.service'; import { SessionKeepAliveService } from '@core/services/session-keep-alive.service'; import { SpinnerService } from '@core/services/spinner.service'; import { TokenTimeoutService } from '@core/services/token/token-timeout.service'; import { TokenService } from '@core/services/token/token.service'; import { ClientBrandingForUi } from '@core/typings/branding.typing'; import { environment } from '@environment'; import { ClientSettingsService } from '@features/client-settings/client-settings.service'; import { DashboardsService } from '@features/dashboards/dashboards.service'; import { ImpersonationService } from '@features/impersonation/impersonation.service'; import { PageHelpModalService } from '@features/page-help-modals/page-help-modals.service'; import { ReleaseNoteService } from '@features/platform-admin/release-notes/services/release-notes.service'; import { UserService } from '@features/users/user.service'; import { filter, map, Subscription, tap } from 'rxjs'; import { PolicyService } from '../../services/policy.service'; import { FooterState } from '../../states/footer.state'; import { User } from '../../typings/client-user.typing'; @Component({ selector: 'gc-wrapper-management', templateUrl: './gc-wrapper-management.component.html', styleUrls: ['./gc-wrapper-management.component.scss'] }) export class GcWrapperManagementComponent implements OnInit, OnDestroy { sidebarLinks$ = this.appShellService.changesTo$('sidebarLinks'); sidebarClosed$ = this.appShellService.changesTo$('sidebarClosed'); footerState$ = this.footerState.changesTo$('footerState'); footerActionLabel$ = this.footerState.changesTo$('footerActionLabel'); footerCancelLabel$ = this.footerState.changesTo$('footerCancelLabel'); footerSecondaryLabel$ = this.footerState.changesTo$('footerSecondaryLabel'); footerSecondaryDisabled$ = this.footerState.changesTo$('footerSecondaryDisabled'); footerTertiaryLabel$ = this.footerState.changesTo$('footerTertiaryLabel'); footerActionDisabled$ = this.footerState.changesTo$('footerActionDisabled'); footerAction$ = this.footerState.changesTo$('footerAction'); footerCancelAction$ = this.footerState.changesTo$('footerCancelAction'); footerSecondaryAction$ = this.footerState.changesTo$('footerSecondaryAction'); footerTertiaryAction$ = this.footerState.changesTo$('footerTertiaryAction'); footerInfoText$ = this.footerState.changesTo$('footerInfoText'); footerInfoIcon$ = this.footerState.changesTo$('footerInfoIcon'); footerInfoTooltip$ = this.footerState.changesTo$('footerInfoTooltip'); banners$ = this.bannerService.changesTo$('banners'); supportLinks$ = this.appShellService.changesTo$('supportLinks'); FOOTER_STATES = this.footerState.FOOTER_STATES; copyrightText = `©2020 YourCause - GrantsConnect (${environment.version}) (${this.appInsightsSessionService.sessionId})`; versionInvalid$ = this.appShellService.changesTo$('latestVersion').pipe( map((version) => { return version && (version !== environment.version); })); copyrightIcon$ = this.versionInvalid$.pipe( map((invalid) => invalid ? 'exclamation-triangle text-warning mr-2' : '')); copyrightIconTooltip$ = this.versionInvalid$.pipe( map((invalid) => invalid ? 'Refresh to get latest version' : '')); showHeaderButtons$ = this.appShellService .changesTo$('showHeaderButtons'); termsOfServiceLink = this.authService.termsOfServiceLink; privacyPolicyLink = this.authService.privacyPolicyLink; navToggled: boolean; loading = false; showTimeoutWarning = false; timeRemaining$ = this.timeoutService.timeRemaining$.pipe( tap(time => { if (time <= 0) { this.onSignOutClick(); } }), filter(time => time <= this.timeoutService.timeoutStart)); showTimeout$ = this.timeoutService.timeoutStart$; version = environment.version; hasNominations = false; user: User; branding: ClientBrandingForUi; logoLocation: string; initials: string; sub = new Subscription(); constructor ( private authService: AuthService, private sessionKeepAliveService: SessionKeepAliveService, private tokenService: TokenService, private spinnerService: SpinnerService, private appShellService: AppShellService, private router: Router, private policyService: PolicyService, private clientSettingsService: ClientSettingsService, private userService: UserService, private footerState: FooterState, private timeoutService: TokenTimeoutService, private dashboardService: DashboardsService, private impersonationService: ImpersonationService, private bannerService: BannerService, private appInsightsSessionService: AppInsightsSessionService, private cardsService: CardsService, private releaseNoteService: ReleaseNoteService, private pageHelpModalService: PageHelpModalService ) { this.sub.add(this.router.events.subscribe((event) => { if (event instanceof NavigationEnd) { this.pageHelpModalService.checkIfWeShouldOpenPageHelpModal(); } })); } get accountName () { return this.userService.get('userName'); } get accountRole () { return this.userService.get('userJobTitle'); } async ngOnInit () { this.sub.add( this.clientSettingsService.changesTo$('clientBranding').subscribe(() => { this.branding = this.clientSettingsService.get('clientBranding'); this.logoLocation = this.branding ? this.branding.logoUrl : ''; }) ); this.spinnerService.startSpinner(); this.sub.add( this.userService.changesTo$('user').subscribe(async (user: User) => { if (user && this.tokenService.hasToken()) { this.initials = user.firstName[0] + user.lastName[0]; if (location.pathname.includes('auth')) { this.router.navigateByUrl(this.dashboardService.homeRoute); } this.hasNominations = user.clientHasNominations; this.user = user; this.timeoutService.start(); this.sessionKeepAliveService.startWatching(); if (this.tokenService.hasImpersonationToken()) { this.impersonationService.startPollingEndedImpersonationSession(); } } else { this.initials = ''; this.timeoutService.stop(); this.sessionKeepAliveService.stopWatching(); setTimeout(() => { this.impersonationService.stopPollingEndedImpersonationSession(); }, 700); } this.setBannerInfo(); this.setSidebarLinks(); this.spinnerService.stopSpinner(); if (!!this.user) { await this.releaseNoteService.setReleaseNoteForManager(); } this.appShellService.setSupportLinks(); this.appShellService.registerSupportLinkListener(); }) ); this.sub.add(this.dashboardService.changesTo$('homeRoute').subscribe(() => { if (this.appShellService.sidebarLinks) { this.setSidebarLinks(); } })); } setSidebarLinks () { const showInsights = this.cardsService.canSeePage(CardPageTypes.INSIGHTS); const showApplicationManager = this.policyService.grantApplication.canAccessApplicationManager(); const canManageProcessing = this.policyService.processing.canManageProcessing(); const canViewDisbursementReport = this.policyService.processing.canViewDisbursementReport(); const canSeeProgramSetup = this.cardsService.canSeePage(CardPageTypes.PROGRAM); const canSeeSettings = this.cardsService.canSeePage(CardPageTypes.SETTINGS); const canSeeDataHub = this.policyService.dataExport.canPullApplicationDetails() || this.policyService.dataExport.canPullAwardExport() || this.policyService.dataExport.canPullBudgetExport() || this.policyService.dataExport.canPullFormExport() || this.policyService.dataExport.canPullPaymentExport() || this.policyService.dataExport.canPullProgramSummaryExport() || this.policyService.dataExport.canManageAdHoc() || (this.userService.get('user') && this.userService.get('user').hasReports); this.appShellService.setSidebarLinks([{ label: 'Home', labelClass: '', i18nKey: 'NAV:Home', href: this.dashboardService.homeRoute, icon: 'home', sequence: '1.0', group: 1 }, showApplicationManager ? { label: 'Applications', i18nKey: 'common:hdrApplications', href: '/management/manage-applications/applications', icon: 'clipboard-list', sequence: '1.2', group: 2 } : null, showApplicationManager && (this.userService.get('user') as User).clientHasNominations && (this.userService.get('user') as User).isInNominationWorkFlow ? { label: 'Nominations', i18nKey: 'common:hdrNominations', href: '/management/manage-nominations/nominations', icon: 'medal', sequence: '', group: 2 } : null, showInsights ? { label: 'Insights', i18nKey: 'GLOBAL:textInsights', href: '/management/insights', icon: 'chart-line', sequence: '1.3', group: 2 } : null, canSeeDataHub ? { label: 'Reporting', i18nKey: 'common:hdrReporting', href: '/management/reporting', icon: 'file-chart-line', sequence: '1.5', group: 3 } : null, canManageProcessing || canViewDisbursementReport ? { label: 'Payment Processing', i18nKey: 'common:hdrPaymentProcessing', href: canManageProcessing ? '/management/payment-processing/available' : '/management/payment-processing/disbursement-report', icon: 'money-bill', sequence: '', group: 3 } : null, canSeeProgramSetup ? { label: 'Program Setup', i18nKey: 'GLOBAL:textProgramSetup', href: '/management/program-setup', icon: 'toolbox', sequence: '', group: 4 } : null, canSeeSettings ? { label: 'Settings', i18nKey: 'GLOBAL:textSettings', href: '/management/configure', icon: 'cog', sequence: '1.4', group: 4 } : null].filter(link => !!link)); } setBannerInfo () { this.bannerService.setManagerPortalBanners(this.user?.passwordExpirationDate); } onSignOutClick () { this.showTimeoutWarning = false; this.tokenService.logout(); } keepMeSignedIn () { this.tokenService.getLatestToken(); } handleSidebarToggle () { this.appShellService.toggleSidebar(); } ngOnDestroy () { this.sub.unsubscribe(); } }