2021-03-18 09:52:18 +01:00
|
|
|
import { AfterViewInit, Component, Input, OnInit, OnChanges, SimpleChanges, Output, EventEmitter } from '@angular/core';
|
2019-01-31 11:29:35 +01:00
|
|
|
import { FormGroup, FormArray, AbstractControl } from '@angular/forms';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { FormFocusService } from '../../form-focus/form-focus.service';
|
|
|
|
import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service';
|
2019-01-31 11:29:35 +01:00
|
|
|
import { DatasetDescriptionSectionEditorModel, DatasetDescriptionCompositeFieldEditorModel } from '../../dataset-description-form.model';
|
|
|
|
import { FormCompositeFieldComponent } from '../form-composite-field/form-composite-field.component';
|
2019-10-15 16:25:43 +02:00
|
|
|
import { LinkToScroll } from '../../tableOfContentsMaterial/table-of-contents';
|
2021-03-09 09:04:50 +01:00
|
|
|
import { ToCEntry, ToCEntryType } from '../../dataset-description.component';
|
|
|
|
|
2018-01-05 18:02:26 +01:00
|
|
|
|
2017-11-23 11:40:02 +01:00
|
|
|
@Component({
|
2019-01-18 18:03:45 +01:00
|
|
|
selector: 'app-form-section',
|
|
|
|
templateUrl: './form-section.component.html',
|
|
|
|
styleUrls: ['./form-section.component.scss']
|
2017-12-06 11:35:50 +01:00
|
|
|
})
|
2019-10-15 16:25:43 +02:00
|
|
|
export class FormSectionComponent implements OnInit, OnChanges {
|
2017-11-23 11:40:02 +01:00
|
|
|
|
2019-01-31 11:29:35 +01:00
|
|
|
//@Input() section: DatasetDescriptionSectionEditorModel;
|
2019-01-29 08:47:50 +01:00
|
|
|
@Input() datasetProfileId: String;
|
2019-01-28 14:47:31 +01:00
|
|
|
@Input() form: FormGroup;
|
2021-03-09 09:04:50 +01:00
|
|
|
@Input() tocentry: ToCEntry;
|
2018-10-05 17:00:54 +02:00
|
|
|
@Input() pathName: string;
|
|
|
|
@Input() path: string;
|
2019-10-15 16:25:43 +02:00
|
|
|
@Input() linkToScroll: LinkToScroll;
|
2019-01-28 14:47:31 +01:00
|
|
|
//trackByFn = (index, item) => item ? item['id'] : null;
|
2019-10-15 16:25:43 +02:00
|
|
|
panelExpanded = true;
|
|
|
|
// sub = true;
|
|
|
|
subsectionLinkToScroll: LinkToScroll;
|
2021-03-18 09:52:18 +01:00
|
|
|
|
|
|
|
|
2021-04-06 08:57:17 +02:00
|
|
|
@Output() askedToScroll = new EventEmitter<string>();
|
2021-03-09 09:04:50 +01:00
|
|
|
|
|
|
|
tocentriesType = ToCEntryType;
|
2021-03-18 09:52:18 +01:00
|
|
|
@Input() TOCENTRY_ID_PREFIX="";
|
2019-10-15 16:25:43 +02:00
|
|
|
|
2018-11-01 17:02:15 +01:00
|
|
|
constructor(
|
2019-01-31 11:29:35 +01:00
|
|
|
public visibilityRulesService: VisibilityRulesService,
|
2018-11-01 17:02:15 +01:00
|
|
|
private formFocusService: FormFocusService
|
|
|
|
) { }
|
2017-11-23 11:40:02 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
ngOnInit() {
|
2019-01-28 14:47:31 +01:00
|
|
|
// if (this.section) {
|
|
|
|
// this.form = this.visibilityRulesService.getFormGroup(this.section.id);
|
|
|
|
// }
|
2021-03-09 09:04:50 +01:00
|
|
|
|
|
|
|
if(this.tocentry){//maybe not needed as well
|
|
|
|
this.form = this.tocentry.form as FormGroup;
|
|
|
|
}
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2018-09-18 14:41:24 +02:00
|
|
|
|
2019-10-15 16:25:43 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 14:47:31 +01:00
|
|
|
// ngAfterViewInit() {
|
|
|
|
// this.visibilityRulesService.triggerVisibilityEvaluation();
|
|
|
|
// }
|
2018-01-05 18:02:26 +01:00
|
|
|
|
2019-01-31 11:29:35 +01:00
|
|
|
addMultipleField(fieldsetIndex: number) {
|
|
|
|
const compositeFieldToBeCloned = (this.form.get('compositeFields').get('' + fieldsetIndex) as FormGroup).getRawValue();
|
2019-02-01 09:29:00 +01:00
|
|
|
const compositeField: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel().cloneForMultiplicity(compositeFieldToBeCloned);
|
2019-01-31 11:29:35 +01:00
|
|
|
(<FormArray>(this.form.get('compositeFields').get('' + fieldsetIndex).get('multiplicityItems'))).push(compositeField.buildForm());
|
|
|
|
}
|
2018-01-05 18:02:26 +01:00
|
|
|
|
2019-09-18 13:35:51 +02:00
|
|
|
deleteCompositeFieldFormGroup(compositeFildIndex: number) {
|
2020-01-29 11:38:16 +01:00
|
|
|
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);
|
|
|
|
}
|
2019-09-18 13:35:51 +02:00
|
|
|
(<FormArray>(this.form.get('compositeFields').get('' + compositeFildIndex).get('multiplicityItems'))).removeAt(0);
|
|
|
|
}
|
|
|
|
|
2019-02-04 14:41:54 +01:00
|
|
|
deleteMultipeFieldFromCompositeFormGroup(compositeFildIndex: number, fildIndex: number) {
|
|
|
|
(<FormArray>(this.form.get('compositeFields').get('' + compositeFildIndex).get('multiplicityItems'))).removeAt(fildIndex);
|
|
|
|
}
|
|
|
|
|
2019-01-28 14:47:31 +01:00
|
|
|
// isElementVisible(fieldSet: CompositeField): boolean {
|
|
|
|
// return fieldSet && fieldSet.fields && fieldSet.fields.length > 0
|
|
|
|
// }
|
2018-11-01 17:02:15 +01:00
|
|
|
|
2019-01-28 14:47:31 +01:00
|
|
|
// next(compositeField: CompositeField) {
|
|
|
|
// this.formFocusService.focusNext(compositeField);
|
|
|
|
// }
|
2021-03-18 09:52:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-06 08:57:17 +02:00
|
|
|
onAskedToScroll(id:string){
|
2021-03-18 09:52:18 +01:00
|
|
|
this.panelExpanded = true;
|
2021-04-06 08:57:17 +02:00
|
|
|
this.askedToScroll.emit(id);
|
2021-03-18 09:52:18 +01:00
|
|
|
}
|
2018-05-28 11:50:42 +02:00
|
|
|
}
|