2019-03-01 16:16:21 +01:00
|
|
|
import { Component, Input, OnInit } from "@angular/core";
|
|
|
|
import { FormArray, FormGroup } from "@angular/forms";
|
2019-12-11 15:51:03 +01:00
|
|
|
import { DatasetWizardService } from '@app/core/services/dataset-wizard/dataset-wizard.service';
|
|
|
|
import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item';
|
|
|
|
import { IBreadCrumbComponent } from '@app/ui/misc/breadcrumb/definition/IBreadCrumbComponent';
|
|
|
|
import { DatasetDescriptionFormEditorModel } from '@app/ui/misc/dataset-description-form/dataset-description-form.model';
|
|
|
|
import { QuickWizardDatasetDescriptionModel } from '@app/ui/quick-wizard/dataset-editor/quick-wizard-dataset-description-model';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
2019-04-02 09:00:15 +02:00
|
|
|
import { TranslateService } from "@ngx-translate/core";
|
2019-03-01 16:16:21 +01:00
|
|
|
import { Observable } from "rxjs";
|
|
|
|
import { takeUntil } from "rxjs/operators";
|
2020-01-16 11:08:51 +01:00
|
|
|
import { LinkToScroll } from '@app/ui/misc/dataset-description-form/tableOfContentsMaterial/table-of-contents';
|
2019-03-01 16:16:21 +01:00
|
|
|
|
|
|
|
@Component({
|
2019-03-26 16:52:21 +01:00
|
|
|
selector: 'app-dataset-editor-wizard-component',
|
|
|
|
templateUrl: 'dataset-editor-wizard.component.html',
|
|
|
|
styleUrls: ['./dataset-editor-wizard.component.scss']
|
2019-03-01 16:16:21 +01:00
|
|
|
})
|
|
|
|
export class DatasetEditorWizardComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
|
2019-03-26 16:52:21 +01:00
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
2019-03-01 16:16:21 +01:00
|
|
|
|
2019-03-26 16:52:21 +01:00
|
|
|
@Input() formGroup: FormGroup;
|
2019-06-19 10:59:47 +02:00
|
|
|
@Input() datasetProfile: FormGroup; // DatasetProfileModel;
|
2019-03-26 16:52:21 +01:00
|
|
|
@Input() datasetLabel: string;
|
|
|
|
editedDataset: boolean = false;
|
|
|
|
dataset: DatasetDescriptionFormEditorModel;
|
|
|
|
public datasetProfileDefinition: DatasetDescriptionFormEditorModel;
|
|
|
|
public lastIndexOfDataset = 0;
|
|
|
|
public toggleButton = 0;
|
|
|
|
public _inputValue: string;
|
2019-03-01 16:16:21 +01:00
|
|
|
|
2019-06-19 10:59:47 +02:00
|
|
|
isFirst: boolean;
|
|
|
|
|
2019-03-26 16:52:21 +01:00
|
|
|
constructor(
|
|
|
|
private datasetWizardService: DatasetWizardService,
|
|
|
|
public language: TranslateService,
|
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
2019-03-01 16:16:21 +01:00
|
|
|
|
2019-03-26 16:52:21 +01:00
|
|
|
ngOnInit(): void {
|
|
|
|
this.datasetWizardService.getDefinition(this.datasetProfile.value["id"])
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(item => {
|
|
|
|
this.datasetProfileDefinition = new DatasetDescriptionFormEditorModel().fromModel(item);
|
|
|
|
this.onValChange("list");
|
|
|
|
const length = (this.formGroup.get('datasets').get('datasetsList') as FormArray).length;
|
|
|
|
if (length == 0) {
|
|
|
|
this.lastIndexOfDataset = length;
|
2019-06-19 10:59:47 +02:00
|
|
|
this.isFirst = true;
|
|
|
|
this.addDataset(this.isFirst);
|
2019-03-26 16:52:21 +01:00
|
|
|
this.onValChange("dataset");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-03-05 12:21:04 +01:00
|
|
|
|
2019-03-26 16:52:21 +01:00
|
|
|
onValChange(event: any) {
|
|
|
|
if (event == "list") {
|
|
|
|
this.toggleButton = 0;
|
|
|
|
this.editedDataset = false;
|
|
|
|
this._inputValue = "list";
|
|
|
|
} else if (event == "add") {
|
2019-06-19 10:59:47 +02:00
|
|
|
this.addDataset(this.isFirst);
|
2019-03-26 16:52:21 +01:00
|
|
|
this.toggleButton = 2;
|
|
|
|
this._inputValue = "dataset";
|
|
|
|
} else if (event == "dataset") {
|
|
|
|
this.toggleButton = 2;
|
|
|
|
this._inputValue = "dataset";
|
|
|
|
}
|
|
|
|
}
|
2019-03-01 16:16:21 +01:00
|
|
|
|
2019-03-26 16:52:21 +01:00
|
|
|
editDataset(index: number) {
|
2019-06-19 10:59:47 +02:00
|
|
|
// this.lastIndexOfDataset = index;
|
2019-03-26 16:52:21 +01:00
|
|
|
this.toggleButton = 2;
|
|
|
|
this.editedDataset = true;
|
|
|
|
this._inputValue = "dataset"
|
|
|
|
}
|
2019-03-01 16:16:21 +01:00
|
|
|
|
2019-03-26 16:52:21 +01:00
|
|
|
deleteDataset(index: number) {//TODO: delete Dataset From List
|
|
|
|
this.lastIndexOfDataset = index;
|
|
|
|
this.toggleButton = 0;
|
|
|
|
this.editedDataset = false;
|
|
|
|
this._inputValue = "list";
|
|
|
|
(this.formGroup.get('datasets').get('datasetsList') as FormArray).removeAt(index);
|
2019-10-08 17:26:55 +02:00
|
|
|
if (index == 0) {
|
|
|
|
this.isFirst = true;
|
|
|
|
}
|
2019-03-26 16:52:21 +01:00
|
|
|
}
|
2019-03-05 12:21:04 +01:00
|
|
|
|
2019-06-19 10:59:47 +02:00
|
|
|
addDataset(isFirst: boolean) {
|
2019-03-26 16:52:21 +01:00
|
|
|
const formArray: FormArray = (this.formGroup.get('datasets').get('datasetsList') as FormArray);
|
|
|
|
let dataset = new QuickWizardDatasetDescriptionModel().fromModel(this.datasetProfileDefinition);
|
|
|
|
let formGroup = dataset.buildForm();
|
2019-03-01 16:16:21 +01:00
|
|
|
|
2019-09-25 16:09:19 +02:00
|
|
|
if (isFirst) {
|
2019-06-19 10:59:47 +02:00
|
|
|
formGroup.get('datasetLabel').setValue(
|
|
|
|
this.datasetProfile.value["label"] + " " +
|
|
|
|
this.language.instant('GENERAL.NAMES.DATASET')
|
|
|
|
);
|
|
|
|
this.isFirst = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
formGroup.get('datasetLabel').setValue(
|
|
|
|
this.datasetProfile.value["label"] + " " +
|
|
|
|
this.language.instant('GENERAL.NAMES.DATASET') +
|
|
|
|
" (" +
|
|
|
|
this.lastIndexOfDataset + ")"
|
|
|
|
);
|
|
|
|
}
|
2019-03-26 16:52:21 +01:00
|
|
|
formArray.push(formGroup);
|
|
|
|
this.lastIndexOfDataset = formArray.length - 1;
|
|
|
|
this.editedDataset = true;
|
2019-09-25 16:09:19 +02:00
|
|
|
this.scrollToTop();
|
2019-03-26 16:52:21 +01:00
|
|
|
}
|
2019-03-01 16:16:21 +01:00
|
|
|
|
2019-03-26 16:52:21 +01:00
|
|
|
listingMode() {
|
|
|
|
if (this.toggleButton === 0) return true;
|
|
|
|
}
|
2019-09-25 16:09:19 +02:00
|
|
|
|
|
|
|
scrollToTop() {
|
|
|
|
var currentScroll = document.documentElement.scrollTop || document.body.scrollTop;
|
|
|
|
if (currentScroll > 0) {
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
}
|
2020-01-16 11:08:51 +01:00
|
|
|
|
|
|
|
linkToScroll: LinkToScroll;
|
|
|
|
onStepFound(linkToScroll: LinkToScroll) {
|
|
|
|
this.linkToScroll = linkToScroll;
|
|
|
|
}
|
2019-03-26 16:52:21 +01:00
|
|
|
}
|