File

libs/ngx-pfe/services/pfe-page-mapping-service/page-mapping-service.service.ts

Description

The PfePageMappingService is responsible to map the configuration to a page component.

Index

Methods

Methods

Static addLazyLoadedPageToMap
addLazyLoadedPageToMap(pages: Map<string | PageDefinition>, pageType: string, lazyPageRoute: RoutePfeLazy)

Helper to add a lazy loaded page component to the mapping. Check the documentation, on how to create such a page.

Parameters :
Name Type Optional Description
pages Map<string | PageDefinition> No
pageType string No

The attribute used in the configuration.

lazyPageRoute RoutePfeLazy No

The lazy loaded module.

Returns : void
Static addPageToMap
addPageToMap(pages: Map<string | PageDefinition>, pageType: string, pageComponent: Type<>)

Helper to add a page component to the mapping.

Parameters :
Name Type Optional Description
pages Map<string | PageDefinition> No
pageType string No

The attribute used in the configuration.

pageComponent Type<> No

The page component to use.

Returns : void
getPageDefinition
getPageDefinition(config: PageConfig)

Determines the page type of a page configuration by its page configuration attribute.

Parameters :
Name Type Optional Description
config PageConfig No

The page config.

The determined page type.

import { inject, Injectable, Type } from '@angular/core';
import { PageConfig } from '../../models/ngx-pfe-page-config.model';
import { PfeModuleConfigurationService } from '../pfe-module-configuration/pfe-module-configuration.service';
import { PageDefinition, RoutePfeLazy } from './page-definition';

/**
 * The PfePageMappingService is responsible to map the configuration to a page component.
 *
 * @export
 */
@Injectable()
export class PfePageMappingService {
  private pfeModuleConfigurationService = inject(PfeModuleConfigurationService);

  /**
   * Helper to add a page component to the mapping.
   *
   * @param  pageType The attribute used in the configuration.
   * @param pageComponent The page component to use.
   */
  static addPageToMap(pages: Map<string, PageDefinition>, pageType: string, pageComponent: Type<unknown>) {
    pages.set(pageType, new PageDefinition(pageComponent));
  }

  /**
   * Helper to add a lazy loaded page component to the mapping.
   * Check the documentation, on how to create such a page.
   *
   * @param  pageType The attribute used in the configuration.
   * @param lazyPageRoute The lazy loaded module.
   */
  static addLazyLoadedPageToMap(pages: Map<string, PageDefinition>, pageType: string, lazyPageRoute: RoutePfeLazy) {
    const pageDef = new PageDefinition();
    pageDef.lazyPageRoute = lazyPageRoute;
    pages.set(pageType, pageDef);
  }

  /**
   * Determines the page type of a page configuration by its page configuration attribute.
   *
   * @param config The page config.
   * @returns The determined page type.
   */
  getPageDefinition(config: PageConfig): PageDefinition | undefined {
    for (const key in config) {
      if (Object.prototype.hasOwnProperty.call(config, key)) {
        const pageDef: PageDefinition | undefined = this.pfeModuleConfigurationService.pfeModuleConfig().pageMapping.get(key);
        if (pageDef) {
          return pageDef;
        }
      }
    }
  }
}

results matching ""

    No results matching ""