@WidgetComponent

nm-form

File

src/app/shared/widgets/form.component.ts

Implements

OnChanges OnDestroy

Metadata

providers { : , : , : [, ], }
selector nm-form
template
<div [formGroup]="_form">
  <nm-container
    [configuration]="config | async"
    [parent]="null"
    id="root"
  ></nm-container>
</div>

Index

Widget inputs
Widget outputs
Properties
Methods
Inputs

Constructor

constructor(authHttp: HttpClient, _widgetRegistry: WidgetRegistry, _changeDetectorRef: ChangeDetectorRef)
Parameters :
Name Type Optional
authHttp HttpClient no
_widgetRegistry WidgetRegistry no
_changeDetectorRef ChangeDetectorRef no

Inputs

action
form
input-parameters
rootconfig

Methods

ngOnChanges
ngOnChanges(changes: any)
Parameters :
Name Type Optional
changes any no
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

_action
_action: ActionForm
Type : ActionForm
_form
_form: FormGroup
Type : FormGroup
_inputParameters
_inputParameters: InputParameterDefinition
Type : InputParameterDefinition
_rootconfig
_rootconfig: WidgetConfig
Type : WidgetConfig
config
config:
Default value : new Subject<WidgetConfig>()

Accessors

action
setaction(action: )
Parameters :
Name Optional
action no
Returns : void
inputParameters
setinputParameters(inputParameters: )
Parameters :
Name Optional
inputParameters no
Returns : void
form
setform(form: )
Parameters :
Name Optional
form no
Returns : void
rootconfig
setrootconfig(rootconfig: )
Parameters :
Name Optional
rootconfig no
Returns : void
import { map } from "rxjs/operators";
import {
  Component,
  OnChanges,
  OnDestroy,
  Input,
  ChangeDetectorRef,
} from "@angular/core";
import { FormGroup } from "@angular/forms";
import { HttpClient } from "@angular/common/http";
import { Subject } from "rxjs";
import { WidgetRegistry, widgetRegistryFactory } from "./widget.registry";
import { WidgetConfig } from "./widget.configuration";
import { InputParameterDefinition } from "./widget.descriptor";
import { HalService } from "../components/hal/hal.service";
import { CurrentLocaleService } from "../components/i18n/currentLocale.service";
import { ActionForm } from "../components/hal/actionForm";

@Component({
  selector: "nm-form",
  template: `
    <div [formGroup]="_form">
      <nm-container
        [configuration]="config | async"
        [parent]="null"
        id="root"
      ></nm-container>
    </div>
  `,
  providers: [
    {
      provide: WidgetRegistry,
      useFactory: widgetRegistryFactory,
      deps: [HalService, CurrentLocaleService],
    },
  ],
})
export class NmFormComponent implements OnChanges, OnDestroy {
  config = new Subject<WidgetConfig>();
  _action: ActionForm;

  _inputParameters: InputParameterDefinition;
  _form: FormGroup;
  _rootconfig: WidgetConfig;

  @Input("action")
  set action(action: ActionForm) {
    this._action = action;
  }

  @Input("input-parameters")
  set inputParameters(inputParameters: InputParameterDefinition) {
    this._inputParameters = inputParameters;
  }

  @Input("form")
  set form(form: FormGroup) {
    this._form = form;
  }

  @Input("rootconfig")
  set rootconfig(rootconfig) {
    this._rootconfig = rootconfig;
  }

  constructor(
    private authHttp: HttpClient,
    private _widgetRegistry: WidgetRegistry,
    private _changeDetectorRef: ChangeDetectorRef
  ) {}

  ngOnChanges(changes: any): void {
    if (!this._action) {
      return;
    }

    if (this._rootconfig != undefined) {
      this._widgetRegistry.registerFormGroup(this._form, this._action);
      window.setTimeout(() => {
        this._widgetRegistry.parseConfiguration(this._rootconfig);
        this.config.next(this._rootconfig);
        this._changeDetectorRef.detectChanges();
      }, 1);
    } else if (this._action.formHref) {
      this._widgetRegistry.registerFormGroup(this._form, this._action);
      this.authHttp
        .get(this._action.formHref)
        .pipe(
          map((res) => <WidgetConfig>res),
          map((page) => page["_embedded"]["root"])
        )
        .subscribe(
          (config) => {
            this._widgetRegistry.parseConfiguration(config);
            this.config.next(config);
            this._changeDetectorRef.detectChanges();
          },
          (err) => this.config.error(err)
        );
    }
  }

  ngOnInit() {
    this._widgetRegistry.registerInputParameters(this._inputParameters);
  }

  ngOnDestroy() {
    this._widgetRegistry.dispose();
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""