argos/dmp-frontend/src/app/ui/description/editor/description-form/components/form-section/form-section.component.ts

86 lines
2.7 KiB
TypeScript

import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
EventEmitter,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges
} from '@angular/core';
import { UntypedFormGroup } from '@angular/forms';
import { DescriptionTemplateSection } from '@app/core/model/description-template/description-template';
import { BaseComponent } from '@common/base/base.component';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
import { ToCEntry } from '../../../table-of-contents/models/toc-entry';
import { ToCEntryType } from '../../../table-of-contents/models/toc-entry-type.enum';
import { LinkToScroll } from '../../../table-of-contents/table-of-contents.component';
import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service';
import { Guid } from '@common/types/guid';
@Component({
selector: 'app-description-form-section',
templateUrl: './form-section.component.html',
styleUrls: ['./form-section.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DescriptionFormSectionComponent extends BaseComponent implements OnInit, OnChanges {
@Input() section: DescriptionTemplateSection;
@Input() propertiesFormGroup: UntypedFormGroup;
@Input() visibilityRulesService: VisibilityRulesService;
@Input() path: string;
@Input() descriptionId: Guid;
// @Input() datasetProfileId: String;
// @Input() form: UntypedFormGroup;
@Input() tocentry: ToCEntry;
@Input() pathName: string;
@Input() linkToScroll: LinkToScroll;
@Input() hiddenEntriesIds: string[] = [];
panelExpanded = true;
subsectionLinkToScroll: LinkToScroll;
@Output() askedToScroll = new EventEmitter<string>();
tocentriesType = ToCEntryType;
@Input() TOCENTRY_ID_PREFIX = "";
@Input() validationErrorModel: ValidationErrorModel;
constructor(
private changeDetector: ChangeDetectorRef
) {
super();
}
ngOnInit() {
// this.visibilityRulesService.getElementVisibilityMapObservable().pipe(takeUntil(this._destroyed)).subscribe(x => {
// this.changeDetector.markForCheck();
// });
}
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;
}
}
}
}
onAskedToScroll(event:MouseEvent, id: string) {
event.stopPropagation();
this.panelExpanded = true;
this.askedToScroll.emit(id);
}
}