2023-12-20 08:20:38 +01:00
|
|
|
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input } from '@angular/core';
|
|
|
|
import { UntypedFormGroup } from '@angular/forms';
|
|
|
|
import { MatDialog } from "@angular/material/dialog";
|
|
|
|
import { DescriptionTemplateFieldSet } from '@app/core/model/description-template/description-template';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { ToCEntry } from '../../../table-of-contents/models/toc-entry';
|
|
|
|
import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-form-field-set',
|
|
|
|
templateUrl: './form-field-set.component.html',
|
|
|
|
styleUrls: ['./form-field-set.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
|
|
})
|
|
|
|
export class DescriptionFormFieldSetComponent extends BaseComponent {
|
|
|
|
|
|
|
|
@Input() fieldSet: DescriptionTemplateFieldSet;
|
|
|
|
@Input() propertiesFormGroup: UntypedFormGroup;
|
|
|
|
isVisibleByVisibilityService: boolean = true;
|
|
|
|
@Input() visibilityRulesService: VisibilityRulesService;
|
2023-12-28 16:18:49 +01:00
|
|
|
@Input() path: String;
|
2023-12-20 08:20:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
@Input() datasetProfileId: String;
|
|
|
|
// @Input() form: UntypedFormGroup;
|
|
|
|
@Input() isChild: Boolean = false;
|
|
|
|
@Input() showDelete: Boolean = false;
|
|
|
|
@Input() tocentry: ToCEntry;
|
|
|
|
@Input() tableRow: boolean = false;
|
|
|
|
@Input() showTitle: boolean = true;
|
|
|
|
@Input() placeholderTitle: boolean = false;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private dialog: MatDialog,
|
|
|
|
private changeDetector: ChangeDetectorRef
|
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.visibilityRulesService.getElementVisibilityMapObservable().pipe(takeUntil(this._destroyed)).subscribe(x => {
|
2024-01-19 13:28:31 +01:00
|
|
|
// console.log('getElementVisibilityMapObservable form field');
|
2023-12-28 16:18:49 +01:00
|
|
|
if (x[this.fieldSet.id]) {
|
|
|
|
this.isVisibleByVisibilityService = x[this.fieldSet.id];
|
2023-12-20 08:20:38 +01:00
|
|
|
// this.changeDetector.markForCheck();
|
2023-12-28 16:18:49 +01:00
|
|
|
} else {
|
|
|
|
this.isVisibleByVisibilityService = false;
|
2023-12-20 08:20:38 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
// if (this.tocentry) {
|
|
|
|
// this.form = this.tocentry.form as UntypedFormGroup;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
// editCompositeFieldInDialog() {
|
|
|
|
// const dialogRef = this.dialog.open(FormCompositeFieldDialogComponent, {
|
|
|
|
// width: '750px',
|
|
|
|
// disableClose: true,
|
|
|
|
// data: {
|
|
|
|
// formGroup: cloneAbstractControl(this.form),
|
|
|
|
// datasetProfileId: this.datasetProfileId,
|
|
|
|
// visibilityRulesService: this.visibilityRulesService
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(data => {
|
|
|
|
// if (data) {
|
|
|
|
// this.form.patchValue(data.value);
|
|
|
|
// this.changeDetector.detectChanges();
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
// deleteCompositeField() {
|
|
|
|
// if (this.isChild) {
|
|
|
|
// this.deleteMultipeFieldFromCompositeFormGroup();
|
|
|
|
// } else {
|
|
|
|
// this.deleteCompositeFieldFormGroup();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// deleteCompositeFieldFormGroup() {
|
|
|
|
|
|
|
|
// const compositeFieldId = ((this.form.get('multiplicityItems') as UntypedFormArray).get('' + 0) as UntypedFormGroup).getRawValue().id;
|
|
|
|
// const fieldIds = (this.form.get('fields') as UntypedFormArray).controls.map(control => control.get('id').value) as string[];
|
|
|
|
|
|
|
|
// const numberOfItems = this.form.get('multiplicityItems').get('' + 0).get('fields').value.length;
|
|
|
|
// for (let i = 0; i < numberOfItems; i++) {
|
|
|
|
// const multiplicityItem = this.form.get('multiplicityItems').get('' + 0).get('fields').get('' + i).value;
|
|
|
|
// this.form.get('fields').get('' + i).patchValue(multiplicityItem);
|
|
|
|
// }
|
|
|
|
// (<UntypedFormArray>(this.form.get('multiplicityItems'))).removeAt(0);
|
|
|
|
|
|
|
|
|
|
|
|
// this.visibilityRulesService.removeAllIdReferences(compositeFieldId);
|
|
|
|
// fieldIds.forEach(x => this.visibilityRulesService.removeAllIdReferences(x));
|
|
|
|
// }
|
|
|
|
|
|
|
|
// deleteMultipeFieldFromCompositeFormGroup() {
|
|
|
|
// const parent = this.form.parent;
|
|
|
|
// const index = (parent as UntypedFormArray).controls.indexOf(this.form);
|
|
|
|
|
|
|
|
// const currentId = this.form.get('id').value;
|
|
|
|
// const fieldIds = (this.form.get('fields') as UntypedFormArray).controls.map(control => control.get('id').value) as string[];
|
|
|
|
|
|
|
|
|
|
|
|
// this.visibilityRulesService.removeAllIdReferences(currentId);
|
|
|
|
// fieldIds.forEach(x => this.visibilityRulesService.removeAllIdReferences(x));
|
|
|
|
|
|
|
|
// (parent as UntypedFormArray).removeAt(index);
|
|
|
|
// (parent as UntypedFormArray).controls.forEach((control, i) => {
|
|
|
|
// try {
|
|
|
|
// control.get('ordinal').setValue(i);
|
|
|
|
// } catch {
|
|
|
|
// throw 'Could not find ordinal';
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
}
|