import { Injectable } from '@angular/core'; import { NavigationEnd, Router } from '@angular/router'; import { HelpContentService } from '@features/platform-admin/help-content/help-content.service'; import { ReleaseNoteService } from '@features/platform-admin/release-notes/services/release-notes.service'; import { SupportService } from '@features/support/support.service'; import { SidebarLink, SupportLink } from '@yourcause/common'; import { I18nService } from '@yourcause/common/i18n'; import { AttachYCState, BaseYCService } from '@yourcause/common/state'; import { filter } from 'rxjs'; import { AppShellState } from '../states/app-shell.state'; import { LocationService } from './location.service'; import { PortalDeterminationService } from './portal-determination.service'; export const defaultApplicantLink = 'https://webfiles.blackbaud.com/files/support/helpfiles/grantsconnect/content/gc-applicants.html'; export const defaultGMLink = 'https://webfiles.blackbaud.com/files/support/helpfiles/grantsconnect/content/home.html'; @Injectable({ providedIn: 'root' }) @AttachYCState(AppShellState) export class AppShellService extends BaseYCService { constructor ( private router: Router, private i18n: I18nService, private releaseNoteService: ReleaseNoteService, private supportService: SupportService, private helpContentService: HelpContentService, private locationService: LocationService, private portal: PortalDeterminationService ) { super(); } get sidebarClosed () { return this.get('sidebarClosed'); } get sidebarLinks () { return this.get('sidebarLinks'); } toggleSidebar () { this.set('sidebarClosed', !this.sidebarClosed); } setSidebarLinks (links: SidebarLink[]) { this.set('sidebarLinks', links); } registerSupportLinkListener () { this.router.events.pipe( filter(e => e instanceof NavigationEnd)) .subscribe(() => { this.setSupportLinks(); }); } setSupportLinks () { const currentGenericRoute = this.locationService.getGenericRoute(); const applicableHelpContents = this.helpContentService .contents?.filter(content => { const contentGenericRoute = this.locationService.getGenericRoute(content.grantsConnectLink); return currentGenericRoute.startsWith(contentGenericRoute); }); let helpContentLink = this.portal.isApply ? defaultApplicantLink : defaultGMLink; if (applicableHelpContents.length) { const applicableHelpContent = applicableHelpContents .reduce((val, next) => { // if val has a longer link, we assume it is more accurate and use that return val.grantsConnectLink.length > next.grantsConnectLink.length ? val : next; }); helpContentLink = applicableHelpContent.helpContentLink; if (!helpContentLink.startsWith('https:')) { helpContentLink = `https://${helpContentLink}`; } } const links: SupportLink[][] = [[{ label: this.i18n.translate('common:btnOpenHelp', {}, 'Open help'), external: true, link: helpContentLink }, { label: this.i18n.translate('common:btnWhatsNew', {}, 'What\'s new'), external: true, link: this.releaseNoteService.releaseNotes?.[0]?.releaseNotesUrl }], [{ label: this.i18n.translate('common:btnContactSupport', {}, 'Contact support'), external: false, onClick: () => { this.supportService.openSupportEmailModal(); } }, { label: this.i18n.translate('common:liveChat', {}, 'Live chat'), external: false, onClick: () => { this.supportService.openLiveChat(); } }]]; this.set('supportLinks', links); } setActiveHelpLink (link: string) { this.set('activeHelpLink', link); } setShowHeaderButtons (show: boolean) { this.set('showHeaderButtons', show); } }