File

src/services/tabService/factoryNodes/factory-nodes.ts

Index

Properties
Methods

Constructor

constructor()

Methods

create
create(componentInstance: any)
Parameters :
Name Type Optional
componentInstance any No
Returns : any
getType
getType(componentInstance: any)

Returns an specific type of Node

Parameters :
Name Type Optional Description
componentInstance any No

reference of component instance

Returns : string
register
register(name: TabNodeTypes, nodeType: ITabNode)

Regist nodetypes in to the dictionary

Parameters :
Name Type Optional Description
name TabNodeTypes No

name type node

nodeType ITabNode No

tabNode component

Returns : void

Properties

Private nodesTypes
Type : IDictionary
Default value : new Dictionary()
import { Injectable } from '@angular/core';
import { IDictionary, Dictionary } from '@mobilize/webmap-core';
import { TabNodeTypes } from '../nodes/tabNodeTypes';
import { ITabNode } from '../tabContracts/iTabNode';
import { IFactoryNode } from '../tabContracts/iFactoryNode';
import { ComponentTypeName } from '../../../components/base/base-component/componentTypeName';

@Injectable({
  providedIn: 'root'
})
export class FactoryNodes implements IFactoryNode {
  constructor() {}
  private nodesTypes: IDictionary = new Dictionary();

  create(componentInstance: any): any {
    // We need to define a variable in order to define node type
    const nodeInstance = this.nodesTypes.value(this.getType(componentInstance));
    if (!nodeInstance) {
      return null;
    }
    return new nodeInstance(componentInstance);
  }

  /**
   * Regist nodetypes in to the dictionary
   * @param name name type node
   * @param nodeType  tabNode component
   */
  register(name: TabNodeTypes, nodeType: ITabNode): void {
    this.nodesTypes.add(name as string, nodeType);
  }

  /**
   * Returns an specific type of Node
   * @param componentInstance reference of component instance
   */
  getType(componentInstance: any): string {
    if (
      componentInstance.componentName === ComponentTypeName.DataManagerControl
    ) {
      return TabNodeTypes.dmNode;
    }
    // if component instance is not a defined type and is not a column return default NodeType
    if (componentInstance.tabPageOrderServiceInstance) {
      return TabNodeTypes.tabPageNode;
    }
    return !componentInstance.dataManagerEmitter ? TabNodeTypes.tabNode : null;
  }
}

results matching ""

    No results matching ""