From 8353592b1da03cf703834a7f61b88a8e722a987c Mon Sep 17 00:00:00 2001 From: Michal Berky Date: Tue, 19 Sep 2023 10:40:39 +0200 Subject: [PATCH] feat(admin): change GUI to incorporate moduleClassNames * Changed all uses of moduleClassName to moduleClassNames * Added functionality to add multiple module names in 'Change application form settings' dialog (cherry picked from commit c7fad76e9971d3788060f18447f8488f26971b2f) --- ...ate-application-form-dialog.component.html | 41 ++++++++++++++++--- ...pdate-application-form-dialog.component.ts | 33 +++++++++++++-- ...p-settings-application-form.component.html | 4 +- ...o-settings-application-form.component.html | 4 +- apps/admin-gui/src/assets/i18n/en.json | 9 ++-- .../openapi/src/lib/model/applicationForm.ts | 2 +- 6 files changed, 77 insertions(+), 16 deletions(-) diff --git a/apps/admin-gui/src/app/shared/components/dialogs/update-application-form-dialog/update-application-form-dialog.component.html b/apps/admin-gui/src/app/shared/components/dialogs/update-application-form-dialog/update-application-form-dialog.component.html index b37760e5a..8aaee92c8 100644 --- a/apps/admin-gui/src/app/shared/components/dialogs/update-application-form-dialog/update-application-form-dialog.component.html +++ b/apps/admin-gui/src/app/shared/components/dialogs/update-application-form-dialog/update-application-form-dialog.component.html @@ -5,10 +5,36 @@

{{'DIALOGS.UPDATE_APPLICATION_FORM.TITLE' | translate}}

- - {{'DIALOGS.UPDATE_APPLICATION_FORM.MODULE_NAME' | translate}} - - +
+ + {{'DIALOGS.UPDATE_APPLICATION_FORM.MODULE_NAME' | translate}} + + {{'DIALOGS.UPDATE_APPLICATION_FORM.COMMA_ERROR' | translate}} + + +
+ +
+ +
{{'DIALOGS.UPDATE_APPLICATION_FORM.INITIAL' | translate}}: @@ -58,7 +84,12 @@

{{'DIALOGS.UPDATE_APPLICATION_FORM.TITLE' | translate}}

{{'DIALOGS.UPDATE_APPLICATION_FORM.CANCEL_BUTTON' | translate}} -
diff --git a/apps/admin-gui/src/app/shared/components/dialogs/update-application-form-dialog/update-application-form-dialog.component.ts b/apps/admin-gui/src/app/shared/components/dialogs/update-application-form-dialog/update-application-form-dialog.component.ts index 7c67de3f2..f5ec6cd15 100644 --- a/apps/admin-gui/src/app/shared/components/dialogs/update-application-form-dialog/update-application-form-dialog.component.ts +++ b/apps/admin-gui/src/app/shared/components/dialogs/update-application-form-dialog/update-application-form-dialog.component.ts @@ -1,6 +1,7 @@ import { Component, Inject, OnInit } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { ApplicationForm, RegistrarManagerService } from '@perun-web-apps/perun/openapi'; +import { FormControl, FormArray, Validators } from '@angular/forms'; export interface UpdateApplicationFormDialogData { entity: string; @@ -17,13 +18,13 @@ export interface UpdateApplicationFormDialogData { export class UpdateApplicationFormDialogComponent implements OnInit { entity: string; applicationForm: ApplicationForm; - moduleName: string; initialState: string; extensionState: string; embeddedState: string; loading = false; theme: string; autoRegistrationEnabled: boolean; + formArray: FormArray>; constructor( private dialogRef: MatDialogRef, @@ -34,7 +35,13 @@ export class UpdateApplicationFormDialogComponent implements OnInit { ngOnInit(): void { this.theme = this.data.theme; this.applicationForm = this.data.applicationForm; - this.moduleName = this.applicationForm.moduleClassName; + this.formArray = new FormArray>([]); + for (const moduleName of this.applicationForm.moduleClassNames) { + this.addModule(moduleName); + } + if (this.formArray.length === 0) { + this.addModule(); + } this.initialState = this.applicationForm.automaticApproval ? 'auto' : 'manual'; this.extensionState = this.applicationForm.automaticApprovalExtension ? 'auto' : 'manual'; this.embeddedState = this.applicationForm.automaticApprovalEmbedded ? 'auto' : 'manual'; @@ -42,13 +49,33 @@ export class UpdateApplicationFormDialogComponent implements OnInit { this.autoRegistrationEnabled = this.data.autoRegistrationEnabled; } + addModule(name = ''): void { + const commaControl = new FormControl(name, { + validators: [Validators.pattern(/^[^,]*$/)], + updateOn: 'change', + }); + commaControl.markAsTouched(); // This helps show the mat-error message immediately when a comma is typed + this.formArray.push(commaControl); + } + + removeModule(index: number): void { + this.formArray.removeAt(index); + } + + trackByIndex(index: number): number { + return index; + } + onCancel(): void { this.dialogRef.close(); } submit(): void { this.loading = true; - this.applicationForm.moduleClassName = this.moduleName; + const moduleNamesWithoutEmptyStrings: string[] = this.formArray.controls + .map((control) => control.value) + .filter((name: string) => name.trim() !== ''); + this.applicationForm.moduleClassNames = moduleNamesWithoutEmptyStrings; this.applicationForm.automaticApproval = this.initialState === 'auto'; this.applicationForm.automaticApprovalExtension = this.extensionState === 'auto'; this.applicationForm.automaticApprovalEmbedded = this.embeddedState === 'auto'; diff --git a/apps/admin-gui/src/app/vos/pages/group-detail-page/group-settings/group-settings-application-form/group-settings-application-form.component.html b/apps/admin-gui/src/app/vos/pages/group-detail-page/group-settings/group-settings-application-form/group-settings-application-form.component.html index eda8be548..d8d8e992d 100644 --- a/apps/admin-gui/src/app/vos/pages/group-detail-page/group-settings/group-settings-application-form/group-settings-application-form.component.html +++ b/apps/admin-gui/src/app/vos/pages/group-detail-page/group-settings/group-settings-application-form/group-settings-application-form.component.html @@ -6,8 +6,8 @@

- {{'GROUP_DETAIL.SETTINGS.APPLICATION_FORM.MODULE_NAME' | translate}}: - {{applicationForm.moduleClassName}} + {{'GROUP_DETAIL.SETTINGS.APPLICATION_FORM.MODULE_NAMES' | translate}}: + {{applicationForm.moduleClassNames}}
- {{'VO_DETAIL.SETTINGS.APPLICATION_FORM.MODULE_NAME' | translate}}: - {{applicationForm.moduleClassName}} + {{'VO_DETAIL.SETTINGS.APPLICATION_FORM.MODULE_NAMES' | translate}}: + {{applicationForm.moduleClassNames}}