2019-09-23 10:17:03 +02:00
|
|
|
|
2021-04-13 15:27:29 +02:00
|
|
|
import { of as observableOf, Observable, combineLatest, BehaviorSubject,of } from 'rxjs';
|
2020-12-14 18:28:13 +01:00
|
|
|
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
2021-06-14 00:46:29 +02:00
|
|
|
import { Component, OnInit, QueryList, ViewChild } from '@angular/core';
|
|
|
|
import { AbstractControl, FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
|
2019-09-23 10:17:03 +02:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
2021-06-14 00:46:29 +02:00
|
|
|
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';
|
2021-06-14 00:46:29 +02:00
|
|
|
import { debounceTime, filter, map, mergeMap, takeUntil, tap } 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 { DatasetWizardService } from '@app/core/services/dataset-wizard/dataset-wizard.service';
|
|
|
|
import { DatasetWizardEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model';
|
2021-03-31 17:31:57 +02:00
|
|
|
import { NewEntryType, 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';
|
2021-02-17 18:44:50 +01:00
|
|
|
import { CdkStep, StepperSelectionEvent } from '@angular/cdk/stepper';
|
2021-06-14 00:46:29 +02:00
|
|
|
import { DatasetDescriptionCompositeFieldEditorModel, DatasetDescriptionFieldEditorModel, 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';
|
2021-03-01 10:28:27 +01:00
|
|
|
import { DatasetProfileFieldViewStyle } from '@app/core/common/enum/dataset-profile-field-view-style';
|
2021-03-05 10:05:09 +01:00
|
|
|
import { SideNavService } from '@app/core/services/sidenav/side-nav.sevice';
|
2021-03-12 17:19:51 +01:00
|
|
|
import { EditorCustomValidators, EditorCustomValidatorsEnum } from './custom-validators/editor-custom-validators';
|
2021-04-09 16:05:01 +02:00
|
|
|
import { GENERAL_ANIMATIONS, STEPPER_ANIMATIONS } from './animations/animations';
|
2021-03-27 18:52:53 +01:00
|
|
|
import { DatasetProfileComboBoxType } from '@app/core/common/enum/dataset-profile-combo-box-type';
|
2021-04-07 18:03:22 +02:00
|
|
|
import { UserService } from '@app/core/services/user/user.service';
|
2021-04-09 16:05:01 +02:00
|
|
|
import { MatInput } from '@angular/material';
|
2021-07-23 16:03:29 +02:00
|
|
|
import { CheckDeactivateBaseComponent } from '@app/library/deactivate/deactivate.component';
|
2021-03-23 11:39:04 +01:00
|
|
|
|
|
|
|
|
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',
|
2021-03-08 10:24:30 +01:00
|
|
|
styleUrls: ['./dataset-profile-editor.component.scss'],
|
2021-04-09 16:05:01 +02:00
|
|
|
animations:[...STEPPER_ANIMATIONS, ...GENERAL_ANIMATIONS],
|
2021-04-05 11:06:14 +02:00
|
|
|
providers:[VisibilityRulesService]
|
2019-01-18 18:03:45 +01:00
|
|
|
})
|
2021-07-23 16:03:29 +02:00
|
|
|
export class DatasetProfileEditorComponent extends CheckDeactivateBaseComponent implements OnInit {
|
|
|
|
canDeactivate(): boolean {
|
|
|
|
return !this.form.dirty;
|
|
|
|
}
|
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;
|
2021-04-07 18:03:22 +02:00
|
|
|
public userChipList:any[] = [];
|
|
|
|
displayedColumns: String[] = ['name', 'email', 'button'];
|
2019-02-06 12:10:44 +01:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
colorizeInvalid:boolean = false;
|
2021-04-09 16:05:01 +02:00
|
|
|
inputUserState: 'untriggered'| 'triggered' = 'untriggered';
|
|
|
|
private _inputUserField$:BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
|
|
|
private _inputUserButton$:BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
2021-04-13 15:27:29 +02:00
|
|
|
showScrollOnTopButton:boolean = false;
|
2021-03-12 17:19:51 +01:00
|
|
|
|
2021-04-13 15:27:29 +02:00
|
|
|
private stepperNavigationObserver: IntersectionObserver;
|
2021-03-08 10:24:30 +01:00
|
|
|
|
2021-03-27 18:52:53 +01:00
|
|
|
// customEditorValidators = new EditorCustomValidators();
|
2021-03-08 10:24:30 +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,
|
2021-02-24 15:56:14 +01:00
|
|
|
private visibilityRulesService: VisibilityRulesService,
|
2021-03-05 10:05:09 +01:00
|
|
|
private fb: FormBuilder,
|
2021-04-07 18:03:22 +02:00
|
|
|
private sidenavService: SideNavService,
|
|
|
|
private userService: UserService
|
2019-01-18 18:03:45 +01:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
// this.profileID = route.snapshot.params['id'];
|
|
|
|
// this.cloneId = route.snapshot.params['cloneid'];
|
|
|
|
}
|
|
|
|
|
2021-03-05 10:05:09 +01:00
|
|
|
ngOnDestroy(){
|
|
|
|
this.sidenavService.setStatus(true);
|
2021-04-13 15:27:29 +02:00
|
|
|
if(this.stepperNavigationObserver){
|
|
|
|
this.stepperNavigationObserver.disconnect();
|
|
|
|
this.stepperNavigationObserver = null;
|
|
|
|
}
|
2021-03-05 10:05:09 +01:00
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
ngOnInit() {
|
2021-03-05 10:05:09 +01:00
|
|
|
this.sidenavService.setStatus(false);
|
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)
|
2021-04-27 09:38:20 +02:00
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.HAS-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();
|
2021-04-27 09:38:20 +02:00
|
|
|
} catch (error){
|
2019-10-15 12:38:51 +02:00
|
|
|
this.logger.error('Could not parse MasterItem: ' + data);
|
2021-04-27 09:38:20 +02:00
|
|
|
this.logger.error(error);
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.HAS-ERROR'), SnackBarNotificationLevel.Error);
|
2019-10-15 12:38:51 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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();
|
2021-04-27 09:38:20 +02:00
|
|
|
} catch (error){
|
2019-10-15 12:38:51 +02:00
|
|
|
this.logger.error('Could not parse MasterItem: ' + data);
|
2021-04-27 09:38:20 +02:00
|
|
|
this.logger.error(error);
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.HAS-ERROR'), SnackBarNotificationLevel.Error);
|
2019-10-15 12:38:51 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
error => this.onCallbackError(error)
|
2019-01-18 18:03:45 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.dataModel = new DatasetProfileEditorModel();
|
|
|
|
this.form = this.dataModel.buildForm();
|
2021-03-27 18:52:53 +01:00
|
|
|
// this.form.setValidators([EditorCustomValidators.atLeastOneElementListValidator('pages'), EditorCustomValidators.pagesHaveAtLeastOneSection('pages', 'sections')]);
|
2021-04-07 18:03:22 +02:00
|
|
|
|
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();
|
2021-04-05 11:06:14 +02:00
|
|
|
this.visibilityRulesService.buildVisibilityRules([],this.form);
|
2021-02-18 16:13:56 +01:00
|
|
|
setTimeout(() => {
|
2021-04-07 18:03:22 +02:00
|
|
|
this.steps = this.stepper.steps;
|
2021-02-18 16:13:56 +01:00
|
|
|
});
|
2021-04-07 18:03:22 +02:00
|
|
|
this._initializeToCEntries();
|
2021-03-24 10:40:48 +01:00
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
});
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-17 18:44:50 +01:00
|
|
|
|
2021-04-09 16:05:01 +02:00
|
|
|
combineLatest(this._inputUserButton$.asObservable(),this._inputUserField$.asObservable())
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.pipe(debounceTime(400))
|
|
|
|
.pipe(filter(_=> !_[0] && !_[1]))
|
|
|
|
.subscribe(_=>{
|
|
|
|
// if(!this.userFormDisabled)
|
|
|
|
this.inputUserState = 'untriggered';
|
|
|
|
});
|
2021-03-24 10:40:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private _initializeToCEntries(){
|
|
|
|
const tocentries = this.refreshToCEntries();//tocentries are sorted based on their ordinal value
|
|
|
|
|
|
|
|
this._updateOrdinals(tocentries);
|
|
|
|
|
|
|
|
if(tocentries && tocentries.length){
|
|
|
|
this.selectedTocEntry = tocentries[0];
|
|
|
|
}
|
2021-04-13 15:27:29 +02:00
|
|
|
setTimeout(() => {
|
2021-04-14 08:57:30 +02:00
|
|
|
// const stepperNavigation = document.getElementById('stepper-navigation');
|
|
|
|
const titleColumn = document.getElementById('title-column');
|
|
|
|
// const stepperNavigationWrapper = document.getElementById('stepper-navigation-wrapper');
|
|
|
|
|
|
|
|
if(titleColumn){
|
2021-04-13 15:27:29 +02:00
|
|
|
if(this.stepperNavigationObserver){
|
|
|
|
this.stepperNavigationObserver.disconnect();
|
|
|
|
this.stepperNavigationObserver = null;
|
|
|
|
}
|
|
|
|
this.stepperNavigationObserver = new IntersectionObserver((e)=>{
|
|
|
|
e.forEach(_=>{
|
|
|
|
if(_.isIntersecting){
|
|
|
|
this.showScrollOnTopButton = false;
|
2021-04-14 08:57:30 +02:00
|
|
|
// stepperNavigation.classList.remove('fixed-navigation');
|
|
|
|
// stepperNavigationWrapper.classList.remove('fixed-navigation');
|
2021-04-13 15:27:29 +02:00
|
|
|
}else{
|
|
|
|
this.showScrollOnTopButton = true;
|
2021-04-14 08:57:30 +02:00
|
|
|
// stepperNavigation.classList.add('fixed-navigation');
|
|
|
|
// stepperNavigationWrapper.classList.add('fixed-navigation');
|
2021-04-13 15:27:29 +02:00
|
|
|
}
|
|
|
|
})
|
2021-04-14 08:57:30 +02:00
|
|
|
}, {root:null, rootMargin:'0px', threshold:0});
|
2021-04-27 09:38:20 +02:00
|
|
|
this.stepperNavigationObserver.observe(titleColumn);
|
2021-04-13 15:27:29 +02:00
|
|
|
}else{
|
|
|
|
console.log('Could not load scroll On Top Observer')
|
|
|
|
}
|
|
|
|
}, 400);
|
2021-03-27 18:52:53 +01:00
|
|
|
// this._initializeFormValidity(tocentries);
|
2021-03-24 10:40:48 +01:00
|
|
|
|
2021-05-05 14:50:20 +02:00
|
|
|
//Checking invalid visibilty RULES
|
|
|
|
const fieldsetEntries = this._getAllFieldSets(this.toCEntries);
|
|
|
|
const fieldSetHavingInvalidVisibilityRules:ToCEntry[] = fieldsetEntries
|
|
|
|
.filter(entry=>{
|
|
|
|
const fieldsFormGroup = entry.form.get('fields');
|
|
|
|
const invalid = (fieldsFormGroup as FormArray).controls.filter(field=>{
|
|
|
|
return this.hasInvalidVisibilityRule(field as FormGroup);
|
|
|
|
|
|
|
|
});
|
|
|
|
if(invalid && invalid.length){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if(fieldSetHavingInvalidVisibilityRules.length){
|
|
|
|
const occurences = fieldSetHavingInvalidVisibilityRules.map(record=>record.numbering).join(' , ');
|
|
|
|
this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
data:{
|
|
|
|
message: this.language.instant('DATASET-PROFILE-EDITOR.ERRORS.INVALID-VISIBILITY-RULES.MESSAGE-START')+occurences+ this.language.instant('DATASET-PROFILE-EDITOR.ERRORS.INVALID-VISIBILITY-RULES.MESSAGE-END'),
|
|
|
|
confirmButton: this.language.instant('DATASET-PROFILE-EDITOR.ERRORS.INVALID-VISIBILITY-RULES.CONFIRM-YES'),
|
|
|
|
cancelButton: this.language.instant('DATASET-PROFILE-EDITOR.ERRORS.INVALID-VISIBILITY-RULES.CONFIRM-NO')
|
|
|
|
},
|
|
|
|
maxWidth:'30em'
|
|
|
|
})
|
|
|
|
.afterClosed()
|
|
|
|
.subscribe(confirm=>{
|
|
|
|
if(confirm){
|
|
|
|
this.removeFieldSetVisibilityRules(fieldSetHavingInvalidVisibilityRules);
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-PROFILE-EDITOR.ERRORS.INVALID-VISIBILITY-RULES.REMOVE-SUCCESS'), SnackBarNotificationLevel.Success);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
console.log('User not confirmed');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private removeFieldSetVisibilityRules(fieldsets:ToCEntry[]){
|
|
|
|
|
|
|
|
if(!fieldsets || !fieldsets.length) return;
|
2021-03-24 10:40:48 +01:00
|
|
|
|
2021-05-05 14:50:20 +02:00
|
|
|
fieldsets.forEach(fieldset=>{
|
|
|
|
if(fieldset.type != ToCEntryType.FieldSet){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const fields = fieldset.form.get('fields') as FormArray;
|
|
|
|
|
|
|
|
fields.controls.forEach(fieldControl=>{
|
|
|
|
if(this.hasInvalidVisibilityRule(fieldControl as FormGroup)){
|
|
|
|
try{
|
|
|
|
(fieldControl.get('visible').get('rules') as FormArray).clear();
|
|
|
|
}catch{}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private hasInvalidVisibilityRule(field: FormGroup):boolean{
|
|
|
|
const renderStyle = field.get('viewStyle').get('renderStyle').value;
|
|
|
|
if(renderStyle && ![
|
|
|
|
DatasetProfileFieldViewStyle.TextArea,
|
|
|
|
DatasetProfileFieldViewStyle.FreeText,
|
|
|
|
DatasetProfileFieldViewStyle.BooleanDecision,
|
|
|
|
DatasetProfileFieldViewStyle.RadioBox,
|
|
|
|
DatasetProfileFieldViewStyle.CheckBox,
|
|
|
|
DatasetProfileFieldViewStyle.DatePicker,
|
|
|
|
DatasetProfileFieldViewStyle.ComboBox,
|
|
|
|
].includes(renderStyle)){
|
|
|
|
if(((renderStyle === DatasetProfileFieldViewStyle) && (field.get('data').get('type').value === DatasetProfileComboBoxType.WordList))){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try{
|
|
|
|
if(field.get('visible').get('rules').value.length){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}catch{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
prepareForm() {
|
2021-04-05 11:06:14 +02:00
|
|
|
this.visibilityRulesService.buildVisibilityRules([],this.form);
|
2021-03-27 18:52:53 +01:00
|
|
|
// this.form.setValidators([EditorCustomValidators.atLeastOneElementListValidator('pages'),EditorCustomValidators.pagesHaveAtLeastOneSection('pages', 'sections')]);
|
|
|
|
// this.form.updateValueAndValidity();
|
2019-01-18 18:03:45 +01:00
|
|
|
this.form.valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(change => {
|
2021-03-12 17:19:51 +01:00
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
// 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');
|
|
|
|
// });
|
|
|
|
});
|
2021-02-18 16:13:56 +01:00
|
|
|
setTimeout(() => {
|
2021-04-07 18:03:22 +02:00
|
|
|
this.steps = this.stepper.steps;
|
2021-02-18 16:13:56 +01:00
|
|
|
});
|
2021-03-24 10:40:48 +01:00
|
|
|
this._initializeToCEntries();
|
2021-04-13 15:27:29 +02:00
|
|
|
// console.log(this.form.get('users').value);
|
2021-04-27 09:38:20 +02:00
|
|
|
if (this.form.get('users').value !== null && this.form.get('users').value !== undefined) {
|
|
|
|
this.userChipList = [...this.form.get('users').value];
|
|
|
|
} else {
|
|
|
|
this.userChipList = [];
|
|
|
|
}
|
2021-02-03 11:21:31 +01:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
// addSection() {
|
|
|
|
// const section: SectionEditorModel = new SectionEditorModel();
|
|
|
|
// this.dataModel.sections.push(section);
|
|
|
|
// (<FormArray>this.form.get('sections')).push(section.buildForm());
|
|
|
|
// }
|
2019-01-18 18:03:45 +01:00
|
|
|
|
2021-03-31 17:31:57 +02:00
|
|
|
// addPage() {
|
|
|
|
// const page: PageEditorModel = new PageEditorModel(this.dataModel.pages.length);
|
|
|
|
// this.dataModel.pages.push(page);
|
|
|
|
// (<FormArray>this.form.get('pages')).push(page.buildForm());
|
|
|
|
// }
|
2019-01-18 18:03:45 +01:00
|
|
|
|
2021-03-31 17:31:57 +02:00
|
|
|
// DeleteSection(index) {
|
|
|
|
// this.dataModel.sections.splice(index, 1);
|
|
|
|
// (<FormArray>this.form.get('sections')).removeAt(index);
|
|
|
|
// }
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
onSubmit() {
|
2019-02-15 11:26:14 +01:00
|
|
|
let data = this.form.value;
|
2021-03-31 17:31:57 +02:00
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
if (this.datasetProfileId) {
|
|
|
|
this.datasetProfileService.updateForm(this.datasetProfileId, data)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(() => {
|
2021-07-23 16:03:29 +02:00
|
|
|
this.form.markAsPristine();//deactivate guard
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/dataset-profiles']);
|
2021-03-31 17:31:57 +02:00
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-PROFILE-EDITOR.FEEDBACK-MESSAGES.SAVE-SUCCESS'), SnackBarNotificationLevel.Success);
|
|
|
|
},error=> this.onCallbackError(error));
|
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(() => {
|
2021-07-23 16:03:29 +02:00
|
|
|
this.form.markAsPristine();//deactivate guard
|
2019-03-26 15:30:33 +01:00
|
|
|
this.router.navigate(['/dataset-profiles']);
|
2021-03-31 17:31:57 +02:00
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-PROFILE-EDITOR.FEEDBACK-MESSAGES.SAVE-SUCCESS'), SnackBarNotificationLevel.Success);
|
2019-03-26 15:30:33 +01:00
|
|
|
},
|
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 {
|
2021-03-31 17:31:57 +02:00
|
|
|
if(this.form.get('status').value != DatasetStatus.Finalized){// forn created and finalized instantly
|
|
|
|
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(() => {
|
2021-07-23 16:03:29 +02:00
|
|
|
this.form.markAsPristine();//deactivate guard
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/dataset-profiles']);
|
2021-03-31 17:31:57 +02:00
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-PROFILE-EDITOR.FEEDBACK-MESSAGES.SAVE-SUCCESS'), SnackBarNotificationLevel.Success);
|
|
|
|
}, error=> this.onCallbackError(error));
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(() => {
|
2021-09-09 08:09:27 +02:00
|
|
|
this.form.markAsPristine();//deactivate guard
|
2019-11-22 16:06:47 +01:00
|
|
|
this.router.navigate(['/dataset-profiles']);
|
2021-03-31 17:31:57 +02:00
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-PROFILE-EDITOR.FEEDBACK-MESSAGES.SAVE-SUCCESS'), SnackBarNotificationLevel.Success)
|
|
|
|
},error=>this.onCallbackError(error));
|
2019-11-22 16:06:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
showUpdateButton() {
|
|
|
|
return !this.isNew && this.dataModel.status === DatasetProfileEnum.FINALIZED;
|
|
|
|
}
|
|
|
|
|
2021-03-31 17:31:57 +02:00
|
|
|
// isStepActive(step: number) {
|
|
|
|
// return this.stepper && this.stepper.selectedIndex === step;
|
|
|
|
// }
|
2019-01-18 18:03:45 +01:00
|
|
|
|
2021-03-31 17:31:57 +02:00
|
|
|
// 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-01-18 18:03:45 +01:00
|
|
|
|
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() {
|
2021-03-12 17:19:51 +01:00
|
|
|
this.colorizeInvalid = true;
|
|
|
|
this.printMyErrors(this.form);
|
|
|
|
|
|
|
|
|
|
|
|
// if (!this.form.valid) {
|
|
|
|
// this.nestedIndex = -1;
|
|
|
|
// this.form.markAllAsTouched();
|
|
|
|
// this.printErrors(this.form);
|
|
|
|
// this.showValidationErrorsDialog();
|
|
|
|
// this.nestedCount = [];
|
|
|
|
// this.nestedIndex = 0;
|
|
|
|
// this.errorMessages = [];
|
|
|
|
// }
|
2020-09-22 10:27:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-31 17:31:57 +02:00
|
|
|
//BEFORE REDESIGN
|
|
|
|
// 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 {
|
|
|
|
// this.errorMessages.push(numbering + ' ' + key + ': ' + keyError + ': ' + JSON.stringify(errors[keyError]));
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// } 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--;
|
2020-09-22 10:27:10 +02:00
|
|
|
|
2021-03-31 17:31:57 +02:00
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// }
|
2021-02-03 11:21:31 +01:00
|
|
|
|
2021-03-31 17:31:57 +02:00
|
|
|
// private showValidationErrorsDialog(projectOnly?: boolean) {
|
|
|
|
// const dialogRef = this.dialog.open(FormValidationErrorsDialogComponent, {
|
|
|
|
// disableClose: true,
|
|
|
|
// autoFocus: false,
|
|
|
|
// restoreFocus: false,
|
|
|
|
// data: {
|
|
|
|
// errorMessages: this.errorMessages,
|
|
|
|
// projectOnly: projectOnly
|
|
|
|
// },
|
|
|
|
// });
|
|
|
|
// }
|
2021-02-03 11:21:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-31 17:31:57 +02:00
|
|
|
// links: Link[] = [];
|
|
|
|
|
|
|
|
// getLinks(currentLinks: Link[]) {
|
|
|
|
// this.links = currentLinks;
|
|
|
|
// }
|
2021-02-03 11:21:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
datasetWizardModel: DatasetWizardEditorModel;
|
|
|
|
formGroup: FormGroup;
|
|
|
|
getPreview() {
|
2021-03-17 15:29:02 +01:00
|
|
|
let data = this.form.getRawValue();
|
2021-02-03 11:21:31 +01:00
|
|
|
this.datasetProfileService.preview(data).subscribe(x => {
|
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel({
|
|
|
|
datasetProfileDefinition: x
|
|
|
|
});
|
2021-03-17 15:29:02 +01:00
|
|
|
this.updateVisibilityRules();
|
2021-02-03 11:21:31 +01:00
|
|
|
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();
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
|
2021-02-19 15:35:14 +01:00
|
|
|
private refreshToCEntries(): ToCEntry[]{
|
|
|
|
this.toCEntries = this.getTocEntries();
|
|
|
|
//update selected tocentry
|
|
|
|
if(this.selectedTocEntry){
|
|
|
|
this.selectedTocEntry = this._findTocEntryById(this.selectedTocEntry.id, this.toCEntries);
|
|
|
|
}
|
2021-03-08 10:24:30 +01:00
|
|
|
// this.updateOrdinals(this.toCEntries);
|
|
|
|
// this._updateNumbering(this.toCEntries);
|
2021-02-19 15:35:14 +01:00
|
|
|
return this.toCEntries;
|
|
|
|
}
|
|
|
|
|
2021-03-24 10:40:48 +01:00
|
|
|
/**
|
2021-04-07 18:03:22 +02:00
|
|
|
* Updates entries ordinal form value
|
2021-03-24 10:40:48 +01:00
|
|
|
* based on the index they have on the tocentry array.
|
|
|
|
* Tocentries that are on the same level have distinct ordinal value
|
2021-04-07 18:03:22 +02:00
|
|
|
*
|
|
|
|
* @param tocentries
|
|
|
|
*
|
2021-03-24 10:40:48 +01:00
|
|
|
*/
|
|
|
|
private _updateOrdinals(tocentries: ToCEntry[]){
|
|
|
|
|
|
|
|
if(!tocentries || !tocentries.length) return;
|
|
|
|
tocentries.forEach((e,idx)=>{
|
|
|
|
const ordinalControl = e.form.get('ordinal');
|
|
|
|
if(ordinalControl){
|
|
|
|
ordinalControl.setValue(idx);
|
|
|
|
ordinalControl.updateValueAndValidity();
|
|
|
|
}
|
|
|
|
this._updateOrdinals(e.subEntries);
|
|
|
|
});
|
|
|
|
}
|
2021-02-25 13:17:47 +01:00
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
//sort tocentries based on their ordinality
|
|
|
|
private _sortToCentries(entries: ToCEntry[]){
|
|
|
|
if(!entries || !entries.length) return;
|
|
|
|
entries.sort(this._compareOrdinals);
|
|
|
|
entries.forEach(e=>{
|
|
|
|
this._sortToCentries(e.subEntries)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
private _compareOrdinals(a, b){
|
|
|
|
|
|
|
|
const aValue = a.form.get('ordinal').value as number;
|
|
|
|
const bValue = b.form.get('ordinal').value as number;
|
|
|
|
|
|
|
|
// if(!aValue || !bValue) return 0;
|
|
|
|
return aValue - bValue;
|
|
|
|
}
|
2021-03-08 10:24:30 +01:00
|
|
|
private _updateNumbering(entries:ToCEntry[], parentNumbering:string){
|
|
|
|
if(!entries || !entries.length) return;
|
|
|
|
let prefix ='';
|
|
|
|
if(parentNumbering.length){
|
|
|
|
prefix = parentNumbering + '.';
|
|
|
|
}
|
|
|
|
entries.forEach((entry,index)=>{
|
|
|
|
const numbering = prefix + (index+1);
|
|
|
|
entry.numbering = numbering;
|
|
|
|
this._updateNumbering(entry.subEntries, numbering);
|
|
|
|
})
|
|
|
|
}
|
2021-02-25 13:17:47 +01:00
|
|
|
|
2021-02-19 15:35:14 +01:00
|
|
|
toCEntries:ToCEntry[];
|
|
|
|
|
2021-02-03 11:21:31 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
});
|
2021-03-08 10:24:30 +01:00
|
|
|
this._sortToCentries(result);//ordeby ordinal
|
|
|
|
this._updateNumbering(result, '');//update nubering if needed
|
2021-02-04 11:22:52 +01:00
|
|
|
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{
|
2021-03-23 11:39:04 +01:00
|
|
|
if(!tocentries || !tocentries.length){
|
2021-02-15 18:16:48 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let tocEntryFound = tocentries.find(entry=>entry.id === id);
|
|
|
|
|
|
|
|
if(tocEntryFound){
|
|
|
|
return tocEntryFound;
|
2021-04-07 18:03:22 +02:00
|
|
|
}
|
2021-02-15 18:16:48 +01:00
|
|
|
|
|
|
|
for(let entry of tocentries){
|
|
|
|
const result = this._findTocEntryById(id, entry.subEntries);
|
|
|
|
if(result){
|
|
|
|
tocEntryFound = result;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
return tocEntryFound? tocEntryFound: null;
|
2021-02-15 18:16:48 +01:00
|
|
|
}
|
2021-03-31 17:31:57 +02:00
|
|
|
addNewEntry(tce: NewEntryType) {
|
2021-02-12 12:23:39 +01:00
|
|
|
|
|
|
|
const parent = tce.parent;
|
|
|
|
|
|
|
|
//define entry type
|
|
|
|
switch (tce.childType) {
|
2021-03-01 10:28:27 +01:00
|
|
|
case ToCEntryType.Page:
|
2021-03-04 13:38:46 +01:00
|
|
|
const pagesArray = (this.form.get('pages') as FormArray);
|
2021-02-12 12:23:39 +01:00
|
|
|
|
2021-03-04 13:38:46 +01:00
|
|
|
const page: PageEditorModel = new PageEditorModel(pagesArray.length);
|
2021-03-01 10:28:27 +01:00
|
|
|
const pageForm = page.buildForm();
|
|
|
|
// this.dataModel.pages.push(page);
|
2021-02-12 12:23:39 +01:00
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
pagesArray.push(pageForm);
|
2021-03-12 17:19:51 +01:00
|
|
|
// this.form.updateValueAndValidity();
|
2021-03-01 10:28:27 +01:00
|
|
|
this.refreshToCEntries();
|
|
|
|
this.selectedTocEntry = this._findTocEntryById(pageForm.get('id').value, this.toCEntries);
|
2021-02-12 12:23:39 +01:00
|
|
|
|
|
|
|
break;
|
2021-03-01 10:28:27 +01:00
|
|
|
case ToCEntryType.Section:
|
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
const section: SectionEditorModel = new SectionEditorModel();
|
|
|
|
section.id = Guid.create().toString();
|
|
|
|
let sectionsArray:FormArray;
|
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
if (parent.type === ToCEntryType.Page) {//FIRST LEVEL SECTION
|
|
|
|
sectionsArray = this.form.get('sections') as FormArray;
|
2021-02-12 12:23:39 +01:00
|
|
|
|
|
|
|
section.page = parent.id;
|
2021-03-24 10:40:48 +01:00
|
|
|
|
|
|
|
try{
|
|
|
|
const max = sectionsArray.controls.filter(control=>control.get('page').value === parent.id)
|
|
|
|
.map(control=>control.get('ordinal').value)
|
|
|
|
.reduce((a,b)=>Math.max(a,b));
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-24 10:40:48 +01:00
|
|
|
section.ordinal = max + 1;
|
|
|
|
}catch{
|
|
|
|
section.ordinal = sectionsArray.length;
|
|
|
|
|
|
|
|
}
|
2021-03-01 10:28:27 +01:00
|
|
|
sectionsArray.push(section.buildForm());
|
2021-03-12 17:19:51 +01:00
|
|
|
// this.form.updateValueAndValidity();
|
2021-02-12 12:23:39 +01:00
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
} else if( parent.type == ToCEntryType.Section) { //SUBSECTION OF SECTION
|
|
|
|
sectionsArray = parent.form.get('sections') as FormArray;
|
2021-02-12 12:23:39 +01:00
|
|
|
|
|
|
|
//adding page parent MAYBE NOT NEEDED
|
|
|
|
section.page = parent.form.get('page').value;
|
2021-03-24 10:40:48 +01:00
|
|
|
try{
|
|
|
|
const maxOrdinal = sectionsArray.controls.map(control=>control.get('ordinal').value).reduce((a,b)=>Math.max(a, b));
|
|
|
|
section.ordinal = maxOrdinal+1;
|
|
|
|
}catch{
|
|
|
|
section.ordinal = sectionsArray.length;
|
|
|
|
}
|
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
sectionsArray.push(section.buildForm());
|
2021-02-12 12:23:39 +01:00
|
|
|
// (child.form.parent as FormArray).push(section.buildForm());
|
|
|
|
|
|
|
|
}else{
|
2021-03-24 10:40:48 +01:00
|
|
|
console.error('Section can only be child of a page or another section');
|
2021-02-12 12:23:39 +01:00
|
|
|
}
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
const sectionAdded = sectionsArray.at(sectionsArray.length -1) as FormGroup;
|
2021-03-27 18:52:53 +01:00
|
|
|
// sectionAdded.setValidators(this.customEditorValidators.sectionHasAtLeastOneChildOf('fieldSets','sections'));
|
|
|
|
// sectionAdded.updateValueAndValidity();
|
2021-02-12 12:23:39 +01:00
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
|
|
|
|
this.refreshToCEntries();
|
|
|
|
this.selectedTocEntry = this._findTocEntryById(sectionAdded.get('id').value, this.toCEntries);
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
break;
|
|
|
|
case ToCEntryType.FieldSet:
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
//create one field form fieldset
|
2021-03-01 10:28:27 +01:00
|
|
|
const field: FieldEditorModel = new FieldEditorModel();
|
2021-02-12 12:23:39 +01:00
|
|
|
field.id = Guid.create().toString();
|
2021-02-18 16:13:56 +01:00
|
|
|
field.ordinal = 0;//first filed in the fields list
|
2021-03-01 10:28:27 +01:00
|
|
|
const fieldForm = field.buildForm();
|
2021-03-01 17:42:18 +01:00
|
|
|
// fieldForm.setValidators(this.customFieldValidator());
|
2021-03-01 10:28:27 +01:00
|
|
|
// fieldForm.get('viewStyle').get('renderStyle').setValidators(Validators.required);
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
// fieldSet.fields.push(field);
|
2021-02-18 16:13:56 +01:00
|
|
|
// field.ordinal = fieldSet.fields.length-1;
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
const fieldSetsArray = parent.form.get('fieldSets') as FormArray
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
//give fieldset id and ordinal
|
2021-03-01 10:28:27 +01:00
|
|
|
const fieldSet: FieldSetEditorModel = new FieldSetEditorModel();
|
|
|
|
const fieldSetId = Guid.create().toString();
|
|
|
|
fieldSet.id = fieldSetId;
|
2021-03-24 10:40:48 +01:00
|
|
|
|
|
|
|
try{
|
|
|
|
const maxOrdinal = fieldSetsArray.controls.map(control=>control.get('ordinal').value).reduce((a,b)=>Math.max(a, b));
|
|
|
|
fieldSet.ordinal = maxOrdinal+1;
|
|
|
|
}catch{
|
|
|
|
fieldSet.ordinal = fieldSetsArray.length;
|
|
|
|
}
|
2021-03-01 10:28:27 +01:00
|
|
|
const fieldsetForm = fieldSet.buildForm();
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
|
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
(fieldsetForm.get('fields') as FormArray).push(fieldForm);
|
|
|
|
fieldSetsArray.push(fieldsetForm);
|
2021-02-12 12:23:39 +01:00
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
this.refreshToCEntries();
|
|
|
|
this.selectedTocEntry = this._findTocEntryById(fieldSetId, this.toCEntries);
|
2021-03-01 17:42:18 +01:00
|
|
|
// fieldForm.updateValueAndValidity();
|
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-03-12 17:19:51 +01:00
|
|
|
this.form.updateValueAndValidity();
|
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){
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-12 15:27:35 +01:00
|
|
|
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-04-07 18:03:22 +02:00
|
|
|
|
2021-02-12 15:27:35 +01:00
|
|
|
}
|
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
|
2021-02-25 13:17:47 +01:00
|
|
|
this._updateSelectedItem(tce);
|
2021-02-12 12:23:39 +01:00
|
|
|
pages.removeAt(pageIndex);
|
|
|
|
//clean up sections of removed page
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
const sections = (this.form.get('sections') as FormArray);
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
const sectionsIndexToBeRemoved = [];
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
sections.controls.forEach((section,idx)=>{
|
|
|
|
if(section.get('page').value === tce.id){
|
|
|
|
sectionsIndexToBeRemoved.push(idx);
|
2021-02-12 12:23:39 +01:00
|
|
|
}
|
2021-03-12 17:19:51 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if(sectionsIndexToBeRemoved.length){
|
|
|
|
sectionsIndexToBeRemoved.reverse().forEach(index=>{
|
|
|
|
sections.removeAt(index);
|
|
|
|
});
|
2021-02-12 12:23:39 +01:00
|
|
|
}
|
2021-02-04 09:33:03 +01:00
|
|
|
|
2021-04-07 18:03:22 +02:00
|
|
|
//update page ordinals
|
2021-02-12 12:23:39 +01:00
|
|
|
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
|
2021-03-12 17:19:51 +01:00
|
|
|
// this.form.controls.sections.updateValueAndValidity();
|
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
|
|
|
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
|
2021-02-25 13:17:47 +01:00
|
|
|
this._updateSelectedItem(tce);
|
2021-02-12 12:23:39 +01:00
|
|
|
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-04-07 18:03:22 +02:00
|
|
|
//LOOK FOR SUBSECTION CASE
|
2021-02-12 12:23:39 +01:00
|
|
|
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) {
|
2021-02-25 13:17:47 +01:00
|
|
|
this._updateSelectedItem(tce);
|
2021-02-12 12:23:39 +01:00
|
|
|
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;
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
|
|
|
|
let idx = -1;
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
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
|
2021-02-25 13:17:47 +01:00
|
|
|
this._updateSelectedItem(tce);
|
2021-02-12 12:23:39 +01:00
|
|
|
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
|
2021-02-25 13:17:47 +01:00
|
|
|
|
2021-07-23 16:03:29 +02:00
|
|
|
// this.refreshToCEntries();
|
|
|
|
this.onDataNeedsRefresh();
|
2021-03-12 17:19:51 +01:00
|
|
|
this.form.updateValueAndValidity();
|
2021-02-25 13:17:47 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private _updateSelectedItem(tce: ToCEntry){
|
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
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{
|
2021-02-25 13:17:47 +01:00
|
|
|
|
|
|
|
//if first level section
|
|
|
|
const firstLevelSections = (this.form.get('sections') as FormArray);
|
|
|
|
let isFirstLevel: boolean = false;
|
|
|
|
firstLevelSections.controls.forEach(section=>{
|
|
|
|
if(section.get('id').value === tce.id){
|
|
|
|
isFirstLevel = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let parentId = null;
|
|
|
|
if(isFirstLevel){
|
|
|
|
parentId = tce.form.get('page').value;
|
|
|
|
}else{
|
|
|
|
parentId = tce.form.parent.parent.get('id').value
|
|
|
|
}
|
|
|
|
|
|
|
|
// const parentId = tce.form.parent.parent.get('id').value;
|
2021-02-17 17:39:07 +01:00
|
|
|
if(parentId){
|
|
|
|
const tocentries = this.getTocEntries();
|
|
|
|
const parent = this._findTocEntryById(parentId, tocentries);
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-17 17:39:07 +01:00
|
|
|
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(){
|
2021-03-08 10:24:30 +01:00
|
|
|
// console.log(this.form.value);
|
|
|
|
console.log(this.form);
|
2021-02-12 12:23:39 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 15:27:35 +01:00
|
|
|
get barPercentage(){
|
2021-02-17 18:44:50 +01:00
|
|
|
if(!this.stepper || !this.steps){
|
2021-03-17 15:29:02 +01:00
|
|
|
return 0;
|
2021-02-12 12:23:39 +01:00
|
|
|
}
|
|
|
|
const selectedIndex = this.stepper.selectedIndex + 1;
|
2021-03-17 15:29:02 +01:00
|
|
|
return (selectedIndex / this.stepper.steps.length) * 100;
|
2021-02-12 12:23:39 +01:00
|
|
|
}
|
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
|
|
|
|
get progressStyle(){
|
2021-03-17 15:29:02 +01:00
|
|
|
// return {'transform': 'translateX('+this.barPercentage+'%) skewX(-25deg)'}
|
|
|
|
const diff = 3;
|
|
|
|
|
|
|
|
return {
|
|
|
|
'clip-path': `polygon(0 0, ${Math.round(this.barPercentage + diff)}% 0, ${Math.round(this.barPercentage)}% 100%, 0 100%)`
|
|
|
|
}
|
2021-02-15 18:16:48 +01:00
|
|
|
}
|
|
|
|
|
2021-02-17 18:44:50 +01:00
|
|
|
steps:QueryList<CdkStep>;
|
|
|
|
// get steps(){
|
|
|
|
// if(!this.stepper){
|
|
|
|
// return [];
|
|
|
|
// }
|
2021-02-12 15:27:35 +01:00
|
|
|
|
2021-02-17 18:44:50 +01:00
|
|
|
// return this.stepper.steps;
|
|
|
|
// }
|
2021-02-15 18:16:48 +01:00
|
|
|
|
|
|
|
|
2021-03-17 15:29:02 +01:00
|
|
|
// generatePreviewForm(){
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
|
2021-03-17 15:29:02 +01:00
|
|
|
// const model = new DatasetDescriptionFormEditorModel();
|
2021-02-15 18:16:48 +01:00
|
|
|
|
2021-03-17 15:29:02 +01:00
|
|
|
// const toCentries = this.getTocEntries();
|
2021-02-15 18:16:48 +01:00
|
|
|
|
|
|
|
|
2021-03-17 15:29:02 +01:00
|
|
|
// //first level is always pages
|
|
|
|
// model.pages = toCentries.map((entry,idx)=>{
|
|
|
|
// if( !(entry.type == ToCEntryType.Page)){
|
|
|
|
// return null;
|
|
|
|
// }
|
|
|
|
// const pageModel = new DatasetDescriptionPageEditorModel();
|
2021-02-15 18:16:48 +01:00
|
|
|
|
2021-03-17 15:29:02 +01:00
|
|
|
// pageModel.ordinal = entry.form.get('ordinal').value;
|
|
|
|
// pageModel.title = entry.label;
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-17 15:29:02 +01:00
|
|
|
// if(entry.subEntries){
|
|
|
|
// pageModel.sections = entry.subEntries.map(section=>{
|
|
|
|
// const sectionModel = new DatasetDescriptionSectionEditorModel();
|
2021-02-15 18:16:48 +01:00
|
|
|
|
2021-03-17 15:29:02 +01:00
|
|
|
// sectionModel.id = section.id;
|
|
|
|
// sectionModel.ordinal = section.form.get('ordinal').value;
|
2021-04-07 18:03:22 +02:00
|
|
|
// sectionModel.description = section.form.get('description').value;
|
2021-03-17 15:29:02 +01:00
|
|
|
// sectionModel.page = entry.form.get('ordinal').value;
|
|
|
|
// sectionModel.title = section.label;
|
|
|
|
// sectionModel.numbering = (idx+1).toString();
|
2021-02-15 18:16:48 +01:00
|
|
|
|
|
|
|
|
2021-03-17 15:29:02 +01:00
|
|
|
// if(section.subEntriesType == ToCEntryType.Section){
|
|
|
|
// sectionModel.sections = this._buildSectionsRecursively(section.subEntries, sectionModel.numbering);
|
|
|
|
// }else{
|
|
|
|
// sectionModel.compositeFields = this._buildFormFields(section.subEntries, sectionModel.numbering)
|
|
|
|
// }
|
2021-02-15 18:16:48 +01:00
|
|
|
|
2021-03-17 15:29:02 +01:00
|
|
|
// return sectionModel;
|
|
|
|
// });
|
|
|
|
// };
|
|
|
|
// return pageModel;
|
2021-02-15 18:16:48 +01:00
|
|
|
|
2021-03-17 15:29:02 +01:00
|
|
|
// });
|
2021-02-15 18:16:48 +01:00
|
|
|
|
2021-02-17 17:39:07 +01:00
|
|
|
|
2021-03-17 15:29:02 +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);
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// });
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-17 15:29:02 +01:00
|
|
|
// model.rules = rules;
|
|
|
|
// this.visibilityRules = rules;
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-17 15:29:02 +01:00
|
|
|
// this.previewForm = model.buildForm();
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
updateVisibilityRules(){
|
2021-02-17 17:39:07 +01:00
|
|
|
const rules:Rule[] =[];
|
2021-03-17 15:29:02 +01:00
|
|
|
const fieldSets = this._getFieldSets(this.getTocEntries());
|
2021-02-17 17:39:07 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-17 17:39:07 +01:00
|
|
|
this.visibilityRules = rules;
|
2021-03-17 15:29:02 +01:00
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
}
|
|
|
|
|
2021-02-17 17:39:07 +01:00
|
|
|
visibilityRules:Rule[];
|
2021-02-18 16:13:56 +01:00
|
|
|
private _buildSectionsRecursively( tocentries: ToCEntry[], parentNumbering:string): DatasetDescriptionSectionEditorModel[]{
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
|
|
|
|
if(!tocentries) return null;
|
|
|
|
|
|
|
|
|
|
|
|
const result: Array<DatasetDescriptionSectionEditorModel> = [];
|
|
|
|
|
2021-02-18 16:13:56 +01:00
|
|
|
tocentries.forEach((tocentry, idx)=>{
|
2021-02-15 18:16:48 +01:00
|
|
|
|
|
|
|
const sectionModel = new DatasetDescriptionSectionEditorModel();
|
|
|
|
sectionModel.id = tocentry.id;
|
|
|
|
sectionModel.ordinal = tocentry.form.get('ordinal').value;
|
2021-04-07 18:03:22 +02:00
|
|
|
sectionModel.description = tocentry.form.get('description').value;
|
2021-02-15 18:16:48 +01:00
|
|
|
// sectionModel.page = entry.form.get('ordinal').value;
|
|
|
|
sectionModel.title = tocentry.label;
|
2021-02-18 16:13:56 +01:00
|
|
|
// sectionModel.numbering = tocentry.numbering;
|
|
|
|
sectionModel.numbering = parentNumbering+"."+(idx+1);;
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
if(tocentry.subEntriesType == ToCEntryType.Section){
|
2021-02-18 16:13:56 +01:00
|
|
|
sectionModel.sections = this._buildSectionsRecursively(tocentry.subEntries, sectionModel.numbering);
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
}else{
|
2021-02-18 16:13:56 +01:00
|
|
|
sectionModel.compositeFields = this._buildFormFields(tocentry.subEntries, sectionModel.numbering);
|
2021-02-15 18:16:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
result.push(sectionModel);
|
|
|
|
})
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-02-18 16:13:56 +01:00
|
|
|
private _buildFormFields(tocentries: ToCEntry[], parentNumbering: string):DatasetDescriptionCompositeFieldEditorModel[]{
|
2021-02-15 18:16:48 +01:00
|
|
|
if(!tocentries) return null;
|
|
|
|
|
|
|
|
const fieldsets:DatasetDescriptionCompositeFieldEditorModel[] = [];
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-02-18 16:13:56 +01:00
|
|
|
tocentries.forEach((fs, idx)=>{
|
2021-02-15 18:16:48 +01:00
|
|
|
|
|
|
|
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-18 16:13:56 +01:00
|
|
|
// fieldset.numbering = fs.numbering;
|
|
|
|
fieldset.numbering = parentNumbering+"."+(idx+1);
|
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-18 16:13:56 +01:00
|
|
|
fieldModel.defaultValue = fieldModel.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-25 13:17:47 +01:00
|
|
|
|
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
// get basicInfo(){
|
2021-02-25 13:17:47 +01:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
// const label = this.form.get('label');
|
|
|
|
// const description = this.form.get('description');
|
|
|
|
// const language = this.form.get('language');
|
2021-02-25 13:17:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
// const fg = new FormGroup({
|
|
|
|
// label: label,
|
|
|
|
// description: description,
|
|
|
|
// language: language
|
|
|
|
// })
|
2021-02-25 13:17:47 +01:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
// return fg;
|
|
|
|
// }
|
2021-02-25 13:17:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 18:03:22 +02:00
|
|
|
onMatStepperSelectionChange(event: StepperSelectionEvent){
|
2021-02-15 18:16:48 +01:00
|
|
|
|
2021-03-08 10:24:30 +01:00
|
|
|
if(event.selectedIndex === (this.steps.length -1)){//preview selected
|
2021-03-17 15:29:02 +01:00
|
|
|
// this.generatePreviewForm();//TODO LAZY LOADING IN THE TEMPLATE
|
|
|
|
this.getPreview();
|
2021-02-17 17:39:07 +01:00
|
|
|
}else{
|
2021-03-17 15:29:02 +01:00
|
|
|
// this.previewForm = null;
|
|
|
|
this.formGroup = null;
|
2021-02-15 18:16:48 +01:00
|
|
|
}
|
2021-03-08 10:24:30 +01:00
|
|
|
this.form.markAsUntouched();
|
2021-02-17 17:39:07 +01:00
|
|
|
|
2021-02-15 18:16:48 +01:00
|
|
|
}
|
|
|
|
|
2021-03-17 15:29:02 +01:00
|
|
|
// previewForm:FormGroup;
|
2021-03-23 11:39:04 +01:00
|
|
|
onDataNeedsRefresh(params?){
|
|
|
|
|
|
|
|
const tocentries = this.refreshToCEntries();
|
|
|
|
|
|
|
|
if(params && params.draggedItemId){
|
|
|
|
if(params.draggedItemId){
|
|
|
|
this.displayItem(this._findTocEntryById(params.draggedItemId, tocentries));
|
|
|
|
}
|
|
|
|
}
|
2021-07-23 16:03:29 +02:00
|
|
|
this.form.markAsDirty();
|
2021-02-24 15:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cloneFieldSet(fieldset: FormGroup){
|
|
|
|
const values = fieldset.getRawValue();
|
|
|
|
const parentArray = fieldset.parent as FormArray;
|
|
|
|
|
|
|
|
values.id = Guid.create().toString();
|
|
|
|
values.ordinal = parentArray.length;
|
|
|
|
|
|
|
|
values.fields.forEach(element => {
|
|
|
|
element.id = Guid.create().toString()
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const clonedModel = new FieldSetEditorModel().fromModel(values);
|
|
|
|
const clonedForm = clonedModel.buildForm();
|
|
|
|
parentArray.push(clonedForm);
|
|
|
|
|
2021-02-25 13:17:47 +01:00
|
|
|
//update tocentries and make selected tocentry the cloedn
|
|
|
|
let entries = this.refreshToCEntries();
|
2021-02-24 15:56:14 +01:00
|
|
|
|
2021-02-25 13:17:47 +01:00
|
|
|
const entryfound = this._findTocEntryById(clonedForm.get('id').value, entries);
|
|
|
|
if(entryfound){
|
|
|
|
this.selectedTocEntry = entryfound;
|
|
|
|
}
|
2021-02-24 15:56:14 +01:00
|
|
|
|
|
|
|
// //create one field form fieldset
|
|
|
|
// const field: FieldEditorModel = new FieldEditorModel(); //to ask
|
|
|
|
// field.id = Guid.create().toString();
|
|
|
|
// field.ordinal = 0;//first filed in the fields list
|
|
|
|
// fieldSet.fields.push(field);
|
|
|
|
// // field.ordinal = fieldSet.fields.length-1;
|
|
|
|
|
|
|
|
// //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-04-07 18:03:22 +02:00
|
|
|
|
2021-03-04 13:38:46 +01:00
|
|
|
}
|
|
|
|
|
2021-03-31 17:31:57 +02:00
|
|
|
isStepCompleted(stepIndex: number){
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-04 13:38:46 +01:00
|
|
|
let stepCompleted = false;
|
|
|
|
this.steps.forEach((step,index)=>{
|
|
|
|
if(stepIndex === index){
|
2021-03-12 17:19:51 +01:00
|
|
|
stepCompleted = step.completed;
|
2021-03-04 13:38:46 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return stepCompleted;
|
|
|
|
}
|
|
|
|
|
|
|
|
isStepUnlocked(stepIndex: number): boolean{
|
|
|
|
if(stepIndex === 0) return true;
|
2021-03-12 17:19:51 +01:00
|
|
|
if(stepIndex <0 ) return false;
|
2021-03-04 13:38:46 +01:00
|
|
|
//if previous step is valid then unlock
|
|
|
|
let stepUnlocked: boolean = false;
|
2021-03-12 17:19:51 +01:00
|
|
|
|
|
|
|
if(!this.isStepUnlocked(stepIndex -1)) return false;
|
|
|
|
|
2021-03-04 13:38:46 +01:00
|
|
|
this.steps.forEach((step,index)=>{
|
|
|
|
|
|
|
|
if(index+1 == stepIndex){//previous step
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
if(step.completed){
|
2021-03-04 13:38:46 +01:00
|
|
|
stepUnlocked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return stepUnlocked;
|
2021-02-25 13:17:47 +01:00
|
|
|
}
|
|
|
|
|
2021-03-29 17:42:55 +02:00
|
|
|
validateStep(selectedIndex){
|
|
|
|
|
|
|
|
if(selectedIndex === 1){//form description
|
|
|
|
if(this.form.invalid){
|
|
|
|
this.checkFormValidation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
// if(step.hasError){
|
|
|
|
// this.printMyErrors(this.form);
|
|
|
|
// }
|
2021-02-19 15:35:14 +01:00
|
|
|
}
|
2021-03-01 10:28:27 +01:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
// getFormValidationErrors() {
|
|
|
|
// Object.keys(this.form.controls).forEach(key => {
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
// const controlErrors: ValidationErrors = this.form.get(key).errors;
|
|
|
|
// if (controlErrors != null) {
|
|
|
|
// Object.keys(controlErrors).forEach(keyError => {
|
|
|
|
// console.log('Key control: ' + key + ', keyError: ' + keyError + ', err value: ', controlErrors[keyError]);
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// });
|
2021-03-01 10:28:27 +01:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
// if(this.form.invalid){
|
|
|
|
// console.log('this form is invalid!');
|
|
|
|
// console.log(this.form.errors);
|
|
|
|
// }
|
|
|
|
// }
|
2021-03-01 10:28:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-01 17:42:18 +01:00
|
|
|
private _buildErrorMessage(errors, numbering, key):string[]{
|
|
|
|
const errmess: string[] = [];
|
2021-03-01 10:28:27 +01:00
|
|
|
|
2021-03-01 17:42:18 +01:00
|
|
|
Object.keys(errors).forEach(keyError => {
|
2021-03-12 17:19:51 +01:00
|
|
|
|
|
|
|
switch(keyError){
|
|
|
|
case EditorCustomValidatorsEnum.atLeastOneSectionInPage:
|
2021-03-22 14:47:45 +01:00
|
|
|
errmess.push( this.language.instant('DATASET-PROFILE-EDITOR.STEPS.FORM.FORM-VALIDATION.ERROR-MESSAGES.PAGE-MUST-HAVE-SECTION'));
|
2021-03-12 17:19:51 +01:00
|
|
|
break;
|
|
|
|
case EditorCustomValidatorsEnum.emptyArray:
|
2021-03-22 14:47:45 +01:00
|
|
|
errmess.push(numbering+this.language.instant('DATASET-PROFILE-EDITOR.STEPS.FORM.FORM-VALIDATION.ERROR-MESSAGES.NEEDS-MORE-INFORMATION'))
|
2021-03-12 17:19:51 +01:00
|
|
|
break;
|
|
|
|
case EditorCustomValidatorsEnum.sectionMustHaveOneChild:
|
2021-03-22 14:47:45 +01:00
|
|
|
errmess.push(numbering+this.language.instant('DATASET-PROFILE-EDITOR.STEPS.FORM.FORM-VALIDATION.ERROR-MESSAGES.MUST-HAVE-SECTION-OR-FIELDSET'))
|
2021-03-12 17:19:51 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (typeof errors[keyError] === 'boolean') {
|
|
|
|
errmess.push(numbering + ' ' + key + ' is ' + keyError);
|
|
|
|
} else {
|
|
|
|
errmess.push(numbering + ' ' + key + ': ' + keyError + ': ' + JSON.stringify(errors[keyError]));
|
|
|
|
}
|
|
|
|
|
2021-03-01 17:42:18 +01:00
|
|
|
}
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-01 17:42:18 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
return errmess;
|
2021-03-01 10:28:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-08 10:24:30 +01:00
|
|
|
printMyErrors(form: AbstractControl){
|
2021-03-01 17:42:18 +01:00
|
|
|
// this._printToCentriesErrrors(this.toCEntries);
|
2021-03-08 10:24:30 +01:00
|
|
|
const result = this._getErrors(form);
|
2021-03-01 10:28:27 +01:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
// console.log('got errors ');
|
2021-03-01 17:42:18 +01:00
|
|
|
// console.log(result);
|
2021-03-01 10:28:27 +01:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
if(result && form.invalid){
|
2021-03-01 17:42:18 +01:00
|
|
|
const errmess:string[] = [];
|
2021-03-12 17:19:51 +01:00
|
|
|
if(result.length){
|
|
|
|
form.markAllAsTouched();
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
let indexes:number[] = [];
|
2021-04-07 18:03:22 +02:00
|
|
|
///search in pages,sections and fieldsets for the id
|
2021-03-12 17:19:51 +01:00
|
|
|
result.forEach((err,i)=>{
|
|
|
|
const entry = this._findTocEntryById(err.id, this.toCEntries);
|
|
|
|
if(entry){
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
// errmess.push(`Error on ${entry.numbering} ${entry.label} . ${err.key}`);
|
|
|
|
errmess.push(...this._buildErrorMessage(err.errors, entry.numbering, err.key));
|
|
|
|
indexes.push(i);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
indexes.reverse().forEach(index=>{
|
|
|
|
result.splice(index,1);
|
|
|
|
});
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
indexes = [];
|
|
|
|
//searching in fields
|
|
|
|
const fieldsets = this._getAllFieldSets(this.toCEntries);
|
|
|
|
result.forEach((err,i)=>{
|
|
|
|
fieldsets.filter(fs=>{
|
|
|
|
let fieldFound = false;
|
|
|
|
(fs.form.get('fields') as FormArray).controls.forEach(field=>{
|
|
|
|
if(field.get('id').value === err.id){
|
|
|
|
fieldFound = true;
|
|
|
|
indexes.push(i);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return fieldFound;
|
|
|
|
})
|
|
|
|
//printing fieldsets that the field missing
|
|
|
|
.forEach(fs=>{
|
|
|
|
// errmess.push(`Missing input in ${fs.numbering} ${fs.label} . ${err.key}`);
|
|
|
|
errmess.push(...this._buildErrorMessage(err.errors, fs.numbering, err.key));
|
2021-03-01 17:42:18 +01:00
|
|
|
});
|
|
|
|
});
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
indexes.reverse().forEach(index=>{
|
|
|
|
result.splice(index,1);
|
|
|
|
});
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
result.forEach(err=>{
|
|
|
|
// console.log(err);
|
|
|
|
if(err.key){
|
2021-03-22 14:47:45 +01:00
|
|
|
errmess.push(`${this.language.instant('DATASET-PROFILE-EDITOR.STEPS.FORM.FORM-VALIDATION.ERROR-MESSAGES.MISSING')} ${err.key}` );
|
2021-03-12 17:19:51 +01:00
|
|
|
}else{
|
2021-03-01 17:42:18 +01:00
|
|
|
|
2021-03-22 14:47:45 +01:00
|
|
|
errmess.push(this.language.instant('DATASET-PROFILE-EDITOR.STEPS.FORM.FORM-VALIDATION.ERROR-MESSAGES.PROVIDE-PAGE-AND-SECTION'));
|
2021-03-12 17:19:51 +01:00
|
|
|
}
|
|
|
|
// errmess.push(...this._buildErrorMessage(err.errors,"", err.key) );
|
2021-03-01 10:28:27 +01:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
})
|
|
|
|
}
|
2021-03-01 10:28:27 +01:00
|
|
|
|
2021-03-01 17:42:18 +01:00
|
|
|
const dialogRef = this.dialog.open(FormValidationErrorsDialogComponent, {
|
|
|
|
disableClose: true,
|
|
|
|
autoFocus: false,
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
errorMessages: errmess,
|
|
|
|
projectOnly: false
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-27 18:52:53 +01:00
|
|
|
/**
|
|
|
|
* Get all filedsets in a tocentry array;
|
|
|
|
* @param entries Tocentries to search in
|
|
|
|
* @returns The tocentries that are Fieldsets provided in the entries
|
|
|
|
*/
|
2021-03-01 17:42:18 +01:00
|
|
|
private _getAllFieldSets(entries: ToCEntry[]):ToCEntry[]{
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-01 17:42:18 +01:00
|
|
|
const fieldsets:ToCEntry[] = [];
|
|
|
|
if(!entries || !entries.length) return fieldsets;
|
|
|
|
|
|
|
|
|
|
|
|
entries.forEach(e=>{
|
|
|
|
if(e.type === ToCEntryType.FieldSet){
|
|
|
|
fieldsets.push(e);
|
|
|
|
}else{
|
|
|
|
fieldsets.push(...this._getAllFieldSets(e.subEntries));
|
2021-03-01 10:28:27 +01:00
|
|
|
}
|
|
|
|
});
|
2021-03-01 17:42:18 +01:00
|
|
|
return fieldsets;
|
2021-03-01 10:28:27 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 17:42:18 +01:00
|
|
|
|
|
|
|
private _getErrors(aControl: AbstractControl):InvalidControl[]{
|
|
|
|
|
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
if(aControl.valid) return;
|
|
|
|
|
|
|
|
let controlType = 'control';
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
if(aControl instanceof FormGroup) controlType="fg"
|
|
|
|
if(aControl instanceof FormControl) controlType="fc";
|
|
|
|
if(aControl instanceof FormArray) controlType="fa";
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
|
2021-03-01 17:42:18 +01:00
|
|
|
const invalidControls:InvalidControl[] = [];
|
2021-03-01 10:28:27 +01:00
|
|
|
//invalid
|
|
|
|
switch (controlType){
|
|
|
|
case 'fg':
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-01 17:42:18 +01:00
|
|
|
const controls = (aControl as FormGroup).controls;
|
2021-04-07 18:03:22 +02:00
|
|
|
const keys = Object.keys(controls);
|
2021-03-01 17:42:18 +01:00
|
|
|
keys.forEach(key=>{
|
2021-04-07 18:03:22 +02:00
|
|
|
const control = controls[key];
|
2021-03-12 17:19:51 +01:00
|
|
|
if(!control.invalid) return; //// !!!!! Important to be !invalid. (In case the template is finalized)
|
2021-03-01 17:42:18 +01:00
|
|
|
|
|
|
|
if(control instanceof FormControl){
|
|
|
|
const ctrl = control as FormControl;
|
|
|
|
|
|
|
|
invalidControls.push({
|
|
|
|
errors:ctrl.errors,
|
|
|
|
id: ctrl.get('id')? ctrl.get('id').value: null,
|
|
|
|
invalidSubControls: [],
|
|
|
|
key: key
|
|
|
|
});
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-01 17:42:18 +01:00
|
|
|
}else{
|
2021-03-04 13:38:46 +01:00
|
|
|
// if(aControl.errors){
|
|
|
|
// invalidControls.push({
|
|
|
|
// id: aControl.get('id')? aControl.get('id').value: null,
|
|
|
|
// errors:aControl.errors,
|
|
|
|
// key: aControl.get('title')? aControl.get('title').value: 'unspecified',
|
|
|
|
// invalidSubControls:[]//TODO TO CHECK
|
|
|
|
// });
|
|
|
|
// }
|
2021-03-12 17:19:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
//THE ONE WE REMOVED
|
|
|
|
// if(control.errors){
|
|
|
|
// // invalidControls.push({
|
|
|
|
// // id: aControl.get('id')? aControl.get('id').value: null,
|
|
|
|
// // errors:aControl.errors,
|
|
|
|
// // key: aControl.get('title')? aControl.get('title').value: 'unspecified',
|
|
|
|
// // invalidSubControls:[]//TODO TO CHECK
|
|
|
|
// // });
|
|
|
|
|
|
|
|
// invalidControls.push({
|
|
|
|
// errors:control.errors,
|
|
|
|
// id: control.get('id')? control.get('id').value: null,
|
|
|
|
// invalidSubControls: [],
|
|
|
|
// key: key
|
|
|
|
// });
|
|
|
|
// }
|
2021-03-01 17:42:18 +01:00
|
|
|
invalidControls.push(...this._getErrors(control)) ;
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-01 17:42:18 +01:00
|
|
|
}
|
|
|
|
});
|
2021-03-04 13:38:46 +01:00
|
|
|
|
2021-03-12 17:19:51 +01:00
|
|
|
/**In case there is an error in a formgroup then the validator probably is custom */
|
|
|
|
if(aControl.errors){
|
|
|
|
invalidControls.push({
|
|
|
|
errors:aControl.errors,
|
|
|
|
id: aControl.get('id')? aControl.get('id').value: null,
|
|
|
|
invalidSubControls: [],
|
|
|
|
key: aControl.get('title')?aControl.get('title').value: null
|
|
|
|
});
|
|
|
|
}
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
break;
|
|
|
|
case 'fa':
|
2021-03-01 17:42:18 +01:00
|
|
|
// const fa = (aControl as FormArray);
|
|
|
|
const ctrls = (aControl as FormArray).controls;
|
2021-04-07 18:03:22 +02:00
|
|
|
const keys_ = Object.keys(ctrls);
|
2021-03-01 17:42:18 +01:00
|
|
|
keys_.forEach(key=>{
|
|
|
|
const control = ctrls[key];
|
|
|
|
if(control.valid) return;
|
|
|
|
|
|
|
|
|
|
|
|
if(control instanceof FormControl){ //for completion purposes. should never run this case
|
|
|
|
const ctrl = control as FormControl;
|
|
|
|
invalidControls.push({
|
|
|
|
errors:ctrl.errors,
|
|
|
|
id: ctrl.get('id')? ctrl.get('id').value: null,
|
|
|
|
invalidSubControls: [],
|
|
|
|
key: key
|
|
|
|
});
|
|
|
|
|
|
|
|
}else{
|
|
|
|
invalidControls.push(... this._getErrors(control));
|
|
|
|
}
|
2021-03-01 10:28:27 +01:00
|
|
|
});
|
2021-03-01 17:42:18 +01:00
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-03-01 17:42:18 +01:00
|
|
|
invalidControls.forEach(e=>{
|
|
|
|
if(!e.id){
|
|
|
|
e.id = aControl.get('id')? aControl.get('id').value : null;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return invalidControls;
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
}
|
2021-04-09 16:05:01 +02:00
|
|
|
userFormDisabled:boolean = false;
|
|
|
|
addUser(email:MatInput){
|
|
|
|
|
|
|
|
// email.focus();
|
|
|
|
if(this.userFormDisabled) return;
|
|
|
|
|
|
|
|
// console.log('user add');
|
|
|
|
if(this.inputUserState === 'triggered'){
|
|
|
|
// this.checkAndAdd(email);
|
2021-04-27 09:38:20 +02:00
|
|
|
|
2021-04-09 16:05:01 +02:00
|
|
|
of(email.value)
|
|
|
|
.pipe(tap(_=> {this.userFormDisabled = true; email.focus()}))
|
|
|
|
.pipe(mergeMap(email=>this.userService.getFromEmail(email)))
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe((result) => {
|
|
|
|
this.userChipList.push(result);
|
|
|
|
this.form.patchValue({'users': this.userChipList});
|
|
|
|
|
|
|
|
email.value = '';
|
|
|
|
this.userFormDisabled = false;
|
2021-07-23 16:03:29 +02:00
|
|
|
this.form.markAsDirty();
|
2021-04-09 16:05:01 +02:00
|
|
|
// email.focus();
|
|
|
|
// this.inputUserState = 'triggered';
|
2021-04-27 09:38:20 +02:00
|
|
|
|
2021-04-09 16:05:01 +02:00
|
|
|
|
|
|
|
},
|
|
|
|
error=>{
|
|
|
|
// console.log(error.message);
|
2021-07-23 13:16:59 +02:00
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-PROFILE-EDITOR.STEPS.GENERAL-INFO.ERRORS.USER-NOT-FOUND'), SnackBarNotificationLevel.Error);
|
2021-04-09 16:05:01 +02:00
|
|
|
this.userFormDisabled = false;
|
|
|
|
// this.inputUserState = 'triggered';//when it loses focus(when disabled) it becomes untriggered
|
|
|
|
// email.focus();
|
|
|
|
});
|
|
|
|
// this.inputUserState = 'untriggered';
|
|
|
|
}else{
|
|
|
|
this.inputUserState = 'triggered';
|
|
|
|
email.focus();
|
2021-04-27 09:38:20 +02:00
|
|
|
|
2021-04-09 16:05:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
onUserButtonFocus(){
|
|
|
|
this._inputUserButton$.next(true);
|
|
|
|
}
|
|
|
|
onUserButtonBlur(){
|
|
|
|
this._inputUserButton$.next(false);
|
|
|
|
}
|
|
|
|
onUserFieldFocus(){
|
|
|
|
this._inputUserField$.next(true);
|
|
|
|
}
|
|
|
|
onUserFieldBlur(){
|
|
|
|
this._inputUserField$.next(false);
|
|
|
|
}
|
|
|
|
|
2021-03-01 10:28:27 +01:00
|
|
|
|
2021-03-27 18:52:53 +01:00
|
|
|
|
|
|
|
//Temporary patch
|
|
|
|
/**
|
|
|
|
* Append custom validators to fields. Some validators are applied on template. In case they are never rendereed,
|
|
|
|
* he form might be valid when it shouldnt.
|
|
|
|
* @param
|
|
|
|
*/
|
|
|
|
private _initializeFormValidity(tocentries: ToCEntry[]) {
|
|
|
|
const fieldsets = this._getAllFieldSets(tocentries);
|
|
|
|
|
|
|
|
try{
|
|
|
|
fieldsets.forEach(fs=>{
|
|
|
|
fs.form.get('title').setValidators(Validators.required);
|
|
|
|
const fieldsF = fs.form.get('fields') as FormArray;
|
|
|
|
if(fieldsF){
|
|
|
|
fieldsF.controls.forEach(field=>{
|
|
|
|
const renderStyleValue = field.get('viewStyle').get('renderStyle').value;
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-27 18:52:53 +01:00
|
|
|
if(renderStyleValue === DatasetProfileFieldViewStyle.CheckBox){
|
2021-04-07 18:03:22 +02:00
|
|
|
field.get('defaultValue').get('value').setValidators(Validators.required);
|
2021-03-27 18:52:53 +01:00
|
|
|
}else if(renderStyleValue === 'combobox'){
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-27 18:52:53 +01:00
|
|
|
const comboType = field.get('data').get('type').value;
|
|
|
|
if(comboType === DatasetProfileComboBoxType.Autocomplete){//As 'Other' in UI
|
|
|
|
field.get('data').setValidators(EditorCustomValidators.atLeastOneElementListValidator('autoCompleteSingleDataList'));
|
|
|
|
}else if(comboType === DatasetProfileComboBoxType.WordList){
|
|
|
|
field.get('data').setValidators(EditorCustomValidators.atLeastOneElementListValidator('options'));
|
|
|
|
}
|
2021-04-07 18:03:22 +02:00
|
|
|
|
2021-03-27 18:52:53 +01:00
|
|
|
}else if(renderStyleValue === DatasetProfileFieldViewStyle.RadioBox){
|
|
|
|
field.get('data').setValidators(EditorCustomValidators.atLeastOneElementListValidator('options'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}catch(e){
|
|
|
|
console.error('Error initializing validators.');
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-07 18:03:22 +02:00
|
|
|
checkAndAdd(ev: any) {
|
|
|
|
this.userService.getFromEmail(ev).pipe(takeUntil(this._destroyed)).subscribe((result) => {
|
|
|
|
this.userChipList.push(result);
|
|
|
|
this.form.patchValue({'users': this.userChipList});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
removeUser(user: any) {
|
|
|
|
this.userChipList.splice(this.userChipList.indexOf(user), 1);
|
|
|
|
this.form.patchValue({'users': this.userChipList});
|
2021-07-23 16:09:12 +02:00
|
|
|
this.form.markAsDirty();//deactivate guard
|
2021-04-07 18:03:22 +02:00
|
|
|
}
|
|
|
|
|
2021-04-09 16:05:01 +02:00
|
|
|
|
|
|
|
verifyAndRemoveUser(user:any){
|
|
|
|
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(approve => {
|
|
|
|
if (approve) {
|
|
|
|
this.removeUser(user);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-13 15:27:29 +02:00
|
|
|
scrollOnTop(){
|
|
|
|
try{
|
|
|
|
const topPage = document.getElementById('main-content');
|
|
|
|
topPage.scrollIntoView({behavior:'smooth'});
|
|
|
|
}catch{
|
|
|
|
console.log('coulnd not scroll');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateAndFinalize(){
|
|
|
|
if(this.form.get('status').value == DatasetProfileEnum.FINALIZED ){
|
|
|
|
//UPDATE FORM
|
|
|
|
if(this.newVersionId){
|
|
|
|
this.onSubmit();
|
|
|
|
}else{
|
|
|
|
this.updateFinalized();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
//finalize
|
|
|
|
this.finalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-04-14 08:57:30 +02:00
|
|
|
discardChanges(){
|
|
|
|
this.router.navigate([
|
|
|
|
'dataset-profiles'
|
|
|
|
]);
|
|
|
|
}
|
2021-04-13 15:27:29 +02:00
|
|
|
|
2021-03-01 17:42:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
interface InvalidControl{
|
|
|
|
key: string,
|
|
|
|
errors: any,
|
|
|
|
id: string,
|
|
|
|
invalidSubControls: InvalidControl[]
|
2021-04-07 18:03:22 +02:00
|
|
|
}
|