diff --git a/dmp-frontend/src/app/ui/admin/dataset-profile/editor/dataset-profile-editor.component.html b/dmp-frontend/src/app/ui/admin/dataset-profile/editor/dataset-profile-editor.component.html index ecae5993f..c6d9198aa 100644 --- a/dmp-frontend/src/app/ui/admin/dataset-profile/editor/dataset-profile-editor.component.html +++ b/dmp-frontend/src/app/ui/admin/dataset-profile/editor/dataset-profile-editor.component.html @@ -81,6 +81,7 @@
+
@@ -88,6 +89,7 @@
+
diff --git a/dmp-frontend/src/app/ui/admin/dataset-profile/editor/dataset-profile-editor.component.ts b/dmp-frontend/src/app/ui/admin/dataset-profile/editor/dataset-profile-editor.component.ts index 79e5da735..4eee5e892 100644 --- a/dmp-frontend/src/app/ui/admin/dataset-profile/editor/dataset-profile-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/dataset-profile/editor/dataset-profile-editor.component.ts @@ -24,6 +24,7 @@ import { DatasetStatus } from '@app/core/common/enum/dataset-status'; import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component'; import { LanguageInfo } from '@app/core/model/language-info'; import { LanguageInfoService } from '@app/core/services/culture/language-info-service'; +import { FormValidationErrorsDialogComponent } from '@common/forms/form-validation-errors-dialog/form-validation-errors-dialog.component'; const skipDisable: any[] = require('../../../../../assets/resources/skipDisable.json'); @@ -47,6 +48,9 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn breadCrumbs: Observable; @ViewChild('stepper', { static: false }) stepper: MatHorizontalStepper; viewOnly = false; + nestedCount: number[] = []; + nestedIndex: number = 0; + errorMessages: string[] = []; constructor( private datasetProfileService: DatasetProfileService, @@ -331,4 +335,66 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn getLanguageInfos(): LanguageInfo[] { return this.languageInfoService.getLanguageInfoValues(); } + + checkFormValidation() { + if (!this.form.valid) { + this.nestedIndex = -1; + this.form.markAllAsTouched(); + this.printErrors(this.form); + this.showValidationErrorsDialog(); + this.nestedCount = []; + this.nestedIndex = 0; + this.errorMessages = []; + } + } + + printErrors(rootform: FormGroup) { + if (!rootform.valid) { + Object.keys(rootform.controls).forEach(key => { + const errors = rootform.get(key).errors; + if (errors !== null) { + let numbering: string = ''; + for (let j = 0; j < this.nestedCount.length; j++) { + numbering += this.nestedCount[j]; + if (j < this.nestedIndex) { + numbering += '.'; + } else { + break; + } + } + Object.keys(errors).forEach(keyError => { + if (typeof errors[keyError] === 'boolean') { + this.errorMessages.push(numbering + ' ' + key + ' is ' + keyError); + } else { + this.errorMessages.push(numbering + ' ' + key + ': ' + keyError + ': ' + errors[keyError]); + } + }); + } else { + if (rootform.get(key) instanceof FormGroup) { + this.printErrors(rootform.get(key)); + } else if (rootform.get(key) instanceof FormArray) { + this.nestedIndex++; + this.nestedCount[this.nestedIndex] = 0; + for (let childForm of (rootform.get(key)).controls) { + this.nestedCount[this.nestedIndex]++; + this.printErrors(childForm); + } + this.nestedCount[this.nestedIndex] = 0; + this.nestedIndex--; + + } + } + }); + } + } + + private showValidationErrorsDialog(projectOnly?: boolean) { + const dialogRef = this.dialog.open(FormValidationErrorsDialogComponent, { + disableClose: true, + data: { + errorMessages: this.errorMessages, + projectOnly: projectOnly + }, + }); + } } diff --git a/dmp-frontend/src/assets/i18n/de.json b/dmp-frontend/src/assets/i18n/de.json index a962ea327..8a9ffb57d 100644 --- a/dmp-frontend/src/assets/i18n/de.json +++ b/dmp-frontend/src/assets/i18n/de.json @@ -371,7 +371,8 @@ "CANCEL": "Cancel", "DELETE": "Delete", "ADD-PAGE": "Add Page +", - "ADD-SECTION": "Add Section +" + "ADD-SECTION": "Add Section +", + "VALIDATE": "Validate" } }, "GRANT-LISTING": { diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index 73e691a34..28dd05a8f 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -391,7 +391,8 @@ "CANCEL": "Cancel", "DELETE": "Delete", "ADD-PAGE": "Add Page +", - "ADD-SECTION": "Add Section +" + "ADD-SECTION": "Add Section +", + "VALIDATE": "Validate" } }, "GRANT-LISTING": { diff --git a/dmp-frontend/src/assets/i18n/es.json b/dmp-frontend/src/assets/i18n/es.json index 5fbec1181..062aca5f2 100644 --- a/dmp-frontend/src/assets/i18n/es.json +++ b/dmp-frontend/src/assets/i18n/es.json @@ -392,7 +392,8 @@ "CANCEL": "Cancelar", "DELETE": "Borrar", "ADD-PAGE": "Añadir página +", - "ADD-SECTION": "Añadir sección +" + "ADD-SECTION": "Añadir sección +", + "VALIDATE": "Validate" } }, "GRANT-LISTING": { diff --git a/dmp-frontend/src/assets/i18n/gr.json b/dmp-frontend/src/assets/i18n/gr.json index a1a93a6ff..023614f32 100644 --- a/dmp-frontend/src/assets/i18n/gr.json +++ b/dmp-frontend/src/assets/i18n/gr.json @@ -389,7 +389,8 @@ "CANCEL": "Ακύρωση", "DELETE": "Διαγραφή", "ADD-PAGE": "Προσθήκη Σελίδας +", - "ADD-SECTION": "Προσθήκη Ενότητας +" + "ADD-SECTION": "Προσθήκη Ενότητας +", + "VALIDATE": "Validate" } }, "GRANT-LISTING": { diff --git a/dmp-frontend/src/assets/i18n/tr.json b/dmp-frontend/src/assets/i18n/tr.json index 3c6306a9b..3f0e94b38 100644 --- a/dmp-frontend/src/assets/i18n/tr.json +++ b/dmp-frontend/src/assets/i18n/tr.json @@ -389,7 +389,8 @@ "CANCEL": "İptal", "DELETE": "Sil", "ADD-PAGE": "Sayfa Ekle +", - "ADD-SECTION": "Bölüm Ekle +" + "ADD-SECTION": "Bölüm Ekle +", + "VALIDATE": "Validate" } }, "GRANT-LISTING": { diff --git a/dmp-frontend/src/common/forms/form-validation-errors-dialog/form-validation-errors-dialog.component.ts b/dmp-frontend/src/common/forms/form-validation-errors-dialog/form-validation-errors-dialog.component.ts index 2e2b31be6..c0d389bbc 100644 --- a/dmp-frontend/src/common/forms/form-validation-errors-dialog/form-validation-errors-dialog.component.ts +++ b/dmp-frontend/src/common/forms/form-validation-errors-dialog/form-validation-errors-dialog.component.ts @@ -17,8 +17,12 @@ export class FormValidationErrorsDialogComponent { @Inject(MAT_DIALOG_DATA) public data: any, private language: TranslateService ) { - this.formGroup = data.formGroup; - this.errorMessages = this.getErrors(this.formGroup); + if (data.formGroup !== undefined && data.formGroup !== null) { + this.formGroup = data.formGroup; + this.errorMessages = this.getErrors(this.formGroup); + } else if (data.errorMessages !== undefined && data.errorMessages !== null) { + this.errorMessages = data.errorMessages; + } } onClose(): void {