mirror of https://github.com/abpframework/abp.git
3 changed files with 96 additions and 96 deletions
@ -1,82 +1,84 @@ |
|||||
import {TrackByService} from '@abp/ng.core'; |
import { TrackByService } from '@abp/ng.core'; |
||||
import { |
import { |
||||
ChangeDetectionStrategy, |
ChangeDetectionStrategy, |
||||
ChangeDetectorRef, |
ChangeDetectorRef, |
||||
Component, inject, |
Component, |
||||
Input, |
inject, |
||||
Optional, |
Input, |
||||
QueryList, |
Optional, |
||||
SkipSelf, |
QueryList, |
||||
ViewChildren, |
SkipSelf, |
||||
|
ViewChildren, |
||||
} from '@angular/core'; |
} from '@angular/core'; |
||||
import {ControlContainer, ReactiveFormsModule, UntypedFormGroup} from '@angular/forms'; |
import { ControlContainer, ReactiveFormsModule, UntypedFormGroup } from '@angular/forms'; |
||||
import {EXTRA_PROPERTIES_KEY} from '../../constants/extra-properties'; |
import { EXTRA_PROPERTIES_KEY } from '../../constants/extra-properties'; |
||||
import {FormProp, FormPropList, GroupedFormPropList} from '../../models/form-props'; |
import { FormProp, FormPropList, GroupedFormPropList } from '../../models/form-props'; |
||||
import {ExtensionsService} from '../../services/extensions.service'; |
import { ExtensionsService } from '../../services/extensions.service'; |
||||
import {EXTENSIONS_IDENTIFIER} from '../../tokens/extensions.token'; |
import { EXTENSIONS_IDENTIFIER } from '../../tokens/extensions.token'; |
||||
import {selfFactory} from '../../utils/factory.util'; |
import { selfFactory } from '../../utils/factory.util'; |
||||
import {ExtensibleFormPropComponent} from './extensible-form-prop.component'; |
import { ExtensibleFormPropComponent } from './extensible-form-prop.component'; |
||||
import {CommonModule} from "@angular/common"; |
import { CommonModule } from '@angular/common'; |
||||
import {PropDataDirective} from "../../directives/prop-data.directive"; |
import { PropDataDirective } from '../../directives/prop-data.directive'; |
||||
|
|
||||
@Component({ |
@Component({ |
||||
exportAs: 'abpExtensibleForm', |
standalone: true, |
||||
selector: 'abp-extensible-form', |
exportAs: 'abpExtensibleForm', |
||||
templateUrl: './extensible-form.component.html', |
selector: 'abp-extensible-form', |
||||
standalone:true, |
templateUrl: './extensible-form.component.html', |
||||
imports:[CommonModule, PropDataDirective,ReactiveFormsModule,ExtensibleFormPropComponent], |
imports: [CommonModule, PropDataDirective, ReactiveFormsModule, ExtensibleFormPropComponent], |
||||
changeDetection: ChangeDetectionStrategy.OnPush, |
changeDetection: ChangeDetectionStrategy.OnPush, |
||||
viewProviders: [ |
viewProviders: [ |
||||
{ |
{ |
||||
provide: ControlContainer, |
provide: ControlContainer, |
||||
useFactory: selfFactory, |
useFactory: selfFactory, |
||||
deps: [[new Optional(), new SkipSelf(), ControlContainer]], |
deps: [[new Optional(), new SkipSelf(), ControlContainer]], |
||||
}, |
}, |
||||
], |
], |
||||
}) |
}) |
||||
export class ExtensibleFormComponent<R = any> { |
export class ExtensibleFormComponent<R = any> { |
||||
|
public readonly cdRef = inject(ChangeDetectorRef); |
||||
|
public readonly track = inject(TrackByService); |
||||
|
private readonly container = inject(ControlContainer); |
||||
|
private readonly extensions = inject(ExtensionsService); |
||||
|
private readonly identifier = inject(EXTENSIONS_IDENTIFIER); |
||||
|
|
||||
@ViewChildren(ExtensibleFormPropComponent) |
@ViewChildren(ExtensibleFormPropComponent) |
||||
formProps!: QueryList<ExtensibleFormPropComponent>; |
formProps!: QueryList<ExtensibleFormPropComponent>; |
||||
|
|
||||
@Input() |
@Input() |
||||
set selectedRecord(record: R) { |
set selectedRecord(record: R) { |
||||
const type = !record || JSON.stringify(record) === '{}' ? 'create' : 'edit'; |
const type = !record || JSON.stringify(record) === '{}' ? 'create' : 'edit'; |
||||
const propList = this.extensions[`${type}FormProps`].get(this.identifier).props; |
const propList = this.extensions[`${type}FormProps`].get(this.identifier).props; |
||||
this.groupedPropList = this.createGroupedList(propList); |
this.groupedPropList = this.createGroupedList(propList); |
||||
this.record = record; |
this.record = record; |
||||
} |
} |
||||
|
|
||||
extraPropertiesKey = EXTRA_PROPERTIES_KEY; |
extraPropertiesKey = EXTRA_PROPERTIES_KEY; |
||||
groupedPropList!: GroupedFormPropList; |
groupedPropList!: GroupedFormPropList; |
||||
groupedPropListOfArray: FormProp<any>[][]; |
groupedPropListOfArray: FormProp<any>[][]; |
||||
record!: R; |
record!: R; |
||||
|
|
||||
public readonly cdRef = inject(ChangeDetectorRef) |
get form(): UntypedFormGroup { |
||||
public readonly track = inject(TrackByService) |
return (this.container ? this.container.control : { controls: {} }) as UntypedFormGroup; |
||||
private container = inject(ControlContainer) |
} |
||||
private extensions = inject(ExtensionsService); |
|
||||
private identifier = inject(EXTENSIONS_IDENTIFIER) |
|
||||
|
|
||||
createGroupedList(propList: FormPropList<R>) { |
get extraProperties(): UntypedFormGroup { |
||||
const groupedFormPropList = new GroupedFormPropList(); |
return (this.form.controls.extraProperties || { controls: {} }) as UntypedFormGroup; |
||||
propList.forEach(item => { |
} |
||||
groupedFormPropList.addItem(item.value); |
|
||||
}); |
|
||||
return groupedFormPropList; |
|
||||
} |
|
||||
|
|
||||
isAnyGroupMemberVisible(index: number, data){ |
createGroupedList(propList: FormPropList<R>) { |
||||
const isVisible = this.groupedPropList.items.map(i => i.formPropList.toArray())[index].find(prop => prop.visible(data)); |
const groupedFormPropList = new GroupedFormPropList(); |
||||
return isVisible; |
propList.forEach(item => { |
||||
} |
groupedFormPropList.addItem(item.value); |
||||
|
}); |
||||
|
|
||||
get form(): UntypedFormGroup { |
return groupedFormPropList; |
||||
return (this.container ? this.container.control : {controls: {}}) as UntypedFormGroup; |
} |
||||
} |
|
||||
|
|
||||
get extraProperties(): UntypedFormGroup { |
|
||||
return (this.form.controls.extraProperties || {controls: {}}) as UntypedFormGroup; |
|
||||
} |
|
||||
|
|
||||
|
//TODO: Reactor this method
|
||||
|
isAnyGroupMemberVisible(index: number, data) { |
||||
|
const { items } = this.groupedPropList; |
||||
|
const formPropList = items[index].formPropList.toArray(); |
||||
|
return formPropList.some(prop => prop.visible(data)); |
||||
|
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue