Skip to content

Commit 8353592

Browse files
michalberkyxflord
authored andcommitted
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 c7fad76)
1 parent dcfbdcd commit 8353592

6 files changed

Lines changed: 77 additions & 16 deletions

File tree

apps/admin-gui/src/app/shared/components/dialogs/update-application-form-dialog/update-application-form-dialog.component.html

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,36 @@
55
<div *perunWebAppsLoader="loading; indicator: spinner">
66
<h1 mat-dialog-title>{{'DIALOGS.UPDATE_APPLICATION_FORM.TITLE' | translate}}</h1>
77
<div class="dialog-container" mat-dialog-content>
8-
<mat-form-field>
9-
<mat-label>{{'DIALOGS.UPDATE_APPLICATION_FORM.MODULE_NAME' | translate}}</mat-label>
10-
<input matInput [(ngModel)]="moduleName" />
11-
</mat-form-field>
8+
<div
9+
*ngFor="let control of formArray.controls; let i = index; trackBy: trackByIndex"
10+
class="d-flex flex-row align-items-center">
11+
<mat-form-field class="w-100 mb-n2">
12+
<mat-label>{{'DIALOGS.UPDATE_APPLICATION_FORM.MODULE_NAME' | translate}}</mat-label>
13+
<input [formControl]="control" matInput />
14+
<mat-error
15+
*ngIf="control.hasError('pattern')"
16+
>{{'DIALOGS.UPDATE_APPLICATION_FORM.COMMA_ERROR' | translate}}</mat-error
17+
>
18+
</mat-form-field>
19+
<button
20+
*ngIf="formArray.length > 1"
21+
color="warn"
22+
(click)="removeModule(i)"
23+
[matTooltip]="'DIALOGS.UPDATE_APPLICATION_FORM.REMOVE_MODULE_TOOLTIP' | translate"
24+
mat-icon-button>
25+
<mat-icon>remove_circle</mat-icon>
26+
</button>
27+
</div>
28+
29+
<div class="d-flex justify-content-center mb-3">
30+
<button
31+
color="accent"
32+
(click)="addModule()"
33+
[matTooltip]="'DIALOGS.UPDATE_APPLICATION_FORM.ADD_MODULE_TOOLTIP' | translate"
34+
mat-icon-button>
35+
<mat-icon>add_circle</mat-icon>
36+
</button>
37+
</div>
1238

1339
<mat-form-field class="w-100">
1440
<mat-label>{{'DIALOGS.UPDATE_APPLICATION_FORM.INITIAL' | translate}}:</mat-label>
@@ -58,7 +84,12 @@ <h1 mat-dialog-title>{{'DIALOGS.UPDATE_APPLICATION_FORM.TITLE' | translate}}</h1
5884
<button (click)="onCancel()" class="ms-auto" mat-stroked-button>
5985
{{'DIALOGS.UPDATE_APPLICATION_FORM.CANCEL_BUTTON' | translate}}
6086
</button>
61-
<button (click)="submit()" [disabled]="loading" class="ms-2" color="accent" mat-flat-button>
87+
<button
88+
(click)="submit()"
89+
[disabled]="formArray.invalid"
90+
class="ms-2"
91+
color="accent"
92+
mat-flat-button>
6293
{{'DIALOGS.UPDATE_APPLICATION_FORM.SUBMIT_BUTTON' | translate}}
6394
</button>
6495
</div>

apps/admin-gui/src/app/shared/components/dialogs/update-application-form-dialog/update-application-form-dialog.component.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component, Inject, OnInit } from '@angular/core';
22
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
33
import { ApplicationForm, RegistrarManagerService } from '@perun-web-apps/perun/openapi';
4+
import { FormControl, FormArray, Validators } from '@angular/forms';
45

