UNPKG

@memberjunction/ng-shared

Version:

MemberJunction: MJ Explorer Angular Shared Package - utility functions and other reusable elements used across other MJ Angular packages within the MJ Explorer App - do not use outside of MJ Explorer.

114 lines 3.37 kB
import { Injectable } from '@angular/core'; import * as i0 from "@angular/core"; import * as i1 from "@angular/platform-browser"; /** * Service for managing browser tab titles. * Provides a hierarchical naming scheme: "App Name - Resource/Page Name" * Useful for bookmarks and browser history. */ export class TitleService { titleService; baseTitle = 'MemberJunction'; currentAppName = null; currentResourceName = null; constructor(titleService) { this.titleService = titleService; } /** * Set the base application title (e.g., "MemberJunction" or "Skip") */ setBaseTitle(title) { this.baseTitle = title; this.updateTitle(); } /** * Get the current base title */ getBaseTitle() { return this.baseTitle; } /** * Set the current app name (e.g., "Sales", "Marketing") * Pass null to clear the app context */ setAppName(appName) { this.currentAppName = appName; this.updateTitle(); } /** * Get the current app name */ getAppName() { return this.currentAppName; } /** * Set the current resource/page name (e.g., "Accounts", "Contact: John Doe") * Pass null to show only the app name */ setResourceName(resourceName) { this.currentResourceName = resourceName; this.updateTitle(); } /** * Get the current resource name */ getResourceName() { return this.currentResourceName; } /** * Set both app and resource in one call */ setContext(appName, resourceName) { this.currentAppName = appName; this.currentResourceName = resourceName; this.updateTitle(); } /** * Reset to just the base title */ reset() { this.currentAppName = null; this.currentResourceName = null; this.updateTitle(); } /** * Get the full current title */ getFullTitle() { return this.buildTitle(); } /** * Build the title string based on current context * Format: "BaseTitle - AppName - ResourceName" (with optional parts) */ buildTitle() { const parts = []; // Resource name first for better visibility in browser tabs (most specific first) if (this.currentResourceName) { parts.push(this.currentResourceName); } // App name next if (this.currentAppName) { parts.push(this.currentAppName); } // Base title last (least specific) parts.push(this.baseTitle); return parts.join(' - '); } /** * Update the browser tab title */ updateTitle() { const title = this.buildTitle(); this.titleService.setTitle(title); } static ɵfac = function TitleService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || TitleService)(i0.ɵɵinject(i1.Title)); }; static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: TitleService, factory: TitleService.ɵfac, providedIn: 'root' }); } (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TitleService, [{ type: Injectable, args: [{ providedIn: 'root' }] }], () => [{ type: i1.Title }], null); })(); //# sourceMappingURL=title.service.js.map