nm-form
src/app/shared/widgets/form.component.ts
providers |
{
: , : , : [, ],
}
|
selector | nm-form |
template |
|
Widget inputs |
Widget outputs |
Properties |
Methods |
Inputs |
constructor(authHttp: HttpClient, _widgetRegistry: WidgetRegistry, _changeDetectorRef: ChangeDetectorRef)
|
||||||||||||
Defined in src/app/shared/widgets/form.component.ts:64
|
||||||||||||
Parameters :
|
action
|
|
Defined in src/app/shared/widgets/form.component.ts:47
|
form
|
|
Defined in src/app/shared/widgets/form.component.ts:57
|
input-parameters
|
|
Defined in src/app/shared/widgets/form.component.ts:52
|
rootconfig
|
|
Defined in src/app/shared/widgets/form.component.ts:62
|
ngOnChanges | ||||||
ngOnChanges(changes: any)
|
||||||
Defined in src/app/shared/widgets/form.component.ts:72
|
||||||
Parameters :
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Defined in src/app/shared/widgets/form.component.ts:107
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Defined in src/app/shared/widgets/form.component.ts:103
|
Returns :
void
|
_action |
_action:
|
Type : ActionForm
|
Defined in src/app/shared/widgets/form.component.ts:40
|
_form |
_form:
|
Type : FormGroup
|
Defined in src/app/shared/widgets/form.component.ts:43
|
_inputParameters |
_inputParameters:
|
Type : InputParameterDefinition
|
Defined in src/app/shared/widgets/form.component.ts:42
|
_rootconfig |
_rootconfig:
|
Type : WidgetConfig
|
Defined in src/app/shared/widgets/form.component.ts:44
|
config |
config:
|
Default value : new Subject<WidgetConfig>()
|
Defined in src/app/shared/widgets/form.component.ts:39
|
action | ||||
setaction(action: )
|
||||
Defined in src/app/shared/widgets/form.component.ts:47
|
||||
Parameters :
Returns :
void
|
inputParameters | ||||
setinputParameters(inputParameters: )
|
||||
Defined in src/app/shared/widgets/form.component.ts:52
|
||||
Parameters :
Returns :
void
|
form | ||||
setform(form: )
|
||||
Defined in src/app/shared/widgets/form.component.ts:57
|
||||
Parameters :
Returns :
void
|
rootconfig | ||||
setrootconfig(rootconfig: )
|
||||
Defined in src/app/shared/widgets/form.component.ts:62
|
||||
Parameters :
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();
}
}