56
export interface UpdateApplicationFormDialogData {
67
entity: string;
@@ -17,13 +18,13 @@ export interface UpdateApplicationFormDialogData {
1718
export class UpdateApplicationFormDialogComponent implements OnInit {
1819
entity: string;
1920
applicationForm: ApplicationForm;
20-
moduleName: string;
2121
initialState: string;
2222
extensionState: string;
2323
embeddedState: string;
2424
loading = false;
2525
theme: string;
2626
autoRegistrationEnabled: boolean;
27+
formArray: FormArray<FormControl<string>>;
2728

2829
constructor(
2930
private dialogRef: MatDialogRef<UpdateApplicationFormDialogComponent>,
@@ -34,21 +35,47 @@ export class UpdateApplicationFormDialogComponent implements OnInit {
3435
ngOnInit(): void {
3536
this.theme = this.data.theme;
3637
this.applicationForm = this.data.applicationForm;
37-
this.moduleName = this.applicationForm.moduleClassName;
38+
this.formArray = new FormArray<FormControl<string>>([]);
39+
for (const moduleName of this.applicationForm.moduleClassNames) {
40+
this.addModule(moduleName);
41+
}
42+
if (this.formArray.length === 0) {
43+
this.addModule();
44+
}
3845
this.initialState = this.applicationForm.automaticApproval ? 'auto' : 'manual';
3946
this.extensionState = this.applicationForm.automaticApprovalExtension ? 'auto' : 'manual';
4047
this.embeddedState = this.applicationForm.automaticApprovalEmbedded ? 'auto' : 'manual';
4148
this.entity = this.data.entity;
4249
this.autoRegistrationEnabled = this.data.autoRegistrationEnabled;
4350
}
4451

52+
addModule(name = ''): void {
53+
const commaControl = new FormControl(name, {
54+
validators: [Validators.pattern(/^[^,]*$/)],
55+
updateOn: 'change',
56+
});
57+
commaControl.markAsTouched(); // This helps show the mat-error message immediately when a comma is typed
58+
this.formArray.push(commaControl);
59+
}
60+
61+
removeModule(index: number): void {
62+
this.formArray.removeAt(index);
63+
}
64+
65+
trackByIndex(index: number): number {
66+
return index;
67+
}
68+
4569
onCancel(): void {
4670
this.dialogRef.close();
4771
}
4872

4973
submit(): void {
5074
this.loading = true;
51-
this.applicationForm.moduleClassName = this.moduleName;
75+
const moduleNamesWithoutEmptyStrings: string[] = this.formArray.controls
76+
.map((control) => control.value)
77+
.filter((name: string) => name.trim() !== '');
78+
this.applicationForm.moduleClassNames = moduleNamesWithoutEmptyStrings;
5279
this.applicationForm.automaticApproval = this.initialState === 'auto';
5380
this.applicationForm.automaticApprovalExtension = this.extensionState === 'auto';
5481
this.applicationForm.automaticApprovalEmbedded = this.embeddedState === 'auto';

apps/admin-gui/src/app/vos/pages/group-detail-page/group-settings/group-settings-application-form/group-settings-application-form.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ <h1 class="page-subtitle">
66
<div *ngIf="!loading" class="d-flex w-75">
77
<div>
88
<div class="fw-bold">
9-
{{'GROUP_DETAIL.SETTINGS.APPLICATION_FORM.MODULE_NAME' | translate}}:
10-
{{applicationForm.moduleClassName}}
9+
{{'GROUP_DETAIL.SETTINGS.APPLICATION_FORM.MODULE_NAMES' | translate}}:
10+
{{applicationForm.moduleClassNames}}
1111
</div>
1212
<div>
1313
<span

apps/admin-gui/src/app/vos/pages/vo-detail-page/vo-settings/vo-settings-application-form/vo-settings-application-form.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ <h1 class="page-subtitle">
66
<div *ngIf="!loading" class="d-flex w-75">
77
<div>
88
<div class="fw-bold">
9-
{{'VO_DETAIL.SETTINGS.APPLICATION_FORM.MODULE_NAME' | translate}}:
10-
{{applicationForm.moduleClassName}}
9+
{{'VO_DETAIL.SETTINGS.APPLICATION_FORM.MODULE_NAMES' | translate}}:
10+
{{applicationForm.moduleClassNames}}
1111
</div>
1212
<div>
1313
<span

apps/admin-gui/src/assets/i18n/en.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@
396396
"EDIT": "Edit",
397397
"MANAGE_GROUPS": "Manage groups",
398398
"DELETE": "Delete",
399-
"MODULE_NAME": "Module name",
399+
"MODULE_NAMES": "Module names",
400400
"APPLICATION_TYPE": "Approval style",
401401
"MANUAL": "Manual",
402402
"AUTOMATIC": "Automatic",
@@ -790,7 +790,7 @@
790790
},
791791
"APPLICATION_FORM": {
792792
"TITLE": "Application form",
793-
"MODULE_NAME": "Module name",
793+
"MODULE_NAMES": "Module names",
794794
"APPLICATION_TYPE": "Approval style",
795795
"AUTOMATIC": "Automatic",
796796
"MANUAL": "Manual",
@@ -1367,7 +1367,10 @@
13671367
"MANUAL": "Manual",
13681368
"AUTOMATIC": "Automatic",
13691369
"SUBMIT_BUTTON": "Submit",
1370-
"CANCEL_BUTTON": "Cancel"
1370+
"CANCEL_BUTTON": "Cancel",
1371+
"REMOVE_MODULE_TOOLTIP": "Remove module name",
1372+
"ADD_MODULE_TOOLTIP": "Add module name",
1373+
"COMMA_ERROR": "Commas are not allowed."
13711374
},
13721375
"DELETE_APPLICATION_FORM_ITEM": {
13731376
"TITLE": "Delete confirm",

libs/perun/openapi/src/lib/model/applicationForm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ export interface ApplicationForm {
1919
automaticApproval?: boolean;
2020
automaticApprovalExtension?: boolean;
2121
automaticApprovalEmbedded?: boolean;
22-
moduleClassName?: string;
22+
moduleClassNames?: string[];
2323
}

0 commit comments

Comments
 (0)