-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dialog to register and deregister groupmebers (#1675)
- Loading branch information
Showing
3 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...s-core/web/src/app/dialogs/group-deregister-dialog/group-deregister-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<div class="container"> | ||
<div *ngIf="data.adding" matDialogTitle> | ||
{{ groupName }} - {{ "group.add.member" | i18nextEager }} | ||
</div> | ||
<div *ngIf="!data.adding" matDialogTitle> | ||
{{ groupName }} - {{ "group.deregister.member" | i18nextEager }} | ||
</div> | ||
<mat-dialog-content style="max-height: 100%; overflow: hidden"> | ||
<mat-list> | ||
<mat-list-item *ngFor="let member of members$ | async"> | ||
{{ member.user.prename }} {{ member.user.surname }} | ||
|
||
<span class="spacer"></span> | ||
<button | ||
*ngIf="data.adding" | ||
mat-button | ||
color="warn" | ||
(click)="addMember(member)" | ||
matTooltip="{{ 'dialog.group.deregister.add' | i18nextEager }}" | ||
> | ||
<mat-icon>add</mat-icon> | ||
</button> | ||
<button | ||
*ngIf="!data.adding" | ||
mat-button | ||
color="warn" | ||
(click)="removeMember(member)" | ||
matTooltip="{{ 'dialog.group.deregister.remove' | i18nextEager }}" | ||
> | ||
<mat-icon>remove</mat-icon> | ||
</button> | ||
</mat-list-item> | ||
</mat-list> | ||
</mat-dialog-content> | ||
<mat-dialog-actions class="actions"> | ||
<button mat-flat-button color="warn" (click)="closeDialog()"> | ||
{{ "dialog.group.new.cancel" | i18nextEager }} | ||
</button> | ||
</mat-dialog-actions> | ||
</div> |
7 changes: 7 additions & 0 deletions
7
...s-core/web/src/app/dialogs/group-deregister-dialog/group-deregister-dialog.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.spacer { | ||
flex: 1 1 auto; | ||
} | ||
.actions { | ||
display: flex; | ||
justify-content: flex-end; | ||
} |
83 changes: 83 additions & 0 deletions
83
...fbs-core/web/src/app/dialogs/group-deregister-dialog/group-deregister-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Component, Inject, OnInit } from "@angular/core"; | ||
import { Observable } from "rxjs"; | ||
import { GroupRegistrationService } from "../../service/group-registration.sevice"; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog"; | ||
import { Participant } from "../../model/Participant"; | ||
import { Group } from "../../model/Group"; | ||
import { GroupService } from "../../service/group.service"; | ||
import { CourseRegistrationService } from "../../service/course-registration.service"; | ||
|
||
@Component({ | ||
selector: "app-group-deregister-dialog", | ||
templateUrl: "./group-deregister-dialog.component.html", | ||
styleUrls: ["./group-deregister-dialog.component.scss"], | ||
}) | ||
export class GroupDeregisterDialogComponent implements OnInit { | ||
members$: Observable<Participant[]>; | ||
group$: Observable<Group>; | ||
groupName: string; | ||
|
||
constructor( | ||
private groupRegistrationService: GroupRegistrationService, | ||
private courseRegistrationService: CourseRegistrationService, | ||
private groupService: GroupService, | ||
public dialogRef: MatDialogRef<GroupDeregisterDialogComponent>, | ||
@Inject(MAT_DIALOG_DATA) | ||
public data: { | ||
cid: number; | ||
gid: number; | ||
adding: boolean; | ||
} | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.loadMembers(); | ||
this.group$ = this.groupService.getGroup(this.data.cid, this.data.gid); | ||
this.group$.subscribe((group: Group) => { | ||
this.groupName = group.name; | ||
}); | ||
} | ||
|
||
loadMembers(): void { | ||
if (this.data.adding) { | ||
this.members$ = this.courseRegistrationService.getCourseParticipants( | ||
this.data.cid | ||
); | ||
} else { | ||
this.members$ = this.groupRegistrationService.getGroupParticipants( | ||
this.data.cid, | ||
this.data.gid | ||
); | ||
} | ||
} | ||
|
||
removeMember(member: Participant): void { | ||
this.groupRegistrationService | ||
.deregisterGroup(this.data.cid, this.data.gid, member.user.id) | ||
.subscribe( | ||
() => { | ||
this.loadMembers(); | ||
}, | ||
(error) => { | ||
console.error(error); | ||
} | ||
); | ||
} | ||
|
||
addMember(member: Participant): void { | ||
this.groupRegistrationService | ||
.registerGroup(this.data.cid, this.data.gid, member.user.id) | ||
.subscribe( | ||
() => { | ||
this.loadMembers(); | ||
}, | ||
(error) => { | ||
console.error(error); | ||
} | ||
); | ||
} | ||
|
||
closeDialog() { | ||
this.dialogRef.close(); | ||
} | ||
} |