argos/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.co...

49 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-09-25 16:09:19 +02:00
import { AfterViewInit, Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild } from '@angular/core';
import { FormGroup } from '@angular/forms';
2019-09-25 16:09:19 +02:00
import { MatHorizontalStepper } from '@angular/material/stepper';
import { Rule } from '@app/core/model/dataset-profile-definition/rule';
import { LinkToScroll } from '@app/ui/misc/dataset-description-form/tableOfContentsMaterial/table-of-contents';
import { VisibilityRulesService } from '@app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service';
import { BaseComponent } from '@common/base/base.component';
2018-01-30 10:35:26 +01:00
@Component({
2019-01-18 18:03:45 +01:00
selector: 'app-dataset-description-form',
templateUrl: './dataset-description-form.component.html',
styleUrls: ['./dataset-description-form.component.scss']
2018-01-30 10:35:26 +01:00
})
2019-09-25 16:09:19 +02:00
export class DatasetDescriptionFormComponent extends BaseComponent implements OnInit, AfterViewInit, OnChanges {
2018-01-30 10:35:26 +01:00
2019-09-25 16:09:19 +02:00
@ViewChild('stepper', { static: false }) stepper: MatHorizontalStepper;
2018-10-05 17:00:54 +02:00
@Input() path: string;
@Input() form: FormGroup;
@Input() visibilityRules: Rule[] = [];
@Input() datasetProfileId: String;
2019-10-22 14:46:48 +02:00
@Input() linkToScroll: LinkToScroll;
2018-10-05 17:00:54 +02:00
constructor(
2018-10-05 17:00:54 +02:00
private visibilityRulesService: VisibilityRulesService,
) {
2018-11-27 18:33:17 +01:00
super();
2018-10-05 17:00:54 +02:00
}
ngOnInit() {
this.visibilityRulesService.buildVisibilityRules(this.visibilityRules, this.form);
}
2018-10-05 17:00:54 +02:00
2019-09-25 16:09:19 +02:00
ngOnChanges(changes: SimpleChanges) {
// When the form is changed set stepper index to 0.
if (this.stepper && changes['form'] && !changes['form'].isFirstChange()) {
2019-09-25 16:09:19 +02:00
this.stepper.selectedIndex = 0;
} else if (this.stepper && changes['linkToScroll'] && changes['linkToScroll'].currentValue) {
2019-10-22 14:46:48 +02:00
if (changes['linkToScroll'].currentValue.page >= 0) {
this.stepper.selectedIndex = changes['linkToScroll'].currentValue.page;
}
2019-09-25 16:09:19 +02:00
}
}
ngAfterViewInit() {
2018-10-05 17:00:54 +02:00
2019-10-22 14:46:48 +02:00
}
2018-05-28 11:50:42 +02:00
}