This commit is contained in:
apapachristou 2020-09-23 10:19:09 +03:00
commit 7897d9072d
9 changed files with 108 additions and 15 deletions

View File

@ -81,6 +81,7 @@
<!-- SAVE BUTTON -->
<div class="col-6 d-flex" *ngIf="!viewOnly">
<div class="row mt-4">
<button mat-raised-button class="col-auto mr-2" color="primary" type="button col-auto" (click)='checkFormValidation()' [disabled]="form.valid">{{'DATASET-PROFILE-EDITOR.ACTIONS.VALIDATE' | translate}}</button>
<button mat-raised-button class="col-auto mr-2" color="primary" type="button col-auto" (click)='onSubmit()' [disabled]="!form.valid">{{'DATASET-PROFILE-EDITOR.ACTIONS.SAVE' | translate}}</button>
<button mat-raised-button class="col-auto" color="primary" type="button col-auto" (click)='finalize()' [disabled]="!form.valid">{{'DATASET-PROFILE-EDITOR.ACTIONS.FINALIZE' | translate}}</button>
</div>
@ -88,6 +89,7 @@
<!-- SAVE BUTTON WHEN FINALIZED-->
<div class="col-6 d-flex" *ngIf="showUpdateButton()">
<div class="row mt-4">
<button mat-raised-button class="col-auto mr-2" color="primary" type="button col-auto" (click)='checkFormValidation()' [disabled]="form.valid">{{'DATASET-PROFILE-EDITOR.ACTIONS.VALIDATE' | translate}}</button>
<button mat-raised-button class="col-auto mr-2" color="primary" type="button col-auto" (click)='updateFinalized()' [disabled]="!form.valid">{{'DATASET-PROFILE-EDITOR.ACTIONS.UPDATE' | translate}}</button>
</div>
</div>

View File

@ -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<BreadcrumbItem[]>;
@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(<FormGroup>rootform.get(key));
} else if (rootform.get(key) instanceof FormArray) {
this.nestedIndex++;
this.nestedCount[this.nestedIndex] = 0;
for (let childForm of (<FormArray>rootform.get(key)).controls) {
this.nestedCount[this.nestedIndex]++;
this.printErrors(<any>childForm);
}
this.nestedCount[this.nestedIndex] = 0;
this.nestedIndex--;
}
}
});
}
}
private showValidationErrorsDialog(projectOnly?: boolean) {
const dialogRef = this.dialog.open(FormValidationErrorsDialogComponent, {
disableClose: true,
data: {
errorMessages: this.errorMessages,
projectOnly: projectOnly
},
});
}
}

View File

@ -44,7 +44,7 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
// @Input() field: Field;
@Input() form: FormGroup;
@Input() datasetProfileId: String;
@Input() datasetProfileId: any;
@Input() isChild: Boolean = false;
// change: Subscription;
@ -96,12 +96,17 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
if (this.form.get('viewStyle').value.renderStyle === DatasetProfileFieldViewStyle.ComboBox && this.form.get('data').value.type === DatasetProfileComboBoxType.WordList) {
if (this.form.get('data').value.multiList) {
const originalValue = <string>this.form.get('value').value;
let values = (<string>this.form.get('value').value).slice(1, -1).split(', ');
if (!originalValue.startsWith('[') && !originalValue.endsWith(']')) {
values = undefined;
values = [originalValue];
if (originalValue !== null && typeof originalValue === 'string') {
let values = (<string>this.form.get('value').value).slice(1, -1).split(', ');
if (!originalValue.startsWith('[') && !originalValue.endsWith(']')) {
values = undefined;
values = [originalValue];
}
this.form.patchValue({ 'value': values });
values.forEach(element => {
this.visibilityRulesService.updateValueAndVisibility(this.form.get('id').value, element);
});
}
this.form.patchValue({ 'value': values });
}
}
@ -233,7 +238,14 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
this.form.get('value').valueChanges
.pipe(takeUntil(this._destroyed))
.subscribe(item => {
this.visibilityRulesService.updateValueAndVisibility(this.form.get('id').value, item);
if (this.form.get('viewStyle').value.renderStyle === DatasetProfileFieldViewStyle.ComboBox && this.form.get('data').value.type === DatasetProfileComboBoxType.WordList && this.form.get('data').value.multiList) {
item.forEach(element => {
this.visibilityRulesService.updateValueAndVisibility(this.form.get('id').value, element);
});
} else {
this.visibilityRulesService.updateValueAndVisibility(this.form.get('id').value, item);
}
});
}
@ -253,7 +265,11 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
autocompleteRequestItem.criteria = new DatasetExternalAutocompleteCriteria();
autocompleteRequestItem.criteria.fieldID = this.form.get('id').value;
autocompleteRequestItem.criteria.profileID = this.datasetProfileId;
if (typeof this.datasetProfileId === 'string') {
autocompleteRequestItem.criteria.profileID = this.datasetProfileId;
} else {
autocompleteRequestItem.criteria.profileID = this.datasetProfileId.id;
}
autocompleteRequestItem.criteria.like = query;
return this.datasetExternalAutocompleteService.queryAutocomplete(autocompleteRequestItem);
}

View File

@ -371,7 +371,8 @@
"CANCEL": "Cancel",
"DELETE": "Delete",
"ADD-PAGE": "Add Page +",
"ADD-SECTION": "Add Section +"
"ADD-SECTION": "Add Section +",
"VALIDATE": "Validate"
}
},
"GRANT-LISTING": {

View File

@ -391,7 +391,8 @@
"CANCEL": "Cancel",
"DELETE": "Delete",
"ADD-PAGE": "Add Page +",
"ADD-SECTION": "Add Section +"
"ADD-SECTION": "Add Section +",
"VALIDATE": "Validate"
}
},
"GRANT-LISTING": {

View File

@ -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": {

View File

@ -389,7 +389,8 @@
"CANCEL": "Ακύρωση",
"DELETE": "Διαγραφή",
"ADD-PAGE": "Προσθήκη Σελίδας +",
"ADD-SECTION": "Προσθήκη Ενότητας +"
"ADD-SECTION": "Προσθήκη Ενότητας +",
"VALIDATE": "Validate"
}
},
"GRANT-LISTING": {

View File

@ -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": {

View File

@ -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 {