|
|
@ -1,10 +1,10 @@ |
|
|
import { ABP, AbpValidators, ConfigStateService, TrackByService } from '@abp/ng.core'; |
|
|
import {ABP, AbpValidators, ConfigStateService, TrackByService} from '@abp/ng.core'; |
|
|
import { |
|
|
import { |
|
|
AfterViewInit, |
|
|
AfterViewInit, |
|
|
ChangeDetectionStrategy, |
|
|
ChangeDetectionStrategy, |
|
|
ChangeDetectorRef, |
|
|
ChangeDetectorRef, |
|
|
Component, |
|
|
Component, |
|
|
ElementRef, |
|
|
ElementRef, Injector, |
|
|
Input, |
|
|
Input, |
|
|
OnChanges, |
|
|
OnChanges, |
|
|
Optional, |
|
|
Optional, |
|
|
@ -19,17 +19,18 @@ import { |
|
|
ValidatorFn, |
|
|
ValidatorFn, |
|
|
Validators, |
|
|
Validators, |
|
|
} from '@angular/forms'; |
|
|
} from '@angular/forms'; |
|
|
import { NgbDateAdapter, NgbTimeAdapter } from '@ng-bootstrap/ng-bootstrap'; |
|
|
import {NgbDateAdapter, NgbTimeAdapter} from '@ng-bootstrap/ng-bootstrap'; |
|
|
import { Observable, of } from 'rxjs'; |
|
|
import {Observable, of} from 'rxjs'; |
|
|
import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators'; |
|
|
import {debounceTime, distinctUntilChanged, switchMap} from 'rxjs/operators'; |
|
|
import { DateAdapter } from '../../adapters/date.adapter'; |
|
|
import {DateAdapter} from '../../adapters/date.adapter'; |
|
|
import { TimeAdapter } from '../../adapters/time.adapter'; |
|
|
import {TimeAdapter} from '../../adapters/time.adapter'; |
|
|
import { EXTRA_PROPERTIES_KEY } from '../../constants/extra-properties'; |
|
|
import {EXTRA_PROPERTIES_KEY} from '../../constants/extra-properties'; |
|
|
import { ePropType } from '../../enums/props.enum'; |
|
|
import {ePropType} from '../../enums/props.enum'; |
|
|
import { FormProp } from '../../models/form-props'; |
|
|
import {FormProp} from '../../models/form-props'; |
|
|
import { PropData } from '../../models/props'; |
|
|
import {PropData} from '../../models/props'; |
|
|
import { selfFactory } from '../../utils/factory.util'; |
|
|
import {selfFactory} from '../../utils/factory.util'; |
|
|
import { addTypeaheadTextSuffix } from '../../utils/typeahead.util'; |
|
|
import {addTypeaheadTextSuffix} from '../../utils/typeahead.util'; |
|
|
|
|
|
import {FORM_PROP_DATA_STREAM} from "../../tokens/extensions.token"; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: 'abp-extensible-form-prop', |
|
|
selector: 'abp-extensible-form-prop', |
|
|
@ -41,8 +42,8 @@ import { addTypeaheadTextSuffix } from '../../utils/typeahead.util'; |
|
|
useFactory: selfFactory, |
|
|
useFactory: selfFactory, |
|
|
deps: [[new Optional(), new SkipSelf(), ControlContainer]], |
|
|
deps: [[new Optional(), new SkipSelf(), ControlContainer]], |
|
|
}, |
|
|
}, |
|
|
{ provide: NgbDateAdapter, useClass: DateAdapter }, |
|
|
{provide: NgbDateAdapter, useClass: DateAdapter}, |
|
|
{ provide: NgbTimeAdapter, useClass: TimeAdapter }, |
|
|
{provide: NgbTimeAdapter, useClass: TimeAdapter}, |
|
|
], |
|
|
], |
|
|
}) |
|
|
}) |
|
|
export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit { |
|
|
export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit { |
|
|
@ -54,6 +55,8 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit { |
|
|
|
|
|
|
|
|
@ViewChild('field') private fieldRef!: ElementRef<HTMLElement>; |
|
|
@ViewChild('field') private fieldRef!: ElementRef<HTMLElement>; |
|
|
|
|
|
|
|
|
|
|
|
public injectorForCustomComponent: Injector |
|
|
|
|
|
|
|
|
asterisk = ''; |
|
|
asterisk = ''; |
|
|
|
|
|
|
|
|
options$: Observable<ABP.Option<any>[]> = of([]); |
|
|
options$: Observable<ABP.Option<any>[]> = of([]); |
|
|
@ -62,15 +65,16 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit { |
|
|
|
|
|
|
|
|
readonly!: boolean; |
|
|
readonly!: boolean; |
|
|
|
|
|
|
|
|
disabledFn = (data:PropData) => false; |
|
|
typeaheadModel: any; |
|
|
|
|
|
|
|
|
get disabled() { |
|
|
|
|
|
return this.disabledFn(this.data) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private readonly form: FormGroup; |
|
|
private readonly form: FormGroup; |
|
|
|
|
|
|
|
|
typeaheadModel: any; |
|
|
disabledFn = (data: PropData) => false; |
|
|
|
|
|
|
|
|
|
|
|
get disabled() { |
|
|
|
|
|
return this.disabledFn(this.data) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTypeaheadValue(selectedOption: ABP.Option<string>) { |
|
|
setTypeaheadValue(selectedOption: ABP.Option<string>) { |
|
|
this.typeaheadModel = selectedOption || { key: null, value: null }; |
|
|
this.typeaheadModel = selectedOption || { key: null, value: null }; |
|
|
@ -108,12 +112,13 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit { |
|
|
public readonly track: TrackByService, |
|
|
public readonly track: TrackByService, |
|
|
protected configState: ConfigStateService, |
|
|
protected configState: ConfigStateService, |
|
|
groupDirective: FormGroupDirective, |
|
|
groupDirective: FormGroupDirective, |
|
|
|
|
|
private injector: Injector |
|
|
) { |
|
|
) { |
|
|
this.form = groupDirective.form; |
|
|
this.form = groupDirective.form; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private getTypeaheadControls() { |
|
|
private getTypeaheadControls() { |
|
|
const { name } = this.prop; |
|
|
const {name} = this.prop; |
|
|
const extraPropName = `${EXTRA_PROPERTIES_KEY}.${name}`; |
|
|
const extraPropName = `${EXTRA_PROPERTIES_KEY}.${name}`; |
|
|
const keyControl = |
|
|
const keyControl = |
|
|
this.form.get(addTypeaheadTextSuffix(extraPropName)) || |
|
|
this.form.get(addTypeaheadTextSuffix(extraPropName)) || |
|
|
@ -133,6 +138,9 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getComponent(prop: FormProp): string { |
|
|
getComponent(prop: FormProp): string { |
|
|
|
|
|
if (prop.template) { |
|
|
|
|
|
return 'template' |
|
|
|
|
|
} |
|
|
switch (prop.type) { |
|
|
switch (prop.type) { |
|
|
case ePropType.Boolean: |
|
|
case ePropType.Boolean: |
|
|
return 'checkbox'; |
|
|
return 'checkbox'; |
|
|
@ -173,13 +181,24 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngOnChanges({ prop }: SimpleChanges) { |
|
|
ngOnChanges({prop}: SimpleChanges) { |
|
|
const currentProp = prop?.currentValue; |
|
|
const currentProp = prop?.currentValue as FormProp; |
|
|
const { options, readonly, disabled, validators } = currentProp || {}; |
|
|
const {options, readonly, disabled, validators, template} = currentProp || {}; |
|
|
|
|
|
if (template) { |
|
|
|
|
|
this.injectorForCustomComponent = Injector.create({ |
|
|
|
|
|
providers: [ |
|
|
|
|
|
{ |
|
|
|
|
|
provide: FORM_PROP_DATA_STREAM, |
|
|
|
|
|
useValue: currentProp |
|
|
|
|
|
} |
|
|
|
|
|
], |
|
|
|
|
|
parent: this.injector, |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (options) this.options$ = options(this.data); |
|
|
if (options) this.options$ = options(this.data); |
|
|
if (readonly) this.readonly = readonly(this.data); |
|
|
if (readonly) this.readonly = readonly(this.data); |
|
|
|
|
|
|
|
|
if (disabled) { |
|
|
if (disabled) { |
|
|
this.disabledFn = disabled; |
|
|
this.disabledFn = disabled; |
|
|
} |
|
|
} |
|
|
|