From d4db0e204e962098bd5e0f21fe9fc0c65ae54a6a Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Fri, 13 Dec 2019 11:53:43 +0200 Subject: [PATCH] fixed validation issues on dmp wizard --- .../editor/dmp-profile-editor.component.ts | 41 +------ .../contact-content.component.ts | 20 +--- .../ui/grant/editor/grant-editor.component.ts | 42 ++----- .../dmp-editor/dmp-editor-wizard.component.ts | 40 +------ .../funder-editor-wizard.component.html | 11 +- .../funder-editor-wizard.component.ts | 58 ++-------- .../grant-editor-wizard.component.html | 2 +- .../grant-editor-wizard.component.ts | 106 +++++------------- .../quick-wizard-editor.component.html | 8 +- .../quick-wizard-editor.component.ts | 40 +------ .../sidebar-footer.component.html | 18 +-- .../sidebar-footer.component.ts | 24 +--- 12 files changed, 91 insertions(+), 319 deletions(-) diff --git a/dmp-frontend/src/app/ui/admin/dmp-profile/editor/dmp-profile-editor.component.ts b/dmp-frontend/src/app/ui/admin/dmp-profile/editor/dmp-profile-editor.component.ts index 51fe8a1c7..b7cf3cdd0 100644 --- a/dmp-frontend/src/app/ui/admin/dmp-profile/editor/dmp-profile-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/dmp-profile/editor/dmp-profile-editor.component.ts @@ -1,6 +1,6 @@ import { AfterViewInit, Component } from '@angular/core'; -import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms'; +import { FormArray, FormGroup } from '@angular/forms'; import { ActivatedRoute, Params, Router } from '@angular/router'; import { DmpProfileFieldDataType } from '@app/core/common/enum/dmp-profile-field-type'; import { DmpProfileStatus } from '@app/core/common/enum/dmp-profile-status'; @@ -13,6 +13,7 @@ import { DmpProfileEditorModel, DmpProfileFieldEditorModel } from '@app/ui/admin import { DmpProfileExternalAutoCompleteFieldDataEditorModel } from '@app/ui/admin/dmp-profile/editor/external-autocomplete/dmp-profile-external-autocomplete-field-editor.model'; import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item'; import { BaseComponent } from '@common/base/base.component'; +import { FormService } from '@common/forms/form-service'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; import { TranslateService } from '@ngx-translate/core'; import { environment } from 'environments/environment'; @@ -42,7 +43,8 @@ export class DmpProfileEditorComponent extends BaseComponent implements AfterVie private router: Router, private language: TranslateService, private enumUtils: EnumUtils, - private uiNotificationService: UiNotificationService + private uiNotificationService: UiNotificationService, + private formService: FormService ) { super(); } @@ -86,7 +88,7 @@ export class DmpProfileEditorComponent extends BaseComponent implements AfterVie } formSubmit(): void { - this.touchAllFormFields(this.formGroup); + this.formService.touchAllFormFields(this.formGroup); if (!this.isFormValid()) { return; } this.onSubmit(); } @@ -111,7 +113,7 @@ export class DmpProfileEditorComponent extends BaseComponent implements AfterVie onCallbackError(errorResponse: any) { this.setErrorModel(errorResponse.error); - this.validateAllFormFields(this.formGroup); + this.formService.validateAllFormFields(this.formGroup); } public setErrorModel(validationErrorModel: ValidationErrorModel) { @@ -124,37 +126,6 @@ export class DmpProfileEditorComponent extends BaseComponent implements AfterVie this.router.navigate(['/dmp-profiles']); } - - public touchAllFormFields(formControl: AbstractControl) { - if (formControl instanceof FormControl) { - formControl.markAsTouched(); - } else if (formControl instanceof FormGroup) { - Object.keys(formControl.controls).forEach(item => { - const control = formControl.get(item); - this.touchAllFormFields(control); - }); - } else if (formControl instanceof FormArray) { - formControl.controls.forEach(item => { - this.touchAllFormFields(item); - }); - } - } - - public validateAllFormFields(formControl: AbstractControl) { - if (formControl instanceof FormControl) { - formControl.updateValueAndValidity({ emitEvent: false }); - } else if (formControl instanceof FormGroup) { - Object.keys(formControl.controls).forEach(item => { - const control = formControl.get(item); - this.validateAllFormFields(control); - }); - } else if (formControl instanceof FormArray) { - formControl.controls.forEach(item => { - this.validateAllFormFields(item); - }); - } - } - addField() { (this.formGroup.get('definition').get('fields')).push(new DmpProfileFieldEditorModel().buildForm()); } diff --git a/dmp-frontend/src/app/ui/contact/contact-content/contact-content.component.ts b/dmp-frontend/src/app/ui/contact/contact-content/contact-content.component.ts index b1275e92a..207cc3848 100644 --- a/dmp-frontend/src/app/ui/contact/contact-content/contact-content.component.ts +++ b/dmp-frontend/src/app/ui/contact/contact-content/contact-content.component.ts @@ -8,6 +8,7 @@ import { BaseComponent } from '@common/base/base.component'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; import { TranslateService } from '@ngx-translate/core'; import { takeUntil } from 'rxjs/operators'; +import { FormService } from '@common/forms/form-service'; @Component({ selector: 'app-contact-content', @@ -26,6 +27,7 @@ export class ContactContentComponent extends BaseComponent implements OnInit { private _location: Location, private uiNotificationService: UiNotificationService, private language: TranslateService, + private formService: FormService ) { super(); } @@ -59,7 +61,7 @@ export class ContactContentComponent extends BaseComponent implements OnInit { onCallbackError(errorResponse: any) { this.setErrorModel(errorResponse.error); - this.validateAllFormFields(this.formGroup); + this.formService.validateAllFormFields(this.formGroup); this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-EMAIL-SEND'), SnackBarNotificationLevel.Error); } @@ -68,20 +70,4 @@ export class ContactContentComponent extends BaseComponent implements OnInit { (this.contactEmailFormModel.validationErrorModel)[item] = (validationErrorModel)[item]; }); } - - public validateAllFormFields(formControl: AbstractControl) { - if (formControl instanceof FormControl) { - formControl.updateValueAndValidity({ emitEvent: false }); - } else if (formControl instanceof FormGroup) { - Object.keys(formControl.controls).forEach(item => { - const control = formControl.get(item); - this.validateAllFormFields(control); - }); - } else if (formControl instanceof FormArray) { - formControl.controls.forEach(item => { - this.validateAllFormFields(item); - }); - } - } - } diff --git a/dmp-frontend/src/app/ui/grant/editor/grant-editor.component.ts b/dmp-frontend/src/app/ui/grant/editor/grant-editor.component.ts index 6310ae2da..428cf5a1d 100644 --- a/dmp-frontend/src/app/ui/grant/editor/grant-editor.component.ts +++ b/dmp-frontend/src/app/ui/grant/editor/grant-editor.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms'; +import { FormGroup } from '@angular/forms'; import { MatDialog } from '@angular/material/dialog'; import { MatSnackBar } from '@angular/material/snack-bar'; import { ActivatedRoute, Params, Router } from '@angular/router'; @@ -9,12 +9,13 @@ import { GrantListingModel } from '@app/core/model/grant/grant-listing'; import { GrantFileUploadService } from '@app/core/services/grant/grant-file-upload.service'; import { GrantService } from '@app/core/services/grant/grant.service'; import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; -import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component'; import { GrantEditorModel } from '@app/ui/grant/editor/grant-editor.model'; import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item'; import { IBreadCrumbComponent } from '@app/ui/misc/breadcrumb/definition/IBreadCrumbComponent'; import { BaseComponent } from '@common/base/base.component'; +import { FormService } from '@common/forms/form-service'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; +import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component'; import { TranslateService } from '@ngx-translate/core'; import { environment } from 'environments/environment'; import { Observable, of as observableOf } from 'rxjs'; @@ -44,7 +45,8 @@ export class GrantEditorComponent extends BaseComponent implements OnInit, IBrea public language: TranslateService, private dialog: MatDialog, private grantFileUploadService: GrantFileUploadService, - private uiNotificationService: UiNotificationService + private uiNotificationService: UiNotificationService, + private formService: FormService ) { super(); } @@ -100,7 +102,7 @@ export class GrantEditorComponent extends BaseComponent implements OnInit, IBrea } formSubmit(): void { - this.touchAllFormFields(this.formGroup); + this.formService.touchAllFormFields(this.formGroup); if (!this.isFormValid()) { return; } this.onSubmit(); } @@ -125,7 +127,7 @@ export class GrantEditorComponent extends BaseComponent implements OnInit, IBrea onCallbackError(errorResponse: any) { this.setErrorModel(errorResponse.error.payload); - this.validateAllFormFields(this.formGroup); + this.formService.validateAllFormFields(this.formGroup); } public setErrorModel(validationErrorModel: ValidationErrorModel) { @@ -161,36 +163,6 @@ export class GrantEditorComponent extends BaseComponent implements OnInit, IBrea }); } - public touchAllFormFields(formControl: AbstractControl) { - if (formControl instanceof FormControl) { - formControl.markAsTouched(); - } else if (formControl instanceof FormGroup) { - Object.keys(formControl.controls).forEach(item => { - const control = formControl.get(item); - this.touchAllFormFields(control); - }); - } else if (formControl instanceof FormArray) { - formControl.controls.forEach(item => { - this.touchAllFormFields(item); - }); - } - } - - public validateAllFormFields(formControl: AbstractControl) { - if (formControl instanceof FormControl) { - formControl.updateValueAndValidity({ emitEvent: false }); - } else if (formControl instanceof FormGroup) { - Object.keys(formControl.controls).forEach(item => { - const control = formControl.get(item); - this.validateAllFormFields(control); - }); - } else if (formControl instanceof FormArray) { - formControl.controls.forEach(item => { - this.validateAllFormFields(item); - }); - } - } - public enableForm() { if (!this.isExternalGrant()) { this.editMode = true; diff --git a/dmp-frontend/src/app/ui/quick-wizard/dmp-editor/dmp-editor-wizard.component.ts b/dmp-frontend/src/app/ui/quick-wizard/dmp-editor/dmp-editor-wizard.component.ts index 4674857d6..99d898a15 100644 --- a/dmp-frontend/src/app/ui/quick-wizard/dmp-editor/dmp-editor-wizard.component.ts +++ b/dmp-frontend/src/app/ui/quick-wizard/dmp-editor/dmp-editor-wizard.component.ts @@ -1,6 +1,6 @@ import { Component, Input, OnInit } from '@angular/core'; -import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms'; +import { FormArray, FormGroup } from '@angular/forms'; import { MatSnackBar } from '@angular/material/snack-bar'; import { ActivatedRoute, Router } from '@angular/router'; import { DatasetProfileModel } from '@app/core/model/dataset/dataset-profile'; @@ -12,6 +12,7 @@ import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/sing import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item'; import { IBreadCrumbComponent } from '@app/ui/misc/breadcrumb/definition/IBreadCrumbComponent'; import { BaseComponent } from '@common/base/base.component'; +import { FormService } from '@common/forms/form-service'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; import { TranslateService } from '@ngx-translate/core'; import { Observable, of as observableOf } from 'rxjs'; @@ -44,7 +45,8 @@ export class DmpEditorWizardComponent extends BaseComponent implements OnInit, I public router: Router, private route: ActivatedRoute, private _service: DmpService, - public language: TranslateService + public language: TranslateService, + private formService: FormService ) { super(); } @@ -74,7 +76,7 @@ export class DmpEditorWizardComponent extends BaseComponent implements OnInit, I } formSubmit(): void { - this.touchAllFormFields(this.formGroup); + this.formService.touchAllFormFields(this.formGroup); if (!this.isFormValid()) { return; } this.onSubmit(); } @@ -83,21 +85,6 @@ export class DmpEditorWizardComponent extends BaseComponent implements OnInit, I return this.formGroup.valid; } - public touchAllFormFields(formControl: AbstractControl) { - if (formControl instanceof FormControl) { - formControl.markAsTouched(); - } else if (formControl instanceof FormGroup) { - Object.keys(formControl.controls).forEach(item => { - const control = formControl.get(item); - this.touchAllFormFields(control); - }); - } else if (formControl instanceof FormArray) { - formControl.controls.forEach(item => { - this.touchAllFormFields(item); - }); - } - } - onSubmit(): void { // this.grantService.createGrant(this.formGroup.value) // .pipe(takeUntil(this._destroyed)) @@ -115,7 +102,7 @@ export class DmpEditorWizardComponent extends BaseComponent implements OnInit, I onCallbackError(errorResponse: any) { this.setErrorModel(errorResponse.error.payload); - this.validateAllFormFields(this.formGroup); + this.formService.validateAllFormFields(this.formGroup); } public setErrorModel(validationErrorModel: ValidationErrorModel) { @@ -124,21 +111,6 @@ export class DmpEditorWizardComponent extends BaseComponent implements OnInit, I }); } - public validateAllFormFields(formControl: AbstractControl) { - if (formControl instanceof FormControl) { - formControl.updateValueAndValidity({ emitEvent: false }); - } else if (formControl instanceof FormGroup) { - Object.keys(formControl.controls).forEach(item => { - const control = formControl.get(item); - this.validateAllFormFields(control); - }); - } else if (formControl instanceof FormArray) { - formControl.controls.forEach(item => { - this.validateAllFormFields(item); - }); - } - } - filterProfiles(value: string): Observable { this.filteredProfiles = undefined; diff --git a/dmp-frontend/src/app/ui/quick-wizard/funder-editor/funder-editor-wizard.component.html b/dmp-frontend/src/app/ui/quick-wizard/funder-editor/funder-editor-wizard.component.html index b4606ff50..80acc2f60 100644 --- a/dmp-frontend/src/app/ui/quick-wizard/funder-editor/funder-editor-wizard.component.html +++ b/dmp-frontend/src/app/ui/quick-wizard/funder-editor/funder-editor-wizard.component.html @@ -6,20 +6,19 @@

{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.FIRST-STEP.ABOUT-FUNDER' | translate}}

- + {{'DMP-EDITOR.FIELDS.EXTERNAL-SOURCE-HINT' | translate}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}}

{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.FIRST-STEP.ABOUT-NEW-FUNDER' | translate}}

- - - {{funderFormGroup.get('label').getError('backendError').message}} - - {{'GENERAL.VALIDATION.REQUIRED' | translate}} + + {{funderFormGroup.get('label').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}}
diff --git a/dmp-frontend/src/app/ui/quick-wizard/funder-editor/funder-editor-wizard.component.ts b/dmp-frontend/src/app/ui/quick-wizard/funder-editor/funder-editor-wizard.component.ts index 45334e50a..9fb39f429 100644 --- a/dmp-frontend/src/app/ui/quick-wizard/funder-editor/funder-editor-wizard.component.ts +++ b/dmp-frontend/src/app/ui/quick-wizard/funder-editor/funder-editor-wizard.component.ts @@ -1,11 +1,12 @@ -import { Component, OnInit, Input } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; import { FormGroup } from '@angular/forms'; -import { SingleAutoCompleteConfiguration } from '../../../library/auto-complete/single/single-auto-complete-configuration'; -import { FunderService } from '../../../core/services/funder/funder.service'; -import { RequestItem } from '../../../core/query/request-item'; -import { FunderCriteria } from '../../../core/query/funder/funder-criteria'; -import { FunderFormModel } from '../../dmp/editor/grant-tab/funder-form-model'; +import { FunderModel } from '@app/core/model/funder/funder'; import { TranslateService } from '@ngx-translate/core'; +import { FunderCriteria } from '../../../core/query/funder/funder-criteria'; +import { RequestItem } from '../../../core/query/request-item'; +import { FunderService } from '../../../core/services/funder/funder.service'; +import { SingleAutoCompleteConfiguration } from '../../../library/auto-complete/single/single-auto-complete-configuration'; +import { FunderFormModel } from '../../dmp/editor/grant-tab/funder-form-model'; @Component({ selector: 'app-quick-wizard-funder-editor-component', @@ -18,7 +19,6 @@ export class FunderEditorWizardComponent implements OnInit { funder: FunderFormModel; funderLabelCleared = true; @Input() funderFormGroup: FormGroup; - @Input() grantformGroup: FormGroup; funderAutoCompleteConfiguration: SingleAutoCompleteConfiguration; constructor( @@ -55,51 +55,13 @@ export class FunderEditorWizardComponent implements OnInit { create() { this.isNew = !this.isNew; if (this.isNew) { - this.funderFormGroup.get('existFunder').disable(); this.funderFormGroup.get('existFunder').reset(); + this.funderFormGroup.get('existFunder').disable(); this.funderFormGroup.get('label').enable(); } else { - this.funderFormGroup.get('existFunder').enable(); - this.funderFormGroup.get('label').disable(); this.funderFormGroup.get('label').reset(); + this.funderFormGroup.get('label').disable(); + this.funderFormGroup.get('existFunder').enable(); } } - - onFunderSelected() { - if (this.grantformGroup.get('existGrant').disabled) { - this.grantformGroup.get('existGrant').enable(); - this.grantformGroup.get('label').disable(); - this.grantformGroup.get('description').disable(); - } else { - this.grantformGroup.get('existGrant').disable(); - this.grantformGroup.get('label').enable(); - this.grantformGroup.get('description').enable(); - } - } - - onFunderRemoved() { - if (this.grantformGroup.get('existGrant').enabled) { - this.grantformGroup.get('existGrant').disable(); - this.grantformGroup.get('existGrant').reset(); - this.grantformGroup.get('label').enable(); - this.grantformGroup.get('description').enable(); - } else { - this.grantformGroup.get('existGrant').enable(); - this.grantformGroup.get('label').disable(); - this.grantformGroup.get('label').reset(); - this.grantformGroup.get('description').disable(); - this.grantformGroup.get('description').reset(); - } - } - - controlModified(event: any) { - if (event && this.funderLabelCleared) { - this.funderLabelCleared = false; - this.onFunderSelected(); - } else if (!event) { - this.funderLabelCleared = true; - this.onFunderRemoved(); - } - } - } diff --git a/dmp-frontend/src/app/ui/quick-wizard/grant-editor/grant-editor-wizard.component.html b/dmp-frontend/src/app/ui/quick-wizard/grant-editor/grant-editor-wizard.component.html index 2b4d9e1b0..f55f3f3c1 100644 --- a/dmp-frontend/src/app/ui/quick-wizard/grant-editor/grant-editor-wizard.component.html +++ b/dmp-frontend/src/app/ui/quick-wizard/grant-editor/grant-editor-wizard.component.html @@ -10,7 +10,7 @@

{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.FIRST-STEP.ABOUT-GRANT' | translate}}

- + {{'DMP-EDITOR.FIELDS.EXTERNAL-SOURCE-HINT' | translate}} diff --git a/dmp-frontend/src/app/ui/quick-wizard/grant-editor/grant-editor-wizard.component.ts b/dmp-frontend/src/app/ui/quick-wizard/grant-editor/grant-editor-wizard.component.ts index c1a605c8a..de9f7f666 100644 --- a/dmp-frontend/src/app/ui/quick-wizard/grant-editor/grant-editor-wizard.component.ts +++ b/dmp-frontend/src/app/ui/quick-wizard/grant-editor/grant-editor-wizard.component.ts @@ -12,9 +12,11 @@ import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-it import { IBreadCrumbComponent } from '@app/ui/misc/breadcrumb/definition/IBreadCrumbComponent'; import { GrantEditorWizardModel } from '@app/ui/quick-wizard/grant-editor/grant-editor-wizard-model'; import { BaseComponent } from '@common/base/base.component'; +import { FormService } from '@common/forms/form-service'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; import { TranslateService } from '@ngx-translate/core'; import { Observable, of as observableOf } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; @Component({ selector: 'app-quick-wizard-grant-editor-component', @@ -36,7 +38,8 @@ export class GrantEditorWizardComponent extends BaseComponent implements OnInit, public snackBar: MatSnackBar, public router: Router, public language: TranslateService, - private grantService: GrantService + private grantService: GrantService, + private formService: FormService ) { super(); } @@ -59,12 +62,7 @@ export class GrantEditorWizardComponent extends BaseComponent implements OnInit, subtitleFn: (item) => item['source'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['source'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') }; - if (!this.grantformGroup) { - this.grant = new GrantEditorWizardModel(); - this.grantformGroup = this.grant.buildForm(); - } - - if (this.funderFormGroup && this.funderFormGroup.get('funder')) { + if (this.funderFormGroup && this.funderFormGroup.valid) { this.grantformGroup.get('existGrant').enable(); this.grantformGroup.get('label').disable(); this.grantformGroup.get('description').disable(); @@ -72,55 +70,29 @@ export class GrantEditorWizardComponent extends BaseComponent implements OnInit, this.grantformGroup.get('existGrant').disable(); } - // this.route.params - // .pipe(takeUntil(this._destroyed)) - // .subscribe((params: Params) => { - // const itemId = params['id']; + this.funderFormGroup.statusChanges.pipe(takeUntil(this._destroyed)).subscribe(x => { + if (x == 'INVALID') { + this.grantformGroup.get('existGrant').reset(); + this.grantformGroup.get('label').reset(); + this.grantformGroup.get('description').reset(); + this.grantformGroup.get('existGrant').disable(); + this.grantformGroup.get('label').disable(); + this.grantformGroup.get('description').disable(); + } else if (x == 'VALID') { + if (!this.isNew) { + this.grantformGroup.get('label').reset(); + this.grantformGroup.get('description').reset(); + this.grantformGroup.get('label').disable(); + this.grantformGroup.get('description').disable(); + this.grantformGroup.get('existGrant').enable(); - // if (itemId != null) { - // this.isNew = false; - // this.grantService.getSingle(itemId).map(data => data as GrantListingModel) - // .pipe(takeUntil(this._destroyed)) - // .subscribe(data => { - // this.grant = new GrantEditorModel().fromModel(data); - // this.formGroup = this.grant.buildForm(null, this.grant.type === GrantType.External || !this.editMode); - // this.breadCrumbs = Observable.of([ - // { parentComponentName: 'GrantListingComponent', label: 'Grants', url: '/grants' }, - // ]); - // }); - // } else { - // this.breadCrumbs = Observable.of([ - // { parentComponentName: 'QuickWizardComponent', label: 'Grants', url: '/grants' }, - // ]); - // this.grant = new GrantEditorWizardModel(); - // setTimeout(() => { - // this.formGroup = this.grant.buildForm(); - // }); - // } - // }); - } - - public isFormValid() { - return this.grantformGroup.valid; + } + } + }) } isFunderFormInvalid() { - return !this.funderFormGroup.get('existFunder').value && !this.funderFormGroup.get('label').valid; - } - - public touchAllFormFields(formControl: AbstractControl) { - if (formControl instanceof FormControl) { - formControl.markAsTouched(); - } else if (formControl instanceof FormGroup) { - Object.keys(formControl.controls).forEach(item => { - const control = formControl.get(item); - this.touchAllFormFields(control); - }); - } else if (formControl instanceof FormArray) { - formControl.controls.forEach(item => { - this.touchAllFormFields(item); - }); - } + return !this.funderFormGroup.valid; } onCallbackSuccess(): void { @@ -130,7 +102,7 @@ export class GrantEditorWizardComponent extends BaseComponent implements OnInit, onCallbackError(errorResponse: any) { this.setErrorModel(errorResponse.error.payload); - this.validateAllFormFields(this.grantformGroup); + this.formService.validateAllFormFields(this.grantformGroup); } public setErrorModel(validationErrorModel: ValidationErrorModel) { @@ -139,21 +111,6 @@ export class GrantEditorWizardComponent extends BaseComponent implements OnInit, }); } - public validateAllFormFields(formControl: AbstractControl) { - if (formControl instanceof FormControl) { - formControl.updateValueAndValidity({ emitEvent: false }); - } else if (formControl instanceof FormGroup) { - Object.keys(formControl.controls).forEach(item => { - const control = formControl.get(item); - this.validateAllFormFields(control); - }); - } else if (formControl instanceof FormArray) { - formControl.controls.forEach(item => { - this.validateAllFormFields(item); - }); - } - } - searchGrant(query: string) { const grantRequestItem: RequestItem = new RequestItem(); grantRequestItem.criteria = new GrantCriteria(); @@ -167,21 +124,16 @@ export class GrantEditorWizardComponent extends BaseComponent implements OnInit, create() { this.isNew = !this.isNew; if (this.isNew) { - this.grantformGroup.get('existGrant').disable(); this.grantformGroup.get('existGrant').reset(); + this.grantformGroup.get('existGrant').disable(); this.grantformGroup.get('label').enable(); this.grantformGroup.get('description').enable(); } else { - this.grantformGroup.get('existGrant').enable(); - this.grantformGroup.get('label').disable(); this.grantformGroup.get('label').reset(); - this.grantformGroup.get('description').disable(); + this.grantformGroup.get('label').disable(); this.grantformGroup.get('description').reset(); + this.grantformGroup.get('description').disable(); + this.grantformGroup.get('existGrant').enable(); } } - - onGrantSelected() { - this.grantformGroup.get('label').disable(); - this.grantformGroup.get('description').disable(); - } } diff --git a/dmp-frontend/src/app/ui/quick-wizard/quick-wizard-editor/quick-wizard-editor.component.html b/dmp-frontend/src/app/ui/quick-wizard/quick-wizard-editor/quick-wizard-editor.component.html index 8b3a7c7c9..a240ffbc1 100644 --- a/dmp-frontend/src/app/ui/quick-wizard/quick-wizard-editor/quick-wizard-editor.component.html +++ b/dmp-frontend/src/app/ui/quick-wizard/quick-wizard-editor/quick-wizard-editor.component.html @@ -6,11 +6,11 @@

{{ 'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.POST-SELECTION-INFO' | translate }}

- + {{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.FIRST-STEP.TITLE' | translate}} - +
@@ -19,7 +19,7 @@
- + {{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.SECOND-STEP.TITLE' | translate}} @@ -36,7 +36,7 @@
- + {{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.THIRD-STEP.TITLE' | translate}} diff --git a/dmp-frontend/src/app/ui/quick-wizard/quick-wizard-editor/quick-wizard-editor.component.ts b/dmp-frontend/src/app/ui/quick-wizard/quick-wizard-editor/quick-wizard-editor.component.ts index 2867109dc..35800d86f 100644 --- a/dmp-frontend/src/app/ui/quick-wizard/quick-wizard-editor/quick-wizard-editor.component.ts +++ b/dmp-frontend/src/app/ui/quick-wizard/quick-wizard-editor/quick-wizard-editor.component.ts @@ -10,7 +10,6 @@ import { DmpStatus } from '@app/core/common/enum/dmp-status'; import { DatasetService } from '@app/core/services/dataset/dataset.service'; import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; import { QuickWizardService } from '@app/core/services/quick-wizard/quick-wizard.service'; -import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component'; import { CheckDeactivateBaseComponent } from '@app/library/deactivate/deactivate.component'; import { DmpFinalizeDialogComponent, DmpFinalizeDialogDataset, DmpFinalizeDialogInput } from '@app/ui/dmp/editor/dmp-finalize-dialog/dmp-finalize-dialog.component'; import { FunderFormModel } from '@app/ui/dmp/editor/grant-tab/funder-form-model'; @@ -20,7 +19,9 @@ import { IBreadCrumbComponent } from '@app/ui/misc/breadcrumb/definition/IBreadC import { DatasetEditorWizardComponent } from '@app/ui/quick-wizard/dataset-editor/dataset-editor-wizard.component'; import { GrantEditorWizardModel } from '@app/ui/quick-wizard/grant-editor/grant-editor-wizard-model'; import { QuickWizardEditorWizardModel } from '@app/ui/quick-wizard/quick-wizard-editor/quick-wizard-editor.model'; +import { FormService } from '@common/forms/form-service'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; +import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component'; import { TranslateService } from '@ngx-translate/core'; import { Observable, of as observableOf } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -48,7 +49,8 @@ export class QuickWizardEditorComponent extends CheckDeactivateBaseComponent imp public datasetService: DatasetService, public quickWizardService: QuickWizardService, private uiNotificationService: UiNotificationService, - private dialog: MatDialog + private dialog: MatDialog, + private formService: FormService ) { super(); } @@ -82,7 +84,7 @@ export class QuickWizardEditorComponent extends CheckDeactivateBaseComponent imp } formSubmit(): void { - this.touchAllFormFields(this.formGroup); + this.formService.touchAllFormFields(this.formGroup); if (this.formGroup.get('datasets') && this.formGroup.get('datasets').get('datasetsList') && (this.formGroup.get('datasets').get('datasetsList') as FormArray).length > 0) { for (let control of (this.formGroup.get('datasets').get('datasetsList') as FormArray).controls) { control.get('status').setValue(DatasetStatus.Draft); @@ -137,21 +139,6 @@ export class QuickWizardEditorComponent extends CheckDeactivateBaseComponent imp return this.formGroup.get('grant').valid && this.formGroup.get('funder').valid; } - public touchAllFormFields(formControl: AbstractControl) { - if (formControl instanceof FormControl) { - formControl.markAsTouched(); - } else if (formControl instanceof FormGroup) { - Object.keys(formControl.controls).forEach(item => { - const control = formControl.get(item); - this.touchAllFormFields(control); - }); - } else if (formControl instanceof FormArray) { - formControl.controls.forEach(item => { - this.touchAllFormFields(item); - }); - } - } - onSubmitSaveAndFinalize() { this.quickWizardService.createQuickWizard(this.formGroup.getRawValue()) .pipe(takeUntil(this._destroyed)) @@ -192,7 +179,7 @@ export class QuickWizardEditorComponent extends CheckDeactivateBaseComponent imp onCallbackError(errorResponse: any) { this.setErrorModel(errorResponse.error.payload); - this.validateAllFormFields(this.formGroup); + this.formService.validateAllFormFields(this.formGroup); } public setErrorModel(validationErrorModel: ValidationErrorModel) { @@ -201,21 +188,6 @@ export class QuickWizardEditorComponent extends CheckDeactivateBaseComponent imp }); } - public validateAllFormFields(formControl: AbstractControl) { - if (formControl instanceof FormControl) { - formControl.updateValueAndValidity({ emitEvent: false }); - } else if (formControl instanceof FormGroup) { - Object.keys(formControl.controls).forEach(item => { - const control = formControl.get(item); - this.validateAllFormFields(control); - }); - } else if (formControl instanceof FormArray) { - formControl.controls.forEach(item => { - this.validateAllFormFields(item); - }); - } - } - getGrantLabel(): string { if (this.formGroup.get('grant').get('existGrant').value) { return this.formGroup.get('grant').get('existGrant').value['label']; diff --git a/dmp-frontend/src/app/ui/sidebar/sidebar-footer/sidebar-footer.component.html b/dmp-frontend/src/app/ui/sidebar/sidebar-footer/sidebar-footer.component.html index d9e66567b..ba92feae2 100644 --- a/dmp-frontend/src/app/ui/sidebar/sidebar-footer/sidebar-footer.component.html +++ b/dmp-frontend/src/app/ui/sidebar/sidebar-footer/sidebar-footer.component.html @@ -8,32 +8,32 @@ Help
-->
-
+

{{'FOOTER.GLOSSARY' | translate}}

-
+

{{'FOOTER.FAQ' | translate}}

-
+
+
+

{{'FOOTER.CONTACT-SUPPORT' | translate}}

-
-
-
+ -
+ + {{'FOOTER.PRIVACY-POLICY' | translate}} -
+
-->
diff --git a/dmp-frontend/src/app/ui/sidebar/sidebar-footer/sidebar-footer.component.ts b/dmp-frontend/src/app/ui/sidebar/sidebar-footer/sidebar-footer.component.ts index ac594671b..fcab57335 100644 --- a/dmp-frontend/src/app/ui/sidebar/sidebar-footer/sidebar-footer.component.ts +++ b/dmp-frontend/src/app/ui/sidebar/sidebar-footer/sidebar-footer.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from '@angular/core'; -import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms'; +import { FormGroup } from '@angular/forms'; import { MatDialog } from '@angular/material/dialog'; import { Router } from '@angular/router'; import { ContactEmailFormModel } from '@app/core/model/contact/contact-email-form-model'; @@ -9,6 +9,7 @@ import { ContactDialogComponent } from '@app/ui/contact/contact-dialog/contact-d import { FaqDialogComponent } from '@app/ui/faq/dialog/faq-dialog.component'; import { GlossaryDialogComponent } from '@app/ui/glossary/dialog/glossary-dialog.component'; import { BaseComponent } from '@common/base/base.component'; +import { FormService } from '@common/forms/form-service'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; import { TranslateService } from '@ngx-translate/core'; import { takeUntil } from 'rxjs/operators'; @@ -28,7 +29,8 @@ export class SidebarFooterComponent extends BaseComponent implements OnInit { private language: TranslateService, public router: Router, private contactSupportService: ContactSupportService, - private uiNotificationService: UiNotificationService + private uiNotificationService: UiNotificationService, + private formService: FormService ) { super(); } @@ -99,7 +101,7 @@ export class SidebarFooterComponent extends BaseComponent implements OnInit { onCallbackError(errorResponse: any) { this.setErrorModel(errorResponse.error); - this.validateAllFormFields(this.formGroup); + this.formService.validateAllFormFields(this.formGroup); this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-EMAIL-SEND'), SnackBarNotificationLevel.Error); } @@ -108,20 +110,4 @@ export class SidebarFooterComponent extends BaseComponent implements OnInit { (this.contactEmailFormModel.validationErrorModel)[item] = (validationErrorModel)[item]; }); } - - public validateAllFormFields(formControl: AbstractControl) { - if (formControl instanceof FormControl) { - formControl.updateValueAndValidity({ emitEvent: false }); - } else if (formControl instanceof FormGroup) { - Object.keys(formControl.controls).forEach(item => { - const control = formControl.get(item); - this.validateAllFormFields(control); - }); - } else if (formControl instanceof FormArray) { - formControl.controls.forEach(item => { - this.validateAllFormFields(item); - }); - } - } - }