import { Section } from '../../models/Section'; import { JsonSerializer } from '../../utilities/JsonSerializer'; import { Rule } from '../../models/Rule'; import { DatasetWizardService } from '../../services/dataset-wizard/dataset-wizard.service'; import { BaseHttpService } from '../../utilities/cite-http-service-module/base-http.service'; import { VisibilityRulesService } from '../../utilities/visibility-rules/visibility-rules.service'; import { DatasetProfileDefinitionModel } from '../../models/DatasetProfileDefinitionModel'; import { DatasetWizardModel } from '../../models/datasets/DatasetWizardModel'; import { Component, Input, OnInit, AfterViewChecked, ViewChild, forwardRef, ViewEncapsulation, AfterViewInit, ChangeDetectionStrategy } from '@angular/core'; import { FormGroup, Validators, ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { NgForm } from '@angular/forms'; import { Router, ActivatedRoute, ParamMap, Params } from '@angular/router'; import 'rxjs/add/operator/switchMap'; import { Location } from '@angular/common'; import { MatSidenavModule } from '@angular/material/sidenav'; declare function simple_notifier(type: string, title: string, message: string): any; @Component({ selector: 'dynamic-form', templateUrl: './dynamic-form.component.html', styleUrls: [ './dynamic-form.component.scss' ], providers: [ ], encapsulation: ViewEncapsulation.None, }) export class DynamicFormComponent implements OnInit, AfterViewInit { @Input() dataModel: DatasetWizardModel = new DatasetWizardModel(); @Input() path: string; @Input() form: FormGroup; id: string; trackByFn = (index, item) => item ? item["id"] : null pageTrackByFn = (index, item) => item["id"] // @Input() datasetId: string; pathName: string; pages: Array; activeStepperIndex: number = 1; visibleSidebar: boolean = false; datasetProfileDefinitionModel: DatasetProfileDefinitionModel private progressbar: boolean = false; private currentPageIndex: number = 0; private fragment: string; constructor(private router: Router, private _location: Location, private route: ActivatedRoute, private visibilityRulesService: VisibilityRulesService, private http: BaseHttpService, private datasetWizardService: DatasetWizardService, ) { //this.datasetId = route.snapshot.params['id']; } getSubForm(subformName) { return this.form.controls[subformName]; } ngOnInit() { let rules: Rule[] = JsonSerializer.fromJSONArray(this.dataModel.datasetProfileDefinition.rules, Rule); this.visibilityRulesService.formGroup = this.form; this.visibilityRulesService.buildVisibilityRules(rules) this.datasetProfileDefinitionModel = this.dataModel.datasetProfileDefinition this.visibilityRulesService.setModel(this.datasetProfileDefinitionModel) this.createPagination(); this.progressbar = true; this.route.fragment.subscribe((fragment: string) => { var self = this; setTimeout(function () { self.scrollTo(fragment) }); }); this.route.queryParams.subscribe((params) => { if (params && "page" in params) this.changeCurrentPage(params["page"]); }); } ngAfterViewInit() { this.visibilityRulesService.triggerVisibilityEvaluation() } toggleSidebar() { this.visibleSidebar = !this.visibleSidebar; } // getPages(model: DatasetProfileDefinitionModel): Array { // let pageSet = new Set(); // model.sections.forEach(section => { // pageSet.add(section.page); // }); // return Array.from(pageSet).sort((a, b) => a - b); // } shouldDisplaySection(section: Section): Boolean { return (section.page) == this.currentPageIndex; } createPagination() { /*this.pages.forEach(item => { this.stepperItems.push({ label: '', }) });*/ } changePageIndex(index: any) { this.router.navigate([this.route.snapshot.url[0] + "/" + this.route.snapshot.url[1]], { queryParams: { page: this.pages[index - 1] } }); } scrollTo(sectionID: string) { if (!sectionID) return; var element = document.querySelector('#' + sectionID); if (!element) return; element.scrollIntoView(); this.visibleSidebar = true; var scrollElement = document.querySelector('.scrollableContent'); //scrollElement.scrollTop = topElement.offsetTop; } changeCurrentPage(pageString: string) { if (!pageString) return; var page = parseInt(pageString); if (isNaN(page)) return; var pageIndex = this.pages.indexOf(page); if (pageIndex === -1) return; this.currentPageIndex = page; } }