From 7afe351b6973dd7b5dfb36f7f996a6db18badd65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Sun, 11 Mar 2018 13:09:19 +0100 Subject: [PATCH] Adjist join-room so that you can't enter a room which is not existing --- src/app/join-room/join-room.component.html | 5 +++- src/app/join-room/join-room.component.ts | 34 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/app/join-room/join-room.component.html b/src/app/join-room/join-room.component.html index f95094982..db4f11212 100644 --- a/src/app/join-room/join-room.component.html +++ b/src/app/join-room/join-room.component.html @@ -2,9 +2,12 @@ <div fxLayout="row" fxLayoutAlign="center" fxLayoutGap="10px"> <mat-form-field class="input-block"> <input matInput #roomId placeholder="Room-Id"/> + </mat-form-field> - <button mat-fab color="primary" routerLink="room/{{ roomId.value }}"> + <button mat-fab color="primary" (click)="joinRoom(roomId.value)"> <mat-icon>send</mat-icon> </button> </div> + <mat-error *ngIf="!isExisting">Please enter a <strong>valid</strong> room-id.</mat-error> + <mat-error *ngIf="noInput">Please enter a room-id.</mat-error> </form> diff --git a/src/app/join-room/join-room.component.ts b/src/app/join-room/join-room.component.ts index ad5b3670d..f06ff7649 100644 --- a/src/app/join-room/join-room.component.ts +++ b/src/app/join-room/join-room.component.ts @@ -1,15 +1,47 @@ import { Component, OnInit } from '@angular/core'; +import { Room } from '../room'; +import { RoomService } from '../room.service'; +import { Router } from '@angular/router'; +import { NotificationService } from '../notification.service'; @Component({ selector: 'app-join-room', templateUrl: './join-room.component.html', styleUrls: ['./join-room.component.scss'] }) + export class JoinRoomComponent implements OnInit { - constructor() { } + room: Room; + isExisting = true; + noInput = false; + + constructor(private roomService: RoomService, + private router: Router, + private notificationService: NotificationService) { + } ngOnInit() { + } + joinRoom(id: string): void { + if (id) { + this.roomService.getRoom(id) + .subscribe( room => { + this.room = room; + if (!room) { + this.isExisting = false; + this.noInput = false; + this.notificationService.show('Invalid room-id.'); + } else { + this.router.navigate([`/participant/room/${this.room.id}`], { relativeTo: this.route }); + } + }); + } else { + this.noInput = true; + this.isExisting = true; + this.notificationService.show('No room-id entered.'); + } + } } -- GitLab