File

src/lib/services/pagesRenderer/pages-renderer.service.ts

Description

Service to render pages.

Index

Properties
Methods

Constructor

constructor(wmService: WebMapService)

Creates an instance of PagesRendererService.

Parameters :
Name Type Optional
wmService WebMapService No

Methods

loadPages
loadPages(container: ContainerComponent, component: MasterPageComponent)

Renders the direct child page of the MasterPage component.

Parameters :
Name Type Optional
container ContainerComponent No
component MasterPageComponent No
Returns : void
pagesCollector
pagesCollector(model: any)

Collects all the pages that need to be rendered.

Parameters :
Name Type Optional
model any No
Returns : void
Private setInitializers
setInitializers(container: ContainerComponent, component: MasterPageComponent)

Sets the initialization for the MasterPage component.

Parameters :
Name Type Optional
container ContainerComponent No
component MasterPageComponent No
Returns : void

Properties

Private idsCollection
Type : string[]
Default value : []

Collection of pages IDs.

import { Injectable } from '@angular/core';
import { ContainerComponent } from '@mobilize/base-components';
import { WebMapService } from '@mobilize/angularclient';
import { MasterPageComponent } from '../../components';

/**
 * Service to render pages.
 *
 * @export
 * @class PagesRendererService
 */
@Injectable({
  providedIn: 'root'
})
export class PagesRendererService {
  /**
   * Collection of pages IDs.
   *
   * @private
   * @type {string[]}
   * @memberof PagesRendererService
   */
  private idsCollection: string[] = [];

  /**
   * Creates an instance of PagesRendererService.
   *
   * @param {WebMapService} wmService
   * @memberof PagesRendererService
   */
  constructor(private wmService: WebMapService) {}

  /**
   * Collects all the pages that need to be rendered.
   *
   * @param {*} model
   * @memberof PagesRendererService
   */
  pagesCollector(model: any) {
    /* c8 ignore else */
    if (model?.UniqueID) {
      this.idsCollection.push(model.UniqueID);
      if (model.Parent) {
        const masterChildModel = this.wmService.core.getModel(model.Parent);
        this.pagesCollector(masterChildModel);
      }
    }
  }

  /**
   * Renders the direct child page of the MasterPage component.
   *
   * @param {ContainerComponent} container
   * @param {MasterPageComponent} component
   * @memberof PagesRendererService
   */
  loadPages(container: ContainerComponent, component: MasterPageComponent) {
    /* c8 ignore else */
    if (container && component) {
      /* c8 ignore else */
      if (!component.model.references?.Master) {
        this.idsCollection = [];
        this.pagesCollector(component.model);
      }
      const obj: { [key: string]: boolean } = {};
      const currentComponentId = this.idsCollection.indexOf(component.id);
      /* c8 ignore else */
      if (
        currentComponentId >= 0 &&
        currentComponentId + 1 <= this.idsCollection.length
      ) {
        const childIdToLoad = this.idsCollection[currentComponentId + 1];
        obj[childIdToLoad] = true;
        container.controls = obj;
        setTimeout(() => {
          this.setInitializers(container, component);
        }, 0);
      }
    }
  }

  /**
   * Sets the initialization for the MasterPage component.
   *
   * @private
   * @param {ContainerComponent} container
   * @param {MasterPageComponent} component
   * @memberof PagesRendererService
   */
  private setInitializers(
    container: ContainerComponent,
    component: MasterPageComponent
  ) {
    const openedComponents = container.openedComponents;
    const key = Object.keys(openedComponents)[0];
    const componentPage = openedComponents[key]?.instance;
    componentPage?.initializeEvent.subscribe((p: any) => {
      component.initializeContainers(p);
    });
  }
}

results matching ""

    No results matching ""