src/lib/services/pagesRenderer/pages-renderer.service.ts
Service to render pages.
Properties |
|
Methods |
|
constructor(wmService: WebMapService)
|
||||||
Creates an instance of PagesRendererService.
Parameters :
|
loadPages | |||||||||
loadPages(container: ContainerComponent, component: MasterPageComponent)
|
|||||||||
Renders the direct child page of the MasterPage component.
Parameters :
Returns :
void
|
pagesCollector | ||||||
pagesCollector(model: any)
|
||||||
Collects all the pages that need to be rendered.
Parameters :
Returns :
void
|
Private setInitializers | |||||||||
setInitializers(container: ContainerComponent, component: MasterPageComponent)
|
|||||||||
Sets the initialization for the MasterPage component.
Parameters :
Returns :
void
|
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);
});
}
}