fix update group name

This commit is contained in:
Elise Lebeau 2023-11-06 16:46:34 +01:00
parent 99e9257a13
commit 443e518740
3 changed files with 13 additions and 10 deletions

View File

@ -14,10 +14,12 @@
<mat-tab label="Details" class="details"> <mat-tab label="Details" class="details">
<div> <div>
<div> <div>
<mat-form-field> <form [formGroup]="editGroupForm" class="input-field">
<mat-label>Group name:</mat-label> <mat-form-field>
<input matInput type="text" [ngModel]="group.name"> <mat-label>Group name:</mat-label>
</mat-form-field> <input matInput type="text" formControlName="groupname">
</mat-form-field>
</form>
</div> </div>
<div> <div>

View File

@ -15,7 +15,7 @@ import {ActivatedRoute} from "@angular/router";
import {Controller} from "@models/controller"; import {Controller} from "@models/controller";
import {Group} from "@models/groups/group"; import {Group} from "@models/groups/group";
import {User} from "@models/users/user"; import {User} from "@models/users/user";
import {UntypedFormControl, UntypedFormGroup} from "@angular/forms"; import {UntypedFormControl, UntypedFormGroup, Validators} from "@angular/forms";
import {MatDialog} from "@angular/material/dialog"; import {MatDialog} from "@angular/material/dialog";
import {AddUserToGroupDialogComponent} from "@components/group-details/add-user-to-group-dialog/add-user-to-group-dialog.component"; import {AddUserToGroupDialogComponent} from "@components/group-details/add-user-to-group-dialog/add-user-to-group-dialog.component";
import {RemoveToGroupDialogComponent} from "@components/group-details/remove-to-group-dialog/remove-to-group-dialog.component"; import {RemoveToGroupDialogComponent} from "@components/group-details/remove-to-group-dialog/remove-to-group-dialog.component";
@ -54,9 +54,7 @@ export class GroupDetailsComponent implements OnInit {
private aclService: AclService, private aclService: AclService,
private roleService: RoleService) { private roleService: RoleService) {
this.editGroupForm = new UntypedFormGroup({
groupname: new UntypedFormControl(''),
});
this.route.data.subscribe((d: { controller: Controller; group: Group, members: User[], aces: ACE[] }) => { this.route.data.subscribe((d: { controller: Controller; group: Group, members: User[], aces: ACE[] }) => {
@ -64,7 +62,9 @@ export class GroupDetailsComponent implements OnInit {
this.group = d.group; this.group = d.group;
this.aces = d.aces; this.aces = d.aces;
this.members = d.members.sort((a: User, b: User) => a.username.toLowerCase().localeCompare(b.username.toLowerCase())); this.members = d.members.sort((a: User, b: User) => a.username.toLowerCase().localeCompare(b.username.toLowerCase()));
this.editGroupForm.setValue({groupname: this.group.name}); this.editGroupForm = new UntypedFormGroup({
groupname: new UntypedFormControl(this.group.name, [Validators.required]),
});
}); });
@ -84,6 +84,8 @@ export class GroupDetailsComponent implements OnInit {
} }
onUpdate() { onUpdate() {
this.group.name = this.editGroupForm.get('groupname').value
console.log(this.editGroupForm.get('groupname'))
this.groupService.update(this.controller, this.group) this.groupService.update(this.controller, this.group)
.subscribe(() => { .subscribe(() => {
this.toastService.success(`group updated`); this.toastService.success(`group updated`);

View File

@ -21,7 +21,6 @@ export const groupNameAsyncValidator = (controller: Controller, groupService: Gr
return timer(500).pipe( return timer(500).pipe(
switchMap(() => groupService.getGroups(controller)), switchMap(() => groupService.getGroups(controller)),
map((response) => { map((response) => {
console.log(response);
return (response.find((n) => n.name === control.value) ? { projectExist: true } : null); return (response.find((n) => n.name === control.value) ? { projectExist: true } : null);
}) })
); );