2019-09-23 10:17:03 +02:00
|
|
|
|
2019-10-15 12:38:51 +02:00
|
|
|
import { of as observableOf, Observable } from 'rxjs';
|
2020-12-14 18:28:13 +01:00
|
|
|
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
2021-02-12 12:23:39 +01:00
|
|
|
import { AfterViewInit, Component, OnChanges, OnInit, SimpleChanges, ViewChild } from '@angular/core';
|
2021-02-04 11:22:52 +01:00
|
|
|
import { Form, FormArray, FormControl, FormGroup } from '@angular/forms';
|
2019-09-23 10:17:03 +02:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
|
import { MatHorizontalStepper } from '@angular/material/stepper';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import { map, takeUntil } from 'rxjs/operators';
|
2019-02-25 17:46:16 +01:00
|
|
|
import * as FileSaver from 'file-saver';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { DatasetProfileEditorModel } from '@app/ui/admin/dataset-profile/editor/dataset-profile-editor-model';
|
|
|
|
import { DatasetWizardModel } from '@app/core/model/dataset/dataset-wizard';
|
|
|
|
import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item';
|
|
|
|
import { DatasetProfileService } from '@app/core/services/dataset-profile/dataset-profile.service';
|
|
|
|
import { LoggingService } from '@app/core/services/logging/logging-service';
|
|
|
|
import { UiNotificationService, SnackBarNotificationLevel } from '@app/core/services/notification/ui-notification-service';
|
|
|
|
import { DatasetProfile } from '@app/core/model/admin/dataset-profile/dataset-profile';
|
|
|
|
import { DatasetProfileEnum } from '@app/core/common/enum/dataset-profile';
|
|
|
|
import { SectionEditorModel } from '@app/ui/admin/dataset-profile/admin/section-editor-model';
|
|
|
|
import { PageEditorModel } from '@app/ui/admin/dataset-profile/admin/page-editor-model';
|
|
|
|
import { DatasetStatus } from '@app/core/common/enum/dataset-status';
|
|
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
2020-06-03 11:13:31 +02:00
|
|
|
import { LanguageInfo } from '@app/core/model/language-info';
|
|
|
|
import { LanguageInfoService } from '@app/core/services/culture/language-info-service';
|
2020-09-22 10:27:10 +02:00
|
|
|
import { FormValidationErrorsDialogComponent } from '@common/forms/form-validation-errors-dialog/form-validation-errors-dialog.component';
|
2020-12-14 18:28:13 +01:00
|
|
|
import { MatomoService } from '@app/core/services/matomo/matomo-service';
|
2021-02-03 11:21:31 +01:00
|
|
|
import { Link, LinkToScroll } from '@app/ui/misc/dataset-description-form/tableOfContentsMaterial/table-of-contents';
|
|
|
|
import { DatasetWizardService } from '@app/core/services/dataset-wizard/dataset-wizard.service';
|
|
|
|
import { DatasetWizardEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model';
|
2021-02-12 12:23:39 +01:00
|
|
|
import { Foo, ToCEntry, ToCEntryType } from '../table-of-contents/table-of-contents-entry';
|
2021-02-04 11:22:52 +01:00
|
|
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
2021-02-12 12:23:39 +01:00
|
|
|
import { FieldSetEditorModel } from '../admin/field-set-editor-model';
|
|
|
|
import { Guid } from '@common/types/guid';
|
|
|
|
import { FieldEditorModel } from '../admin/field-editor-model';
|
|
|
|
import { VisibilityRulesService } from '@app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service';
|
|
|
|
import { StepperSelectionEvent } from '@angular/cdk/stepper';
|
2021-02-15 18:16:48 +01:00
|
|
|
import { DatasetDescriptionCompositeFieldEditorModel, DatasetDescriptionFieldEditorModel, DatasetDescriptionFormEditorModel, DatasetDescriptionPageEditorModel, DatasetDescriptionSectionEditorModel } from '@app/ui/misc/dataset-description-form/dataset-description-form.model';
|
2021-02-17 17:39:07 +01:00
|
|
|
import { Rule } from '@app/core/model/dataset-profile-definition/rule';
|
2019-04-16 12:49:09 +02:00
|
|
|
|
|
|
|
const skipDisable: any[] = require('../../../../../assets/resources/skipDisable.json');
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-dataset-profile-editor-component',
|
|
|
|
templateUrl: './dataset-profile-editor.component.html',
|
|
|
|
styleUrls: ['./dataset-profile-editor.component.scss']
|
|
|
|
})
|
2021-02-12 15:27:35 +01:00
|
|
|
export class DatasetProfileEditorComponent extends BaseComponent implements OnInit {
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
isNew = true;
|
2019-09-16 17:46:19 +02:00
|
|
|
isNewVersion = false;
|
|
|
|
isClone = false;
|
2019-01-18 18:03:45 +01:00
|
|
|
isDeleted = false;
|
|
|
|
dataModel: DatasetProfileEditorModel;
|
|
|
|
form: FormGroup;
|
|
|
|
previewerFormGroup: FormGroup;
|
|
|
|
private datasetProfileId: string;
|
2019-03-26 15:30:33 +01:00
|
|
|
newVersionId: string;
|
2019-01-18 18:03:45 +01:00
|
|
|
dataWizardModel: DatasetWizardModel;
|
2019-05-23 11:40:24 +02:00
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
2019-09-23 10:17:03 +02:00
|
|
|
@ViewChild('stepper', { static: false }) stepper: MatHorizontalStepper;
|
2019-02-11 13:04:45 +01:00
|
|
|
viewOnly = false;
|
2020-09-22 10:27:10 +02:00
|
|
|
nestedCount: number[] = [];
|
|
|
|
nestedIndex: number = 0;
|
|
|
|
errorMessages: string[] = [];
|
2021-02-04 11:22:52 +01:00
|
|
|
tocEntryEnumValues = ToCEntryType;
|
2019-02-06 12:10:44 +01:00
|
|
|
|
2021-02-04 09:33:03 +01:00
|
|
|
// sectionIdPreviewed:string = null;
|
|
|
|
// currentSubForm:FormGroup = null;
|
|
|
|
// currentSectionIndex: number = null;
|
|
|
|
// currentSectionEditorModel: SectionEditorModel = null;
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
constructor(
|
|
|
|
private datasetProfileService: DatasetProfileService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private logger: LoggingService,
|
|
|
|
private uiNotificationService: UiNotificationService,
|
2019-02-06 12:10:44 +01:00
|
|
|
private language: TranslateService,
|
2020-06-03 11:13:31 +02:00
|
|
|
private dialog: MatDialog,
|
2020-12-14 18:28:13 +01:00
|
|
|
private languageInfoService: LanguageInfoService,
|
|
|
|
private httpClient: HttpClient,
|
2021-02-03 11:21:31 +01:00
|
|
|
private matomoService: MatomoService,
|
2021-02-04 11:22:52 +01:00
|
|
|
private enumUtils: EnumUtils,
|
2021-02-12 12:23:39 +01:00
|
|
|
private datasetWizardService: DatasetWizardService,
|
|
|
|
private visibilityRulesService: VisibilityRulesService
|
2019-01-18 18:03:45 +01:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
// this.profileID = route.snapshot.params['id'];
|
|
|
|
// this.cloneId = route.snapshot.params['cloneid'];
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-12-14 18:28:13 +01:00
|
|
|
this.matomoService.trackPageView('Admin: Dataset Profile Edit');
|
2019-01-18 18:03:45 +01:00
|
|
|
this.route.paramMap.pipe(takeUntil(this._destroyed)).subscribe((paramMap: ParamMap) => {
|
|
|
|
this.datasetProfileId = paramMap.get('id');
|
|
|
|
const cloneId = paramMap.get('cloneid');
|
2019-03-26 15:30:33 +01:00
|
|
|
this.newVersionId = paramMap.get('newversionid');
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
if (this.datasetProfileId != null) {
|
|
|
|
this.isNew = false;
|
|
|
|
this.datasetProfileService.getDatasetProfileById(this.datasetProfileId)
|
|
|
|
.pipe(map(data => data as DatasetProfile), takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2019-10-15 12:38:51 +02:00
|
|
|
data => {
|
|
|
|
try {
|
|
|
|
this.dataModel = new DatasetProfileEditorModel().fromModel(data);
|
|
|
|
// this.isDeleted = this.masterItem.isActive === IsActive.Inactive;
|
|
|
|
if (this.dataModel.status === DatasetProfileEnum.FINALIZED) {
|
|
|
|
this.form = this.dataModel.buildForm(true, skipDisable);
|
|
|
|
this.viewOnly = true;
|
|
|
|
} else {
|
|
|
|
this.form = this.dataModel.buildForm();
|
|
|
|
}
|
|
|
|
this.prepareForm();
|
2020-09-14 13:31:20 +02:00
|
|
|
} catch (error) {
|
2019-10-15 12:38:51 +02:00
|
|
|
this.logger.error('Could not parse MasterItem: ' + data);
|
2020-09-14 13:31:20 +02:00
|
|
|
console.log(error)
|
2019-10-15 12:38:51 +02:00
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('NOTIFICATIONS.DEFAULT.ERROR'), SnackBarNotificationLevel.Error);
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
2019-10-15 12:38:51 +02:00
|
|
|
},
|
|
|
|
error => this.onCallbackError(error)
|
2019-01-18 18:03:45 +01:00
|
|
|
);
|
2019-10-15 12:38:51 +02:00
|
|
|
this.breadCrumbs = observableOf([{
|
|
|
|
parentComponentName: 'DatasetProfileListingComponent',
|
|
|
|
label: this.language.instant('NAV-BAR.TEMPLATE'),
|
|
|
|
url: '/dataset-profiles/' + this.datasetProfileId
|
|
|
|
}]);
|
2019-01-18 18:03:45 +01:00
|
|
|
} else if (cloneId != null) {
|
2019-09-16 17:46:19 +02:00
|
|
|
this.isClone = true;
|
2019-01-18 18:03:45 +01:00
|
|
|
this.datasetProfileService.clone(cloneId)
|
|
|
|
.pipe(map(data => data as DatasetProfile), takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2019-10-15 12:38:51 +02:00
|
|
|
data => {
|
|
|
|
try {
|
|
|
|
this.dataModel = new DatasetProfileEditorModel().fromModel(data);
|
|
|
|
// this.isDeleted = this.masterItem.isActive === IsActive.Inactive;
|
|
|
|
this.dataModel.status = DatasetProfileEnum.SAVED;
|
|
|
|
this.form = this.dataModel.buildForm();
|
|
|
|
this.prepareForm();
|
|
|
|
} catch {
|
|
|
|
this.logger.error('Could not parse MasterItem: ' + data);
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('NOTIFICATIONS.DEFAULT.ERROR'), SnackBarNotificationLevel.Error);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error => this.onCallbackError(error)
|
2019-03-26 15:30:33 +01:00
|
|
|
);
|
|
|
|
} else if (this.newVersionId != null) {
|
2019-09-16 17:46:19 +02:00
|
|
|
this.isNewVersion = true;
|
2019-03-26 15:30:33 +01:00
|
|
|
this.datasetProfileService.getDatasetProfileById(this.newVersionId)
|
|
|
|
.pipe(map(data => data as DatasetProfile), takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2019-10-15 12:38:51 +02:00
|
|
|
data => {
|
|
|
|
try {
|
|
|
|
this.dataModel = new DatasetProfileEditorModel().fromModel(data);
|
|
|
|
// this.isDeleted = this.masterItem.isActive === IsActive.Inactive;
|
|
|
|
this.form = this.dataModel.buildForm();
|
|
|
|
this.form.get('version').setValue(this.form.get('version').value + 1);
|
|
|
|
this.form.controls['label'].disable();
|
2019-10-16 16:45:08 +02:00
|
|
|
this.form.controls['description'].disable();
|
2020-06-03 11:13:31 +02:00
|
|
|
this.form.controls['language'].disable();
|
2019-10-15 12:38:51 +02:00
|
|
|
this.prepareForm();
|
|
|
|
} catch {
|
|
|
|
this.logger.error('Could not parse MasterItem: ' + data);
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('NOTIFICATIONS.DEFAULT.ERROR'), SnackBarNotificationLevel.Error);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error => this.onCallbackError(error)
|
2019-01-18 18:03:45 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.dataModel = new DatasetProfileEditorModel();
|
|
|
|
this.form = this.dataModel.buildForm();
|
2019-02-11 13:04:45 +01:00
|
|
|
if (this.dataModel.status === DatasetProfileEnum.FINALIZED) {
|
|
|
|
this.form.disable();
|
|
|
|
this.viewOnly = true;
|
|
|
|
}
|
2021-02-12 12:23:39 +01:00
|
|
|
// this.addSection();
|
|
|
|
// this.addPage();
|
|
|
|
this.visibilityRulesService.buildVisibilityRules([],this.form);
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
prepareForm() {
|
2021-02-12 12:23:39 +01:00
|
|
|
this.visibilityRulesService.buildVisibilityRules([],this.form);
|
2019-01-18 18:03:45 +01:00
|
|
|
this.form.valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(change => {
|
|
|
|
// this.datasetProfileService.preview(this.form.value)
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(dataset => {
|
|
|
|
// const datasetModel = new DatasetWizardModel();
|
|
|
|
// datasetModel.datasetProfileDefinition = JsonSerializer.fromJSONObject(dataset, DatasetProfileDefinitionModel);
|
|
|
|
// this.dataWizardModel = datasetModel;
|
|
|
|
// this.previewerFormGroup = <FormGroup>this.dataWizardModel.buildForm().get('datasetProfileDefinition');
|
|
|
|
// });
|
|
|
|
});
|
|
|
|
this.form.updateValueAndValidity();
|
2021-02-03 11:21:31 +01:00
|
|
|
|
|
|
|
//this.getPreview();
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onIsMultiplicityEnabledChange(isMultiplicityEnabled: boolean) {
|
|
|
|
if (!isMultiplicityEnabled) {
|
|
|
|
(<FormControl>this.form.get('multiplicity').get('min')).setValue(0);
|
|
|
|
(<FormControl>this.form.get('multiplicity').get('max')).setValue(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addSection() {
|
|
|
|
const section: SectionEditorModel = new SectionEditorModel();
|
|
|
|
this.dataModel.sections.push(section);
|
|
|
|
(<FormArray>this.form.get('sections')).push(section.buildForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
addPage() {
|
|
|
|
const page: PageEditorModel = new PageEditorModel(this.dataModel.pages.length);
|
|
|
|
this.dataModel.pages.push(page);
|
|
|
|
(<FormArray>this.form.get('pages')).push(page.buildForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
DeleteSection(index) {
|
|
|
|
this.dataModel.sections.splice(index, 1);
|
|
|
|
(<FormArray>this.form.get('sections')).removeAt(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
2019-02-15 11:26:14 +01:00
|
|
|
let data = this.form.value;
|
2019-01-18 18:03:45 +01:00
|
|
|
if (this.datasetProfileId) {
|
|
|
|
this.datasetProfileService.updateForm(this.datasetProfileId, data)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(() => {
|
|
|
|
this.router.navigate(['/dataset-profiles']);
|
|
|
|
});
|
2019-03-26 15:30:33 +01:00
|
|
|
} else if (this.newVersionId) {
|
2020-01-20 17:09:03 +01:00
|
|
|
data.label = this.form.get('label').value;
|
|
|
|
data.description = this.form.get('description').value;
|
2019-03-26 15:30:33 +01:00
|
|
|
this.datasetProfileService.newVersion(this.newVersionId, data)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(() => {
|
|
|
|
this.router.navigate(['/dataset-profiles']);
|
|
|
|
},
|
2019-10-15 12:38:51 +02:00
|
|
|
error => this.onCallbackErrorNewVersion(error)
|
2019-03-26 15:30:33 +01:00
|
|
|
);
|
2019-01-18 18:03:45 +01:00
|
|
|
} else {
|
2019-06-25 11:16:37 +02:00
|
|
|
this.form.get('status').setValue(DatasetStatus.Draft);
|
2019-02-15 11:26:14 +01:00
|
|
|
data = this.form.value;
|
2019-01-18 18:03:45 +01:00
|
|
|
this.datasetProfileService.createForm(data)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(() => {
|
|
|
|
this.router.navigate(['/dataset-profiles']);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-11 13:04:45 +01:00
|
|
|
finalize() {
|
|
|
|
//const data = this.form.value;
|
|
|
|
this.form.get('status').setValue(DatasetProfileEnum.FINALIZED);
|
|
|
|
|
|
|
|
this.onSubmit();
|
|
|
|
}
|
|
|
|
|
2019-11-22 16:06:47 +01:00
|
|
|
updateFinalized() {
|
|
|
|
this.datasetProfileService.updateForm(this.datasetProfileId, this.form.getRawValue())
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(() => {
|
|
|
|
this.router.navigate(['/dataset-profiles']);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
showUpdateButton() {
|
|
|
|
return !this.isNew && this.dataModel.status === DatasetProfileEnum.FINALIZED;
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
isStepActive(step: number) {
|
|
|
|
return this.stepper && this.stepper.selectedIndex === step;
|
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackSuccess(): void {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
|
|
|
this.router.navigate(['/master-items']);
|
|
|
|
}
|
|
|
|
|
2019-03-26 15:30:33 +01:00
|
|
|
onCallbackErrorNewVersion(errorResponse: HttpErrorResponse) {
|
|
|
|
this.uiNotificationService.snackBarNotification(errorResponse.error.message, SnackBarNotificationLevel.Error);
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
onCallbackError(errorResponse: HttpErrorResponse) {
|
|
|
|
// const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
|
|
|
|
// if (error.statusCode === 400) {
|
|
|
|
// this.masterItem.validationErrorModel.fromJSONObject(errorResponse.error);
|
|
|
|
// this.formService.validateAllFormFields(this.formGroup);
|
|
|
|
// } else {
|
|
|
|
this.uiNotificationService.snackBarNotification(errorResponse.message, SnackBarNotificationLevel.Warning);
|
|
|
|
// }
|
|
|
|
}
|
2019-02-06 12:10:44 +01:00
|
|
|
|
|
|
|
// DELETE Function
|
|
|
|
public delete(): void {
|
|
|
|
if (this.datasetProfileId && !this.isNew) {
|
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
2019-09-27 10:09:29 +02:00
|
|
|
restoreFocus: false,
|
2019-02-06 12:10:44 +01:00
|
|
|
data: {
|
|
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
|
|
|
|
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
|
2019-06-26 11:24:06 +02:00
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
|
|
|
isDeleteConfirmation: true
|
2019-02-06 12:10:44 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
2019-02-25 17:49:26 +01:00
|
|
|
//this.form.get('status').setValue(DatasetProfileEnum.DELETED);
|
2019-02-25 17:46:16 +01:00
|
|
|
this.datasetProfileService.delete(this.datasetProfileId, this.form.value)
|
2019-02-06 12:10:44 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2019-10-15 12:38:51 +02:00
|
|
|
complete => {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DATASET-PROFILE-DELETE'), SnackBarNotificationLevel.Success);
|
|
|
|
this.router.navigate(['/dataset-profiles']);
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.onCallbackError(error);
|
|
|
|
if (error.error.statusCode == 674) {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DATASET-PROFILE-DELETE'), SnackBarNotificationLevel.Error);
|
|
|
|
} else {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant(error.message), SnackBarNotificationLevel.Error);
|
|
|
|
}
|
2019-02-25 17:46:16 +01:00
|
|
|
}
|
2019-02-06 12:10:44 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-02-25 17:46:16 +01:00
|
|
|
|
|
|
|
downloadXML(): void {
|
|
|
|
this.datasetProfileService.downloadXML(this.datasetProfileId)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
|
|
|
const blob = new Blob([response.body], { type: 'application/xml' });
|
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
|
|
|
|
FileSaver.saveAs(blob, filename);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getFilenameFromContentDispositionHeader(header: string): string {
|
|
|
|
const regex: RegExp = new RegExp(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g);
|
|
|
|
|
|
|
|
const matches = header.match(regex);
|
|
|
|
let filename: string;
|
|
|
|
for (let i = 0; i < matches.length; i++) {
|
|
|
|
const match = matches[i];
|
|
|
|
if (match.includes('filename="')) {
|
|
|
|
filename = match.substring(10, match.length - 1);
|
|
|
|
break;
|
|
|
|
} else if (match.includes('filename=')) {
|
|
|
|
filename = match.substring(9);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filename;
|
|
|
|
}
|
2020-06-03 11:13:31 +02:00
|
|
|
|
|
|
|
getLanguageInfos(): LanguageInfo[] {
|
|
|
|
return this.languageInfoService.getLanguageInfoValues();
|
|
|
|
}
|
2020-09-22 10:27:10 +02:00
|
|
|
|
|
|
|
checkFormValidation() {
|
|
|
|
if (!this.form.valid) {
|
|
|
|
this.nestedIndex = -1;
|
|
|
|
this.form.markAllAsTouched();
|
|
|
|
this.printErrors(this.form);
|
|
|
|
this.showValidationErrorsDialog();
|
|
|
|
this.nestedCount = [];
|
|
|
|
this.nestedIndex = 0;
|
|
|
|
this.errorMessages = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printErrors(rootform: FormGroup) {
|
|
|
|
if (!rootform.valid) {
|
|
|
|
Object.keys(rootform.controls).forEach(key => {
|
|
|
|
const errors = rootform.get(key).errors;
|
|
|
|
if (errors !== null) {
|
|
|
|
let numbering: string = '';
|
|
|
|
for (let j = 0; j < this.nestedCount.length; j++) {
|
|
|
|
numbering += this.nestedCount[j];
|
|
|
|
if (j < this.nestedIndex) {
|
|
|
|
numbering += '.';
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Object.keys(errors).forEach(keyError => {
|
|
|
|
if (typeof errors[keyError] === 'boolean') {
|
|
|
|
this.errorMessages.push(numbering + ' ' + key + ' is ' + keyError);
|
|
|
|
} else {
|
2020-11-04 15:55:45 +01:00
|
|
|
this.errorMessages.push(numbering + ' ' + key + ': ' + keyError + ': ' + JSON.stringify(errors[keyError]));
|
2020-09-22 10:27:10 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (rootform.get(key) instanceof FormGroup) {
|
|
|
|
this.printErrors(<FormGroup>rootform.get(key));
|
|
|
|
} else if (rootform.get(key) instanceof FormArray) {
|
|
|
|
this.nestedIndex++;
|
|
|
|
this.nestedCount[this.nestedIndex] = 0;
|
|
|
|
for (let childForm of (<FormArray>rootform.get(key)).controls) {
|
|
|
|
this.nestedCount[this.nestedIndex]++;
|
|
|
|
this.printErrors(<any>childForm);
|
|
|
|
}
|
|
|
|
this.nestedCount[this.nestedIndex] = 0;
|
|
|
|
this.nestedIndex--;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private showValidationErrorsDialog(projectOnly?: boolean) {
|
|
|
|
const dialogRef = this.dialog.open(FormValidationErrorsDialogComponent, {
|
|
|
|
disableClose: true,
|
2020-09-25 13:03:04 +02:00
|
|
|
autoFocus: false,
|
|
|
|
restoreFocus: false,
|
2020-09-22 10:27:10 +02:00
|
|
|
data: {
|
|
|
|
errorMessages: this.errorMessages,
|
|
|
|
projectOnly: projectOnly
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2021-02-03 11:21:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
links: Link[] = [];
|
|
|
|
|
|
|
|
getLinks(currentLinks: Link[]) {
|
|
|
|
this.links = currentLinks;
|
|
|
|
}
|
|
|
|
|
|
|
|
linkToScroll: LinkToScroll;
|
|
|
|
onStepFound(linkToScroll: LinkToScroll) {
|
|
|
|
this.linkToScroll = linkToScroll;
|
|
|
|
}
|
|
|
|
|
|
|
|
datasetWizardModel: DatasetWizardEditorModel;
|
|
|
|
formGroup: FormGroup;
|
|
|
|
getPreview() {
|
|
|
|
let data = this.form.value;
|
|
|
|
this.datasetProfileService.preview(data).subscribe(x => {
|
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel({
|
|
|
|
datasetProfileDefinition: x
|
|
|
|
});
|
|
|
|
this.formGroup = <FormGroup>this.datasetWizardModel.buildForm().get('datasetProfileDefinition');
|
|
|
|
});
|
|
|
|
//this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
|
|
|
|
|
|
|
//this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
|
|
|
// if (this.datasetWizardModel.status === DatasetStatus.Finalized) {
|
|
|
|
// this.formGroup.disable();
|
|
|
|
// this.viewOnly = true;
|
|
|
|
// }
|
|
|
|
//if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP.
|
|
|
|
// this.registerFormListeners();
|
|
|
|
// this.dmpValueChanged(null);
|
|
|
|
// this.breadCrumbs = observableOf([
|
|
|
|
// {
|
|
|
|
// parentComponentName: null,
|
|
|
|
// label: this.language.instant('DATASET-LISTING.ACTIONS.CREATE-NEW').toUpperCase(),
|
|
|
|
// url: '/datasets/new/'
|
|
|
|
// }]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this.datasetWizardService.updateDatasetProfile(this.profileUpdateId)
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(data => {
|
|
|
|
// this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data);
|
|
|
|
// this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
|
|
|
|
|
|
|
// this.needsUpdate();
|
|
|
|
// this.breadCrumbs = observableOf([
|
|
|
|
// {
|
|
|
|
// parentComponentName: null,
|
|
|
|
// label: this.language.instant('NAV-BAR.MY-DATASET-DESCRIPTIONS'),
|
|
|
|
// url: '/datasets',
|
|
|
|
// notFoundResolver: [
|
|
|
|
// // {
|
|
|
|
// // parentComponentName: null,
|
|
|
|
// // label: this.datasetWizardModel.dmp.grant.label,
|
|
|
|
// // url: '/grants/edit/' + this.datasetWizardModel.dmp.grant.id
|
|
|
|
// // },
|
|
|
|
// {
|
|
|
|
// parentComponentName: null,
|
|
|
|
// label: this.datasetWizardModel.dmp.label,
|
|
|
|
// url: '/plans/edit/' + this.datasetWizardModel.dmp.id,
|
|
|
|
// },
|
|
|
|
// ]
|
|
|
|
// }]);
|
|
|
|
// this.formGroup = this.datasetWizardModel.buildForm();
|
|
|
|
// this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
|
|
|
// if (this.datasetWizardModel.status === DatasetStatus.Finalized) {
|
|
|
|
// this.formGroup.disable();
|
|
|
|
// this.viewOnly = true;
|
|
|
|
// }
|
|
|
|
// // if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP.
|
|
|
|
// this.loadDatasetProfiles();
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
|
|
|
|
getTocEntries(): ToCEntry[] {
|
|
|
|
if (this.form == null) { return []; }
|
|
|
|
const result: ToCEntry[] = [];
|
2021-02-12 12:23:39 +01:00
|
|
|
|
|
|
|
//build parent pages
|
2021-02-03 11:21:31 +01:00
|
|
|
(this.form.get('pages') as FormArray).controls.forEach((pageElement, i) => {
|
|
|
|
result.push({
|
|
|
|
id: pageElement.get('id').value,
|
2021-02-04 09:33:03 +01:00
|
|
|
label: pageElement.get('title').value,
|
2021-02-04 11:22:52 +01:00
|
|
|
type: ToCEntryType.Page,
|
2021-02-12 12:23:39 +01:00
|
|
|
form: pageElement,
|
|
|
|
numbering: (i + 1).toString(),
|
|
|
|
subEntriesType: ToCEntryType.Section
|
2021-02-03 11:21:31 +01:00
|
|
|
} as ToCEntry)
|
|
|
|
});
|
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
// build first level sections
|
2021-02-03 11:21:31 +01:00
|
|
|
(this.form.get('sections') as FormArray).controls.forEach((sectionElement, i) => {
|
|
|
|
const currentSectionPageId = sectionElement.get('page').value;
|
|
|
|
const pageToAdd = result.filter(x => x.id == currentSectionPageId)[0];
|
|
|
|
if (pageToAdd.subEntries == null) pageToAdd.subEntries = [];
|
|
|
|
|
2021-02-04 11:22:52 +01:00
|
|
|
const item = {
|
2021-02-03 11:21:31 +01:00
|
|
|
id: sectionElement.get('id').value,
|
2021-02-04 09:33:03 +01:00
|
|
|
label: sectionElement.get('title').value,
|
2021-02-04 11:22:52 +01:00
|
|
|
type: ToCEntryType.Section,
|
|
|
|
form: sectionElement,
|
2021-02-12 12:23:39 +01:00
|
|
|
numbering: pageToAdd.numbering + '.' + (pageToAdd.subEntries.length +1)
|
2021-02-04 11:22:52 +01:00
|
|
|
} as ToCEntry;
|
|
|
|
const sectionItems = this.populateSections(sectionElement.get('sections') as FormArray, item.numbering);
|
|
|
|
const fieldSetItems = this.populateFieldSets(sectionElement.get('fieldSets') as FormArray, item.numbering);
|
|
|
|
if (sectionItems != null) {
|
|
|
|
item.subEntries = sectionItems;
|
2021-02-12 12:23:39 +01:00
|
|
|
item.subEntriesType = ToCEntryType.Section;
|
2021-02-04 11:22:52 +01:00
|
|
|
}
|
|
|
|
if (fieldSetItems != null) {
|
|
|
|
if (item.subEntries == null) {
|
|
|
|
item.subEntries = fieldSetItems;
|
|
|
|
} else {
|
|
|
|
item.subEntries.push(...fieldSetItems);
|
|
|
|
}
|
2021-02-12 12:23:39 +01:00
|
|
|
item.subEntriesType = ToCEntryType.FieldSet;
|
|
|
|
|
2021-02-04 11:22:52 +01:00
|
|
|
}
|
|
|
|
pageToAdd.subEntries.push(item);
|
|
|
|
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private populateSections(sections: FormArray, existingNumbering: string): ToCEntry[] {
|
|
|
|
if (sections == null || sections.controls == null || sections.controls.length == 0) { return null; }
|
|
|
|
|
|
|
|
const result: ToCEntry[] = [];
|
|
|
|
sections.controls.forEach((sectionElement, i) => {
|
|
|
|
|
|
|
|
const item = {
|
|
|
|
id: sectionElement.get('id').value,
|
|
|
|
label: sectionElement.get('title').value,
|
|
|
|
type: ToCEntryType.Section,
|
|
|
|
form: sectionElement,
|
2021-02-12 12:23:39 +01:00
|
|
|
numbering: existingNumbering + '.' + (i + 1)
|
2021-02-04 11:22:52 +01:00
|
|
|
} as ToCEntry;
|
|
|
|
const sectionItems = this.populateSections(sectionElement.get('sections') as FormArray, item.numbering);
|
|
|
|
const fieldSetItems = this.populateFieldSets(sectionElement.get('fieldSets') as FormArray, item.numbering);
|
|
|
|
if (sectionItems != null) {
|
|
|
|
item.subEntries = sectionItems;
|
2021-02-12 12:23:39 +01:00
|
|
|
item.subEntriesType = ToCEntryType.Section;
|
2021-02-04 11:22:52 +01:00
|
|
|
}
|
|
|
|
if (fieldSetItems != null) {
|
|
|
|
if (item.subEntries == null) {
|
|
|
|
item.subEntries = fieldSetItems;
|
|
|
|
} else {
|
|
|
|
item.subEntries.push(...fieldSetItems);
|
|
|
|
}
|
2021-02-12 12:23:39 +01:00
|
|
|
item.subEntriesType = ToCEntryType.FieldSet;
|
2021-02-04 11:22:52 +01:00
|
|
|
}
|
|
|
|
result.push(item);
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private populateFieldSets(fieldSets: FormArray, existingNumbering: string): ToCEntry[] {
|
|
|
|
if (fieldSets == null || fieldSets.controls == null || fieldSets.controls.length == 0) { return null; }
|
|
|
|
|
|
|
|
const result: ToCEntry[] = [];
|
|
|
|
fieldSets.controls.forEach((fieldSetElement, i) => {
|
|
|
|
|
|
|
|
result.push({
|
|
|
|
id: fieldSetElement.get('id').value,
|
|
|
|
label: fieldSetElement.get('title').value,
|
|
|
|
type: ToCEntryType.FieldSet,
|
2021-02-12 12:23:39 +01:00
|
|
|
//subEntries: this.populateSections((fieldSetElement.get('fieldSets') as FormArray), existingNumbering + '.' + i),
|
2021-02-04 11:22:52 +01:00
|
|
|
form: fieldSetElement,
|
2021-02-12 12:23:39 +01:00
|
|
|
numbering: existingNumbering + '.' + (i + 1)
|
2021-02-03 11:21:31 +01:00
|
|
|
} as ToCEntry)
|
2021-02-04 11:22:52 +01:00
|
|
|
|
2021-02-03 11:21:31 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
private _findTocEntryById(id: string, tocentries: ToCEntry[]): ToCEntry{
|
|
|
|
if(!tocentries){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let tocEntryFound = tocentries.find(entry=>entry.id === id);
|
|
|
|
|
|
|
|
if(tocEntryFound){
|
|
|
|
return tocEntryFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(let entry of tocentries){
|
|
|
|
const result = this._findTocEntryById(id, entry.subEntries);
|
|
|
|
if(result){
|
|
|
|
tocEntryFound = result;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tocEntryFound) return tocEntryFound;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2021-02-12 12:23:39 +01:00
|
|
|
addNewEntry(tce: Foo) {
|
|
|
|
|
|
|
|
const parent = tce.parent;
|
|
|
|
|
|
|
|
//define entry type
|
|
|
|
switch (tce.childType) {
|
|
|
|
case ToCEntryType.Page: //CALLED FROM PAGE
|
|
|
|
//create section
|
|
|
|
// this.addPage();
|
|
|
|
// this.displayItem(child);
|
|
|
|
|
|
|
|
|
|
|
|
//ceate page editor model and give ordinal
|
|
|
|
const page: PageEditorModel = new PageEditorModel(this.dataModel.pages.length);
|
|
|
|
this.dataModel.pages.push(page);
|
|
|
|
(<FormArray>this.form.get('pages')).push(page.buildForm());
|
|
|
|
|
|
|
|
|
|
|
|
//make new entry selected
|
|
|
|
const pagesArray = (this.form.get('pages') as FormArray);
|
|
|
|
const addedEntry = pagesArray.at(pagesArray.length-1) as FormGroup;
|
2021-02-15 18:16:48 +01:00
|
|
|
|
|
|
|
this.selectedTocEntry = this._findTocEntryById(addedEntry.get('id').value, this.getTocEntries());
|
2021-02-12 12:23:39 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
case ToCEntryType.Section: //adding a section
|
|
|
|
const section: SectionEditorModel = new SectionEditorModel();
|
|
|
|
//give id
|
|
|
|
section.id = Guid.create().toString();
|
|
|
|
let sectionsArray:FormArray;
|
|
|
|
|
|
|
|
if (parent.type === ToCEntryType.Page) {
|
|
|
|
//FIRST LEVEL SECTION
|
|
|
|
|
|
|
|
//give ordinal and link to parent
|
|
|
|
section.page = parent.id;
|
|
|
|
section.ordinal = (this.form.get('sections') as FormArray).length;
|
|
|
|
(<FormArray>this.form.get('sections')).push(section.buildForm());
|
|
|
|
|
|
|
|
sectionsArray = this.form.get('sections') as FormArray;
|
|
|
|
} else if( parent.type == ToCEntryType.Section) { //subsection
|
|
|
|
|
|
|
|
//adding page parent MAYBE NOT NEEDED
|
|
|
|
section.page = parent.form.get('page').value;
|
|
|
|
//MAYBE NOT NEEDED
|
|
|
|
section.ordinal = (parent.form.get('sections') as FormArray).length;
|
|
|
|
(<FormArray>parent.form.get('sections')).push(section.buildForm());
|
|
|
|
// (child.form.parent as FormArray).push(section.buildForm());
|
|
|
|
|
|
|
|
sectionsArray = parent.form.get('sections') as FormArray;
|
|
|
|
}else{
|
|
|
|
console.error('BUg found');
|
|
|
|
}
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
|
|
|
|
const sectionAdded = sectionsArray.at(sectionsArray.length -1) as FormGroup;
|
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
this.selectedTocEntry = this._findTocEntryById(sectionAdded.get('id').value, this.getTocEntries());
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
break;
|
|
|
|
case ToCEntryType.FieldSet:
|
|
|
|
const fieldSet: FieldSetEditorModel = new FieldSetEditorModel();
|
|
|
|
|
|
|
|
//create one field form fieldset
|
|
|
|
const field: FieldEditorModel = new FieldEditorModel(); //to ask
|
|
|
|
field.id = Guid.create().toString();
|
|
|
|
field.ordinal = fieldSet.fields.length;
|
|
|
|
fieldSet.fields.push(field);
|
|
|
|
|
|
|
|
//give fieldset id and ordinal
|
|
|
|
fieldSet.id = Guid.create().toString();
|
|
|
|
fieldSet.ordinal = (parent.form.get('fieldSets') as FormArray).length;
|
|
|
|
|
|
|
|
(<FormArray>parent.form.get('fieldSets')).push(fieldSet.buildForm());
|
|
|
|
|
|
|
|
const parentArray = parent.form.get('fieldSets') as FormArray;
|
|
|
|
const addedFieldSet = parentArray.at(parentArray.length - 1);
|
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
this.selectedTocEntry = this._findTocEntryById(addedFieldSet.get('id').value, this.getTocEntries());
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
break;
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
}
|
2021-02-04 09:33:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-02-12 15:27:35 +01:00
|
|
|
onRemoveEntry(tce: ToCEntry){
|
|
|
|
|
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
|
|
|
|
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
|
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
|
|
|
isDeleteConfirmation: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
|
|
|
this._deleteEntry(tce);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2021-02-04 09:33:03 +01:00
|
|
|
|
|
|
|
|
2021-02-12 15:27:35 +01:00
|
|
|
private _deleteEntry(tce: ToCEntry) {
|
2021-02-12 12:23:39 +01:00
|
|
|
//define entry type
|
|
|
|
switch (tce.type) {
|
|
|
|
case ToCEntryType.Page:
|
|
|
|
const pages = this.form.get('pages') as FormArray;
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
let pageIndex = -1;
|
|
|
|
//get the index
|
|
|
|
for (let i = 0; i < pages.length; i++) {
|
|
|
|
let page = pages.at(i) as FormGroup;
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
if (page.controls.id.value === tce.id) {
|
|
|
|
pageIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
if (pageIndex >= 0) {
|
|
|
|
//remove page
|
|
|
|
pages.removeAt(pageIndex);
|
|
|
|
//clean up sections of removed page
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
const sections = (this.form.get('sections') as FormArray).controls;
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
const updatedSections = new FormArray([]);
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
for (let i = 0; i < sections.length; i++) {
|
|
|
|
let section = sections[i];
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
if (section.get('page').value != tce.id) {
|
|
|
|
updatedSections.push(section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//replace sections value
|
|
|
|
this.form.controls.sections = updatedSections;
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
//update page orders
|
|
|
|
for(let i=0; i<pages.length; i++){
|
|
|
|
pages.at(i).get('ordinal').patchValue(i);
|
|
|
|
}
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
//update validity
|
|
|
|
this.form.controls.sections.updateValueAndValidity();
|
|
|
|
}
|
|
|
|
break;
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
case ToCEntryType.Section:
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
//FIRST LEVEL SECTION CASE
|
|
|
|
let index = -1;
|
2021-02-04 09:33:03 +01:00
|
|
|
|
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
const sections = (this.form.get('sections') as FormArray);
|
2021-02-04 11:22:52 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
for (let i = 0; i < sections.length; i++) {
|
2021-02-04 11:22:52 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
let section = sections.at(i);
|
2021-02-04 11:22:52 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
let sectionId = section.get('id').value;
|
|
|
|
if (sectionId == tce.id) {
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-02-04 11:22:52 +01:00
|
|
|
|
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
if (index >= 0) { //section found
|
2021-02-04 11:22:52 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
const sections = (this.form.get('sections') as FormArray);
|
2021-02-04 11:22:52 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
//remove section
|
|
|
|
sections.removeAt(index);
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
//update ordinal
|
|
|
|
for(let i=0; i< sections.length; i++){
|
|
|
|
sections.at(i).get('ordinal').patchValue(i);
|
|
|
|
}
|
|
|
|
} else {//NOT FOUND IN FIRST LEVEL CASE
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
//LOOK FOR SUBSECTION CASE
|
|
|
|
let parentFormArray = tce.form.parent as FormArray;
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
for (let i = 0; i < parentFormArray.length; i++) {
|
|
|
|
let section = parentFormArray.at(i);
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
if (section.get('id').value == tce.id) {
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (index >= 0) {
|
|
|
|
parentFormArray.removeAt(index);
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
//update odrinal
|
|
|
|
|
|
|
|
for(let i=0; i<parentFormArray.length; i++){
|
|
|
|
parentFormArray.at(i).get('ordinal').patchValue(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case ToCEntryType.FieldSet:
|
|
|
|
const parentFormArray = tce.form.parent as FormArray;
|
|
|
|
|
|
|
|
|
|
|
|
let idx = -1;
|
|
|
|
|
|
|
|
for(let i =0; i< parentFormArray.length; i++){
|
|
|
|
let inspectingField = parentFormArray.at(i);
|
|
|
|
|
|
|
|
if(inspectingField.get('id').value === tce.id){
|
|
|
|
//fieldset found
|
|
|
|
idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(idx>=0){//fieldset found
|
|
|
|
parentFormArray.removeAt(idx);
|
|
|
|
|
|
|
|
//patching order
|
|
|
|
for(let i=0; i<parentFormArray.length;i++){
|
|
|
|
parentFormArray.at(i).get('ordinal').patchValue(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//in case selectedtocentrhy is child of the removed element
|
|
|
|
if(this.selectedTocEntry ){
|
|
|
|
|
|
|
|
if(this.tocEntryIsChildOf(this.selectedTocEntry,tce)){
|
2021-02-17 17:39:07 +01:00
|
|
|
if(this.selectedTocEntry.type == ToCEntryType.Page){
|
|
|
|
this.selectedTocEntry = null;
|
|
|
|
}else{
|
|
|
|
const parentId = tce.form.parent.parent.get('id').value;
|
|
|
|
if(parentId){
|
|
|
|
const tocentries = this.getTocEntries();
|
|
|
|
const parent = this._findTocEntryById(parentId, tocentries);
|
|
|
|
|
|
|
|
if(parent){
|
|
|
|
this.selectedTocEntry = parent;
|
|
|
|
}else{
|
|
|
|
this.selectedTocEntry = null;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
this.selectedTocEntry = null;
|
|
|
|
}
|
|
|
|
}
|
2021-02-12 12:23:39 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-04 09:33:03 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
tocEntryIsChildOf(testingChild: ToCEntry,parent: ToCEntry): boolean{
|
|
|
|
|
|
|
|
if(!testingChild || !parent) return false;
|
|
|
|
|
|
|
|
if(testingChild.id == parent.id){return true;}
|
|
|
|
|
|
|
|
if(parent.subEntries){
|
|
|
|
let childFound:boolean = false;
|
|
|
|
|
|
|
|
parent.subEntries.forEach(subEntry=>{
|
|
|
|
if(this.tocEntryIsChildOf(testingChild, subEntry)){
|
|
|
|
childFound = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return childFound;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
selectedTocEntry: ToCEntry
|
|
|
|
displayItem(entry: ToCEntry): void {
|
|
|
|
this.selectedTocEntry = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
get numOfPages(){
|
|
|
|
return (<FormArray>this.form.get('pages')).length;
|
|
|
|
}
|
|
|
|
|
2021-02-04 09:33:03 +01:00
|
|
|
// getSectionIndex(): number{
|
|
|
|
// // if(this.sectionIdPreviewed == null) return;
|
|
|
|
// const valuesArray = this.form.get('sections').value;
|
|
|
|
// let currentVal = this.sectionIdPreviewed;
|
|
|
|
// let indexArray:string[] = valuesArray.map(element=> element.page);
|
|
|
|
// let index = indexArray.indexOf(currentVal);
|
|
|
|
// console.log(index);
|
|
|
|
// return index ? index :-1;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// getCurrentEditorModel(): SectionEditorModel{
|
|
|
|
// let currentEditor = this.dataModel.sections.filter(section=> section.page == this.sectionIdPreviewed)[0];
|
|
|
|
// return currentEditor;
|
2021-02-04 11:22:52 +01:00
|
|
|
|
2021-02-04 09:33:03 +01:00
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// subForm(){
|
|
|
|
// const valuesArray = this.form.get('sections').value;
|
|
|
|
// let currentVal = this.sectionIdPreviewed;
|
|
|
|
// let indexArray:string[] = valuesArray.map(element=> element.page);
|
|
|
|
// let index = indexArray.indexOf(currentVal);
|
|
|
|
// let subForm = (this.form.get('sections') as FormArray).controls[index];
|
|
|
|
// console.log(subForm);
|
|
|
|
// return subForm;
|
|
|
|
// }
|
|
|
|
|
2021-02-04 11:22:52 +01:00
|
|
|
getFieldTile(formGroup: FormGroup, index: number) {
|
|
|
|
if (formGroup.get('title') && formGroup.get('title').value && formGroup.get('title').value.length > 0) { return formGroup.get('title').value; }
|
|
|
|
return "Field " + (index + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteFieldSet(formArray: FormArray, index: number) {
|
|
|
|
formArray.removeAt(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
|
|
|
|
printForm(){
|
|
|
|
console.log(this.form.value);
|
|
|
|
}
|
|
|
|
|
2021-02-12 15:27:35 +01:00
|
|
|
get barPercentage(){
|
2021-02-12 12:23:39 +01:00
|
|
|
if(!this.stepper){
|
|
|
|
return -110;
|
|
|
|
}
|
|
|
|
const selectedIndex = this.stepper.selectedIndex + 1;
|
2021-02-12 15:27:35 +01:00
|
|
|
return (selectedIndex / this.stepper.steps.length) * 110- 110;
|
2021-02-12 12:23:39 +01:00
|
|
|
}
|
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
|
|
|
|
get progressStyle(){
|
|
|
|
return {'transform': 'translateX('+this.barPercentage+'%) skewX(-25deg)'}
|
|
|
|
}
|
|
|
|
|
2021-02-12 15:27:35 +01:00
|
|
|
get steps(){
|
|
|
|
if(!this.stepper){
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.stepper.steps;
|
|
|
|
}
|
2021-02-15 18:16:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
generatePreviewForm(){
|
|
|
|
|
|
|
|
|
|
|
|
const model = new DatasetDescriptionFormEditorModel();
|
|
|
|
|
|
|
|
const toCentries = this.getTocEntries();
|
|
|
|
|
|
|
|
|
|
|
|
//first level is always pages
|
|
|
|
model.pages = toCentries.map(entry=>{
|
|
|
|
if( !(entry.type == ToCEntryType.Page)){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const pageModel = new DatasetDescriptionPageEditorModel();
|
|
|
|
|
|
|
|
pageModel.ordinal = entry.form.get('ordinal').value;
|
|
|
|
pageModel.title = entry.label;
|
|
|
|
|
|
|
|
if(entry.subEntries){
|
|
|
|
pageModel.sections = entry.subEntries.map(section=>{
|
|
|
|
const sectionModel = new DatasetDescriptionSectionEditorModel();
|
|
|
|
|
|
|
|
sectionModel.id = section.id;
|
|
|
|
sectionModel.ordinal = section.form.get('ordinal').value;
|
|
|
|
sectionModel.description = section.form.get('description').value;
|
|
|
|
sectionModel.page = entry.form.get('ordinal').value;
|
|
|
|
sectionModel.title = section.label;
|
|
|
|
sectionModel.numbering = section.numbering;
|
|
|
|
|
|
|
|
|
|
|
|
if(section.subEntriesType == ToCEntryType.Section){
|
|
|
|
sectionModel.sections = this._buildSectionsRecursively(section.subEntries);
|
|
|
|
}else{
|
|
|
|
sectionModel.compositeFields = this._buildFormFields(section.subEntries)
|
|
|
|
}
|
|
|
|
|
|
|
|
return sectionModel;
|
|
|
|
})
|
|
|
|
};
|
|
|
|
return pageModel;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2021-02-17 17:39:07 +01:00
|
|
|
|
|
|
|
//populate rules
|
|
|
|
const rules:Rule[] =[];
|
|
|
|
const fieldSets = this._getFieldSets(toCentries);
|
|
|
|
|
|
|
|
fieldSets.forEach(fs=>{
|
|
|
|
const fields = fs.form.get('fields') as FormArray;
|
|
|
|
if(fields){
|
|
|
|
fields.controls.forEach(field=>{
|
|
|
|
const rulesArray = field.get('visible').get('rules').value;
|
|
|
|
if(rulesArray){
|
|
|
|
rulesArray.forEach(ruleElement => {
|
|
|
|
const rule: Rule = new Rule();
|
|
|
|
rule.targetField = ruleElement.target;
|
|
|
|
rule.sourceField = field.get('id').value;
|
|
|
|
rule.requiredValue = ruleElement.value;
|
|
|
|
rules.push(rule);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
model.rules = rules;
|
|
|
|
this.visibilityRules = rules;
|
2021-02-15 18:16:48 +01:00
|
|
|
|
|
|
|
this.previewForm = model.buildForm();
|
|
|
|
}
|
|
|
|
|
2021-02-17 17:39:07 +01:00
|
|
|
visibilityRules:Rule[];
|
2021-02-15 18:16:48 +01:00
|
|
|
private _buildSectionsRecursively( tocentries: ToCEntry[]): DatasetDescriptionSectionEditorModel[]{
|
|
|
|
|
|
|
|
|
|
|
|
if(!tocentries) return null;
|
|
|
|
|
|
|
|
|
|
|
|
const result: Array<DatasetDescriptionSectionEditorModel> = [];
|
|
|
|
|
|
|
|
tocentries.forEach(tocentry=>{
|
|
|
|
|
|
|
|
const sectionModel = new DatasetDescriptionSectionEditorModel();
|
|
|
|
sectionModel.id = tocentry.id;
|
|
|
|
sectionModel.ordinal = tocentry.form.get('ordinal').value;
|
|
|
|
sectionModel.description = tocentry.form.get('description').value;
|
|
|
|
// sectionModel.page = entry.form.get('ordinal').value;
|
|
|
|
sectionModel.title = tocentry.label;
|
|
|
|
sectionModel.numbering = tocentry.numbering;
|
|
|
|
|
|
|
|
if(tocentry.subEntriesType == ToCEntryType.Section){
|
|
|
|
sectionModel.sections = this._buildSectionsRecursively(tocentry.subEntries);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
sectionModel.compositeFields = this._buildFormFields(tocentry.subEntries);
|
|
|
|
}
|
|
|
|
|
|
|
|
result.push(sectionModel);
|
|
|
|
})
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private _buildFormFields(tocentries: ToCEntry[]):DatasetDescriptionCompositeFieldEditorModel[]{
|
|
|
|
if(!tocentries) return null;
|
|
|
|
|
|
|
|
const fieldsets:DatasetDescriptionCompositeFieldEditorModel[] = [];
|
|
|
|
|
|
|
|
tocentries.forEach(fs=>{
|
|
|
|
|
|
|
|
const fieldset = new DatasetDescriptionCompositeFieldEditorModel();
|
|
|
|
|
|
|
|
fieldset.description = fs.form.get('description').value;
|
|
|
|
fieldset.extendedDescription = fs.form.get('extendedDescription').value;
|
|
|
|
fieldset.id = fs.form.get('id').value;
|
|
|
|
fieldset.multiplicity = fs.form.get('multiplicity').value;
|
|
|
|
fieldset.additionalInformation = fs.form.get('additionalInformation').value;
|
|
|
|
fieldset.ordinal = fs.form.get('ordinal').value;
|
2021-02-17 17:39:07 +01:00
|
|
|
fieldset.numbering = fs.numbering;
|
2021-02-15 18:16:48 +01:00
|
|
|
fieldset.hasCommentField = fs.form.get('hasCommentField').value;
|
|
|
|
fieldset.title = fs.label;
|
|
|
|
// fieldset.fields = (fs.form.get('fields') as FormArray).getRawValue();
|
|
|
|
fieldset.fields = (fs.form.get('fields') as FormArray).controls.map(field=>{
|
|
|
|
|
|
|
|
const fieldModel = new DatasetDescriptionFieldEditorModel();
|
|
|
|
|
|
|
|
fieldModel.data = (field.get('data') as FormGroup).getRawValue();
|
|
|
|
fieldModel.id = field.get('id').value;
|
|
|
|
fieldModel.viewStyle = (field.get('viewStyle') as FormGroup).getRawValue();
|
2021-02-17 17:39:07 +01:00
|
|
|
// fieldModel.defaultValue = (field.get('defaultValue') as FormGroup).getRawValue();
|
|
|
|
fieldModel.value = (field.get('defaultValue') as FormGroup).get('value').value;
|
2021-02-15 18:16:48 +01:00
|
|
|
fieldModel.page = field.get('page').value;
|
|
|
|
fieldModel.validations = field.get('validations').value;
|
|
|
|
|
|
|
|
return fieldModel;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fieldsets.push(fieldset);
|
|
|
|
});
|
|
|
|
|
|
|
|
return fieldsets;
|
|
|
|
}
|
|
|
|
|
2021-02-17 17:39:07 +01:00
|
|
|
private _getFieldSets(tocentries: ToCEntry[]):ToCEntry[]{
|
|
|
|
|
|
|
|
const fieldsets:ToCEntry[] = [];
|
|
|
|
|
|
|
|
if(!tocentries) return fieldsets;
|
|
|
|
|
|
|
|
tocentries.forEach(entry=>{
|
|
|
|
if(entry.type == ToCEntryType.FieldSet){
|
|
|
|
fieldsets.push(entry);
|
|
|
|
}else{
|
|
|
|
fieldsets.push(...this._getFieldSets(entry.subEntries));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return fieldsets;
|
|
|
|
}
|
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
onMatStepperSelectionChange(event: StepperSelectionEvent){
|
|
|
|
|
|
|
|
if(event.selectedIndex === 2){//preview selected
|
|
|
|
this.generatePreviewForm();//TODO LAZY LOADING IN THE TEMPLATE
|
2021-02-17 17:39:07 +01:00
|
|
|
}else{
|
|
|
|
this.previewForm = null;
|
2021-02-15 18:16:48 +01:00
|
|
|
}
|
|
|
|
|
2021-02-17 17:39:07 +01:00
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
previewForm:FormGroup;
|
2021-02-03 11:21:31 +01:00
|
|
|
}
|