File

projects/wms-framework/src/lib/basecomponentmodel/Application.ts

Description

Class to represent the Application model

Metadata

selector wm-application
template
<div></div>

Index

Properties
Methods
Accessors

Constructor

constructor(elementRef: ElementRef, componentFactoryResolver: ComponentFactoryResolver)
Parameters :
Name Type Optional
elementRef ElementRef No
componentFactoryResolver ComponentFactoryResolver No

Methods

Public changeRootVisual
changeRootVisual(component: any)
Parameters :
Name Type Optional
component any No
Returns : any
getResourceByKey
getResourceByKey(key: string)
Parameters :
Name Type Optional
key string No
Returns : any
Protected initProperties
initProperties()

Initialize the child elements properties of the component in code behind.

Returns : void
Public Install
Install()
Returns : boolean
Static LoadComponent
LoadComponent(component: unknown, location: Uri)

Load component logic

Parameters :
Name Type Optional
component unknown No
location Uri No
Returns : void
Protected loadModels
loadModels()

Loads the model for the child elements defined in component.

Returns : void
Public ngAfterViewInit
ngAfterViewInit()
Returns : void
setResource
setResource(key: string, obj: any)
Parameters :
Name Type Optional
key string No
obj any No
Returns : any
Public startApp
startApp()

Starts the application and fire the startup event

Returns : void

Properties

Public angularHttpClient
Type : HttpClient
Static Current
Type : Application
Default value : new Application(null, null)
dialogService
Type : any
Default value : null
Exit
Default value : new SubscriptionEvent<(sender: any, e: any) => void>()
Public HasElevatedPermissions
Type : boolean
Default value : false
Private innerRootVisual
Type : any
Default value : null
InstallStateChanged
Default value : new SubscriptionEvent<(sender: any, e: any) => void>()
Public Readonly IsRunningOutOfBrowser
Type : boolean
Default value : false
Public resources
Type : ResourceDictionary
Default value : new ResourceDictionary()

The application resources

rootVisualHost
Type : any
Decorators :
@ViewChild(RootVisualDirective)
Startup
Default value : new SubscriptionEvent<(sender: any, e: StartupEventArgs) => void>()
UnhandledException
Default value : new SubscriptionEvent<(sender: any, e: any) => void>()

Accessors

RootVisual
getRootVisual()
setRootVisual(value: any)
Parameters :
Name Type Optional
value any No
Returns : void
InstallState
getInstallState()
Host
getHost()
import { HttpClient } from '@angular/common/http';
import {
  Component,
  ComponentFactoryResolver,
  ElementRef,
  ViewChild,
} from '@angular/core';
import { SimpleDictionary } from '../baseframework/SimpleDictionary';
import { Uri } from '../baseframework/Uri';
import { Debugger } from '../diagnostics/Debugger';
import { RootVisualDirective } from '../directives/rootvisual.directive';
import { TypeResolver } from '../helpers/TypeResolver';
import { StartupEventArgs } from '../models/events/StartupEventArgs';
import { SubscriptionEvent } from '../utils/SubscriptionEvent';
import { NativeHost } from './NativeHost';
import { ResourceDictionary } from './ResourceDictionary';
/**
 * Class to represent the Application model
 *
 * @export
 * @class Application
 * @wType System.Windows.Application
 */
@Component({
  selector: 'wm-application',
  template: `<div></div>`,
})
export class Application {
  /**
   * The application resources
   *
   * @type {ResourceDictionary}
   * @memberof Application
   * @wProperty Resources
   */
  public resources: ResourceDictionary = new ResourceDictionary();

  @ViewChild(RootVisualDirective)
  rootVisualHost: any;

  public HasElevatedPermissions: boolean = false;

  public readonly IsRunningOutOfBrowser: boolean = false;

  public static Current: Application = new Application(null, null);

  public angularHttpClient: HttpClient;

  public ngAfterViewInit() {
    this.startApp();
  }

  private innerRootVisual: any = null;
  public get RootVisual(): any {
    return this.innerRootVisual;
  }
  public set RootVisual(value: any) {
    this.changeRootVisual(value);
    this.innerRootVisual = value;
  }

  Startup = new SubscriptionEvent<(sender: any, e: StartupEventArgs) => void>();
  Exit = new SubscriptionEvent<(sender: any, e: any) => void>();
  UnhandledException = new SubscriptionEvent<(sender: any, e: any) => void>();
  InstallStateChanged = new SubscriptionEvent<(sender: any, e: any) => void>();

  dialogService: any = null;

  /**
   * Initialize the child elements properties of the component in code behind.
   *
   * @protected
   * @memberof Application
   */
  protected initProperties() {}

  /**
   * Loads the model for the child elements defined in component.
   *
   * @protected
   * @memberof Application
   */
  protected loadModels() {}

  /**
   *  Load component logic
   *
   * @static
   * @param {unknown} component
   * @param {Uri} location
   * @memberof Application
   */
  public static LoadComponent(component: unknown, location: Uri) {
    // Not required implementation
  }

  getResourceByKey(key: string): any {
    let res: any = this.resources?.Get(key) ?? this.resources[key];
    if (typeof res === 'undefined') res = null;
    return res;
  }
  setResource(key: string, obj: any): any {
    return (this.resources[key] = obj);
  }

  public Install(): boolean {
    return false;
  }
  public get InstallState(): any {
    return undefined;
  }

  public changeRootVisual(component: any): any {
    let model: unknown = null;
    if (component.AngularComponentId) {
      model = component;
      component = TypeResolver.getType(component.AngularComponentId);
    }
    if (component instanceof Function) {
      const componentFactory =
        this.componentFactoryResolver.resolveComponentFactory(component);
      const viewContainerRef = (<any>this).rootVisualHost.viewContainerRef;
      viewContainerRef.clear();
      const componentRef = viewContainerRef.createComponent(componentFactory);
      if (model) {
        componentRef.instance.model = model;
      }

      return componentRef;
    } else if (
      component &&
      component.constructor &&
      component.constructor.visualType
    ) {
      const componentRef = this.changeRootVisual(
        component.constructor.visualType
      );
      if (
        componentRef &&
        componentRef.instance &&
        componentRef.instance.performDynamicInit
      ) {
        componentRef.instance.performDynamicInit(component);
      }
    } else {
      alert('ERROR: Cannot set root visual');
    }
  }

  constructor(
    private elementRef: ElementRef,
    private componentFactoryResolver: ComponentFactoryResolver
  ) {}

  /**
   * Starts the application and fire the startup event
   *
   * @memberof Application
   */
  public startApp() {
    const initParamsDict = new SimpleDictionary<string, string>();
    if (this.elementRef.nativeElement.hasAttribute('initparams') === true) {
      var initParams = this.elementRef.nativeElement
        .getAttribute('initparams')
        .split(/\s*,\s*/)
        .map((chunk) => chunk.split('='));
      initParams.forEach((param) => {
        initParamsDict.addEntry(param[0], param[1]);
      });
    }
    const startUpEventArgs = new StartupEventArgs(initParamsDict);
    setTimeout(() => this.Startup.fire([this, startUpEventArgs]));
  }

  public get Host(): NativeHost {
    return new NativeHost();
  }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""