angular/projects/researchdatabox/form/src/app/form.component.ts
providers |
Location
{ provide: LocationStrategy, useClass: PathLocationStrategy }
|
selector | redbox-form |
styleUrls | ./form.component.scss |
templateUrl | ./form.component.html |
Properties |
|
Methods |
|
Inputs |
constructor(loggerService: LoggerService, configService: ConfigService, translationService: TranslationService, elementRef: ElementRef, formService: FormService)
|
||||||||||||||||||
Parameters :
|
editMode | |
Type : boolean
|
|
formName | |
Type : string
|
|
oid | |
Type : string
|
|
recordType | |
Type : string
|
|
Protected Async initComponent |
initComponent()
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:72
|
Returns :
Promise<void>
|
getInitSubject |
getInitSubject()
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:71
|
For those interested in the init from RXJS-land. Note that it returns a BehaviorSubject instance, and will have an initial value of false, so process the return value as needed.
Returns :
Subject<any>
|
isInitializing |
isInitializing()
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:95
|
Main flag to indicate the init status
Returns :
boolean
|
ngOnInit |
ngOnInit()
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:50
|
Returns :
void
|
Async waitForDeps |
waitForDeps()
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:78
|
Wait for dependencies to initialise
Returns :
Promise<any>
|
Async waitForInit |
waitForInit()
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:89
|
For those interested in the init from the Promise-land
Returns :
Promise<any>
|
appName |
Type : string
|
fields |
Type : any[]
|
Default value : []
|
modulePaths |
Type : string[]
|
Default value : []
|
Protected brandingAndPortalUrl |
Type : string
|
Default value : ''
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:42
|
Private filterFn |
Default value : function(initStat: boolean) { return initStat; }
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:40
|
Protected initDependencies |
Type : Initable[]
|
Default value : []
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:39
|
Protected initSubject |
Type : BehaviorSubject<any>
|
Default value : new BehaviorSubject(false)
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:38
|
Protected isReady |
Type : boolean
|
Default value : false
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:37
|
import { Component, Inject, Input, ElementRef, EventEmitter, Output, ChangeDetectorRef } from '@angular/core';
import { Location, LocationStrategy, PathLocationStrategy } from '@angular/common';
import { isEmpty as _isEmpty } from 'lodash-es';
import { ConfigService, LoggerService, TranslationService, BaseComponent } from '@researchdatabox/portal-ng-common';
import { FormService } from './form.service';
/**
* The ReDBox Form
*
* Goals:
- unopinionated layout
- dynamic component loading at runtime
- support concurrent modifications
* Author: <a href='https://github.com/shilob' target='_blank'>Shilo Banihit</a>
*
*/
/**
*/
@Component({
selector: 'redbox-form',
templateUrl: './form.component.html',
styleUrls: ['./form.component.scss'],
providers: [Location, {provide: LocationStrategy, useClass: PathLocationStrategy}]
})
export class FormComponent extends BaseComponent {
appName: string;
@Input() oid:string;
@Input() recordType: string;
@Input() editMode: boolean;
@Input() formName: string;
// TODO: remove any
fields: any[] = [];
modulePaths:string[] = [];
constructor(
@Inject(LoggerService) private loggerService: LoggerService,
@Inject(ConfigService) private configService: ConfigService,
@Inject(TranslationService) private translationService: TranslationService,
@Inject(ElementRef) elementRef: ElementRef,
@Inject(FormService) private formService: FormService
) {
super();
this.initDependencies = [this.translationService];
this.oid = elementRef.nativeElement.getAttribute('oid');
this.recordType = elementRef.nativeElement.getAttribute('recordType');
this.editMode = elementRef.nativeElement.getAttribute('editMode') === "true";
this.formName = elementRef.nativeElement.getAttribute('formName') || "";
this.appName = `Form::${this.recordType}::${this.formName} ${ this.oid ? ' - ' + this.oid : ''}`;
this.loggerService.debug(`'${this.appName}' waiting for deps to init...`);
}
protected async initComponent(): Promise<void> {
this.loggerService.debug(`Loading form with OID: ${this.oid}, on edit mode:${this.editMode}, Record Type: ${this.recordType}, formName: ${this.formName}`);
this.fields = await this.formService.get(this.oid, this.recordType, this.editMode, this.formName, this.modulePaths);
}
}
<ng-container *ngFor="let field of fields">
<redbox-form-field [compInfo]="field.componentInfo" [data]="field.data"></redbox-form-field>
</ng-container>
./form.component.scss