2022-02-03 19:06:27 +01:00
|
|
|
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
|
|
|
|
import { FormArray, FormGroup } from '@angular/forms';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { DatasetDescriptionCompositeFieldEditorModel } from '../../../dataset-description-form.model';
|
2021-03-29 17:42:55 +02:00
|
|
|
import { FormFocusService } from '../../../form-focus/form-focus.service';
|
|
|
|
import { LinkToScroll } from '../../../tableOfContentsMaterial/table-of-contents';
|
2022-02-03 19:06:27 +01:00
|
|
|
import { VisibilityRulesService } from '../../../visibility-rules/visibility-rules.service';
|
2021-03-29 17:42:55 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-form-section-inner',
|
|
|
|
templateUrl: './form-section-inner.component.html',
|
2022-02-03 19:06:27 +01:00
|
|
|
styleUrls: ['./form-section-inner.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2021-03-29 17:42:55 +02:00
|
|
|
})
|
2022-02-03 19:06:27 +01:00
|
|
|
export class FormSectionInnerComponent extends BaseComponent implements OnInit, OnChanges {
|
2021-03-29 17:42:55 +02:00
|
|
|
|
|
|
|
//@Input() section: DatasetDescriptionSectionEditorModel;
|
|
|
|
@Input() datasetProfileId: String;
|
|
|
|
// @Input() compositeFieldFormGroup: FormGroup;
|
2022-02-03 19:06:27 +01:00
|
|
|
@Input() form: FormGroup;
|
2021-03-29 17:42:55 +02:00
|
|
|
@Input() pathName: string;
|
|
|
|
@Input() path: string;
|
|
|
|
// @Input() i: number;
|
|
|
|
@Input() linkToScroll: LinkToScroll;
|
|
|
|
//trackByFn = (index, item) => item ? item['id'] : null;
|
|
|
|
panelExpanded = true;
|
|
|
|
// sub = true;
|
|
|
|
subsectionLinkToScroll: LinkToScroll;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
public visibilityRulesService: VisibilityRulesService,
|
2022-02-03 19:06:27 +01:00
|
|
|
private changeDetector: ChangeDetectorRef,
|
2021-03-29 17:42:55 +02:00
|
|
|
private formFocusService: FormFocusService
|
2022-02-03 19:06:27 +01:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
this.visibilityRulesService.getElementVisibilityMapObservable().pipe(takeUntil(this._destroyed)).subscribe(x => {
|
|
|
|
this.changeDetector.markForCheck();
|
|
|
|
});
|
|
|
|
}
|
2021-03-29 17:42:55 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
// if (this.section) {
|
|
|
|
// this.form = this.visibilityRulesService.getFormGroup(this.section.id);
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges) {
|
|
|
|
|
|
|
|
// if (changes['linkToScroll']) {
|
|
|
|
// if (changes['linkToScroll'].currentValue && changes['linkToScroll'].currentValue.section) {
|
|
|
|
|
|
|
|
// if (this.pathName === changes['linkToScroll'].currentValue.section) {
|
|
|
|
// this.panelExpanded = true;
|
|
|
|
// } else if (changes['linkToScroll'].currentValue.section.includes(this.pathName)) {
|
|
|
|
// this.subsectionLinkToScroll = changes['linkToScroll'].currentValue;
|
|
|
|
// this.panelExpanded = true;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
// ngAfterViewInit() {
|
|
|
|
// this.visibilityRulesService.triggerVisibilityEvaluation();
|
|
|
|
// }
|
|
|
|
|
|
|
|
addMultipleField(fieldsetIndex: number) {
|
|
|
|
const compositeFieldToBeCloned = (this.form.get('compositeFields').get('' + fieldsetIndex) as FormGroup).getRawValue();
|
2021-09-17 11:12:48 +02:00
|
|
|
const multiplicityItemsArray = (<FormArray>(this.form.get('compositeFields').get('' + fieldsetIndex).get('multiplicityItems')));
|
|
|
|
const compositeField: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel().cloneForMultiplicity(compositeFieldToBeCloned, multiplicityItemsArray.length);
|
|
|
|
multiplicityItemsArray.push(compositeField.buildForm());
|
2021-03-29 17:42:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteCompositeFieldFormGroup(compositeFildIndex: number) {
|
|
|
|
const numberOfItems = this.form.get('compositeFields').get('' + compositeFildIndex).get('multiplicityItems').get('' + 0).get('fields').value.length;
|
|
|
|
for (let i = 0; i < numberOfItems; i++) {
|
|
|
|
const multiplicityItem = this.form.get('compositeFields').get('' + compositeFildIndex).get('multiplicityItems').get('' + 0).get('fields').get('' + i).value;
|
|
|
|
this.form.get('compositeFields').get('' + compositeFildIndex).get('fields').get('' + i).patchValue(multiplicityItem);
|
|
|
|
}
|
|
|
|
(<FormArray>(this.form.get('compositeFields').get('' + compositeFildIndex).get('multiplicityItems'))).removeAt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteMultipeFieldFromCompositeFormGroup(compositeFildIndex: number, fildIndex: number) {
|
2021-09-17 11:12:48 +02:00
|
|
|
const multiplicityItemsArray = (<FormArray>(this.form.get('compositeFields').get('' + compositeFildIndex).get('multiplicityItems')))
|
|
|
|
multiplicityItemsArray.removeAt(fildIndex);
|
2022-02-03 19:06:27 +01:00
|
|
|
multiplicityItemsArray.controls.forEach((control, i) => {
|
|
|
|
try {
|
2021-09-17 11:12:48 +02:00
|
|
|
control.get('ordinal').setValue(i);
|
2022-02-03 19:06:27 +01:00
|
|
|
} catch {
|
2021-09-17 11:12:48 +02:00
|
|
|
throw 'Could not find ordinal';
|
|
|
|
}
|
|
|
|
});
|
2021-03-29 17:42:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// isElementVisible(fieldSet: CompositeField): boolean {
|
|
|
|
// return fieldSet && fieldSet.fields && fieldSet.fields.length > 0
|
|
|
|
// }
|
|
|
|
|
|
|
|
// next(compositeField: CompositeField) {
|
|
|
|
// this.formFocusService.focusNext(compositeField);
|
|
|
|
// }
|
|
|
|
}
|