From 82ae11a53805b8d6decd301c548e19e9dc9569d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20K=C3=A4sler?= <tom.kaesler@mni.thm.de> Date: Mon, 20 Jan 2020 15:05:54 +0100 Subject: [PATCH] Add a 'delete from room history' button for users --- .../shared/room-list/room-list.component.html | 19 ++++++++++++------- .../shared/room-list/room-list.component.ts | 18 +++++++++++++++++- src/app/services/http/room.service.ts | 8 ++++++++ src/assets/i18n/home/de.json | 2 ++ src/assets/i18n/home/en.json | 2 ++ 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/app/components/shared/room-list/room-list.component.html b/src/app/components/shared/room-list/room-list.component.html index 161628765..83db0cda6 100644 --- a/src/app/components/shared/room-list/room-list.component.html +++ b/src/app/components/shared/room-list/room-list.component.html @@ -73,13 +73,18 @@ </th> <td mat-cell *matCellDef="let room" style="text-align: end" attr.aria-labelledby="empty"> - <button mat-flat-button type="button" - attr.aria-labelledby="{{ 'joinButtonLabel' + room.shortId | translate }}" - name="{{ 'room-list.panel-join-button' | translate }}" - routerLink="/{{ roleToString((room.role)) }}/room/{{ room.shortId }}" - (click)="setCurrentRoom(room.shortId)"> - <mat-icon>input</mat-icon> - </button> + <button *ngIf="room.role < 3" mat-flat-button type="button" + name="{{ 'room-list.panel-remove-button' | translate }}" + (click)="removeFromHistory(room.id)"> + <mat-icon>delete_forever</mat-icon> + </button> + <button mat-flat-button type="button" + attr.aria-labelledby="{{ 'joinButtonLabel' + room.shortId | translate }}" + name="{{ 'room-list.panel-join-button' | translate }}" + routerLink="/{{ roleToString((room.role)) }}/room/{{ room.shortId }}" + (click)="setCurrentRoom(room.shortId)"> + <mat-icon>input</mat-icon> + </button> <div class="visually-hidden"> <div id="{{ 'joinButtonLabel' + room.shortId | translate }}"> {{ 'room-list.join-message-template' | translate:{ diff --git a/src/app/components/shared/room-list/room-list.component.ts b/src/app/components/shared/room-list/room-list.component.ts index b8ac5681a..e42c241d9 100644 --- a/src/app/components/shared/room-list/room-list.component.ts +++ b/src/app/components/shared/room-list/room-list.component.ts @@ -11,6 +11,8 @@ import { ModeratorService } from '../../../services/http/moderator.service'; import { MatTableDataSource } from '@angular/material'; import { Subscription } from 'rxjs'; import { CommentService } from '../../../services/http/comment.service'; +import { NotificationService } from '../../../services/util/notification.service'; +import { TranslateService } from '@ngx-translate/core'; @Component({ selector: 'app-room-list', @@ -38,7 +40,9 @@ export class RoomListComponent implements OnInit, OnDestroy { public eventService: EventService, protected authenticationService: AuthenticationService, private moderatorService: ModeratorService, - private commentService: CommentService + private commentService: CommentService, + public notificationService: NotificationService, + private translateService: TranslateService ) { } @@ -100,6 +104,18 @@ export class RoomListComponent implements OnInit, OnDestroy { } } + removeFromHistory(roomId: string) { + this.roomService.removeFromHistory(roomId).subscribe( x => { + this.rooms = this.rooms.filter(r => r.id !== roomId); + this.closedRooms = this.closedRooms.filter(r => r.id !== roomId); + this.roomsWithRole = this.roomsWithRole.filter(r => r.id !== roomId); + this.updateTable(); + this.translateService.get('room-list.room-successfully-removed').subscribe(message => { + this.notificationService.show(message); + }); + }); + } + roleToString(role: UserRole): string { switch (role) { case UserRole.CREATOR: diff --git a/src/app/services/http/room.service.ts b/src/app/services/http/room.service.ts index 3dc8aaa04..52d6e8032 100644 --- a/src/app/services/http/room.service.ts +++ b/src/app/services/http/room.service.ts @@ -99,6 +99,14 @@ export class RoomService extends BaseHttpService { this.http.post(connectionUrl, { roomId: roomId, lastVisit: this.joinDate.getTime() }, httpOptions).subscribe(() => {}); } + removeFromHistory(roomId: string): Observable<Room> { + const connectionUrl = `${ this.apiUrl.base + this.apiUrl.user }/${ this.authService.getUser().id }/roomHistory/${roomId}`; + return this.http.delete<Room>(connectionUrl, httpOptions).pipe( + tap(() => ''), + catchError(this.handleError<Room>('deleteRoom')) + ); + } + updateRoom(updatedRoom: Room): Observable<Room> { const connectionUrl = `${ this.apiUrl.base + this.apiUrl.rooms }/~${ updatedRoom.shortId }`; return this.http.put(connectionUrl, updatedRoom , httpOptions).pipe( diff --git a/src/assets/i18n/home/de.json b/src/assets/i18n/home/de.json index 9d54acd85..7764920e4 100644 --- a/src/assets/i18n/home/de.json +++ b/src/assets/i18n/home/de.json @@ -206,10 +206,12 @@ "moderator-role": "Moderator", "no-room-history": "Du hast bisher an keiner Sitzung teilgenommen.", "panel-join-button": "", + "panel-remove-button": "Sitzung aus dem Verlauf löschen.", "panel-session-id": "Code", "panel-session-name": "Sitzung", "panel-user-role": "Rolle", "participant-role": "Teilnehmer", + "room-successfully-removed": "Die Sitzung wurde erfolgreich aus dem Verlauf gelöscht.", "session-history": "Dein Sitzungsverlauf enthält {{count}} Sitzungen.", "session-history-1": "Dein Sitzungsverlauf enthält genau eine Sitzung.", "session-history-label": "Nachfolgend findest du eine Liste deiner Sitzungen." diff --git a/src/assets/i18n/home/en.json b/src/assets/i18n/home/en.json index f4a1744cb..2f4a1050f 100644 --- a/src/assets/i18n/home/en.json +++ b/src/assets/i18n/home/en.json @@ -207,10 +207,12 @@ "moderator-role": "Moderator", "no-room-history": "You haven't joined any sessions yet.", "panel-join-button": "", + "panel-remove-button": "Delete the session from your room history.", "panel-session-id": "Key", "panel-session-name": "Session", "panel-user-role": "Role", "participant-role": "Participant", + "room-successfully-removed": "The session was successfully removed from the history.", "session-history": "Your session history contains {count}} sessions.", "session-history-1": "Your session history contains one session.", "session-history-label": "Below you will find a list of your attended sessions." -- GitLab