diff --git a/src/app/join-room/join-room.component.html b/src/app/join-room/join-room.component.html index 63ee40874c61db941b44b6f5dd0057a9f52bd7b9..a90377652e1f69cd4ebe2da722f8d9ed9d8252ec 100644 --- a/src/app/join-room/join-room.component.html +++ b/src/app/join-room/join-room.component.html @@ -5,9 +5,11 @@ [errorStateMatcher]="matcher" maxlength="8"/> <mat-hint align="end">{{roomId.value.length}} / 8</mat-hint> <mat-error *ngIf="roomFormControl.hasError('required')">Please enter a room-id.</mat-error> + <mat-error *ngIf="roomFormControl.hasError('minlength')">A room-id has exactly 8 digits.</mat-error> </mat-form-field> - <button mat-fab color="primary" (click)="joinRoom(roomId.value)"> + <button mat-fab color="primary" type="submit"> <mat-icon>send</mat-icon> </button> </div> </form> +<button mat-button color="primary" (click)="joinDemo()">Join demo room <mat-icon>lightbulb_outline</mat-icon></button> diff --git a/src/app/join-room/join-room.component.ts b/src/app/join-room/join-room.component.ts index df9417c8ec40a4098a69bc6d72cf03de73bb80af..113255d636835070300493751bddb73d02c84a95 100644 --- a/src/app/join-room/join-room.component.ts +++ b/src/app/join-room/join-room.component.ts @@ -22,9 +22,9 @@ export class JoinErrorStateMatcher implements ErrorStateMatcher { export class JoinRoomComponent implements OnInit { room: Room; - isExisting = true; + demoId = '82458028'; - roomFormControl = new FormControl('', [Validators.required]); + roomFormControl = new FormControl('', [Validators.required, Validators.minLength(8)]); matcher = new RegisterErrorStateMatcher(); @@ -37,18 +37,26 @@ export class JoinRoomComponent implements OnInit { ngOnInit() { } + getRoom(id: string): void { + this.roomService.getRoom(id) + .subscribe(room => { + this.room = room; + if (!room) { + this.notificationService.show(`No room was found with id: ${id}`); + } else { + this.roomService.addToHistory(this.room.id); + this.router.navigate([`/participant/room/${this.room.shortId}`]); + } + }); + } + joinRoom(id: string): void { - if (!this.roomFormControl.hasError('required')) { - this.roomService.getRoom(id) - .subscribe(room => { - this.room = room; - if (!room) { - this.notificationService.show(`No room was found with id: ${id}`); - } else { - this.router.navigate([`/participant/room/${this.room.id}`]); - } - }); + if (!this.roomFormControl.hasError('required') && !this.roomFormControl.hasError('minlength')) { + this.getRoom(id); } } + joinDemo(): void { + this.getRoom(this.demoId); + } } diff --git a/src/app/room-creation/room-creation.component.html b/src/app/room-creation/room-creation.component.html index de67617406d588253a7fd14b3074abb0f35ea88a..5ee9f7fbc2cd13c531ea00f6e11300cc79720931 100644 --- a/src/app/room-creation/room-creation.component.html +++ b/src/app/room-creation/room-creation.component.html @@ -1,4 +1,4 @@ -<form (ngSubmit)="addRoom(longRoomName.value, shortRoomName.value)"> +<form (ngSubmit)="addRoom(longRoomName.value, shortRoomName.value, description.value)"> <div fxLayout="column" fxLayoutAlign="center" fxLayoutGap="10px"> <mat-form-field> <input (keypress)="resetEmptyInputs()" matInput #longRoomName class="input-block" type="text" placeholder="Name" @@ -22,6 +22,17 @@ <mat-icon>close</mat-icon> </button> </mat-form-field> + <mat-form-field> + <textarea (keypress)="resetEmptyInputs()" matInput #description type="text" + placeholder="Description" maxlength="255" + [(ngModel)]="shortName"></textarea> + <mat-hint align="start" *ngIf="!emptyInputs"><strong>Max. letters / signs:</strong></mat-hint> + <mat-hint align="end" *ngIf="!emptyInputs">{{description.value.length}} / 255</mat-hint> + <mat-hint align="start" *ngIf="emptyInputs"><strong>Input is required</strong></mat-hint> + <button mat-button *ngIf="shortName" matSuffix mat-icon-button aria-label="Clear" (click)="shortName=''"> + <mat-icon>close</mat-icon> + </button> + </mat-form-field> <button mat-raised-button color="primary" type="submit">Create room </button> </div> diff --git a/src/app/room-creation/room-creation.component.ts b/src/app/room-creation/room-creation.component.ts index ffb25d98e74d5820a7e63ba81e079b14c92e88fa..01733d1dae43a70d674bfd78531536c818578679 100644 --- a/src/app/room-creation/room-creation.component.ts +++ b/src/app/room-creation/room-creation.component.ts @@ -14,6 +14,8 @@ export class RoomCreationComponent implements OnInit { longName: string; shortName: string; emptyInputs = false; + room: Room; + roomId: string; constructor(private roomService: RoomService, private router: Router, @@ -33,19 +35,22 @@ export class RoomCreationComponent implements OnInit { this.emptyInputs = false; } - addRoom(longRoomName: string, shortRoomName: string) { + addRoom(longRoomName: string, shortRoomName: string, description: string) { longRoomName = longRoomName.trim(); shortRoomName = shortRoomName.trim(); if (!longRoomName || !shortRoomName) { this.emptyInputs = true; return; } - this.roomService.addRoom({ name: longRoomName, abbreviation: shortRoomName } as Room) - .subscribe(room => { - this.notification.show(`Room '${room.name}' successfully created.`); - this.router.navigate([`/creator/room/${room.id}`]); - this.dialogRef.close(); - }); + this.roomService.addRoom({ + name: longRoomName, + abbreviation: shortRoomName, + description: description + } as Room).subscribe(room => { + this.room = room; + this.notification.show(`Room '${this.room.name}' successfully created.`); + this.router.navigate([`/creator/room/${this.room.shortId}`]); + this.dialogRef.close(); + }); } } - diff --git a/src/app/room-list/room-list.component.html b/src/app/room-list/room-list.component.html index 869db2914fe77f900b27bbe3ab66a64009ec082d..2513764e9b0fdc1734b5ee7dd2161989ddaec001 100644 --- a/src/app/room-list/room-list.component.html +++ b/src/app/room-list/room-list.component.html @@ -4,7 +4,7 @@ </div> <mat-expansion-panel *ngFor="let room of rooms"> <mat-expansion-panel-header> - <button mat-button color="primary" routerLink="/{{ baseUrl }}/room/{{ room.id }}"> + <button mat-button color="primary" routerLink="/{{ baseUrl }}/room/{{ room.shortId }}"> <mat-icon>send</mat-icon> </button> <mat-panel-title> diff --git a/src/app/room-list/room-list.component.ts b/src/app/room-list/room-list.component.ts index 323b9e57570e9531ea90112243b23616852671a4..cf5720a1b8f3a215e5a953d469086735e4b8b50f 100644 --- a/src/app/room-list/room-list.component.ts +++ b/src/app/room-list/room-list.component.ts @@ -17,7 +17,8 @@ export class RoomListComponent implements OnInit { constructor( private roomService: RoomService, - protected authenticationService: AuthenticationService) {} + protected authenticationService: AuthenticationService) { + } ngOnInit() { this.getRooms(); @@ -33,10 +34,16 @@ export class RoomListComponent implements OnInit { } getRooms(): void { - this.roomService.getRoomsCreator().subscribe(rooms => { - this.rooms = rooms; - this.closedRooms = this.rooms.filter(room => room.closed); - this.isLoading = false; - }); + if (this.authenticationService.getRole() === UserRole.CREATOR) { + this.roomService.getCreatorRooms().subscribe(rooms => this.updateRoomList(rooms)); + } else if (this.authenticationService.getRole() === UserRole.PARTICIPANT) { + this.roomService.getParticipantRooms().subscribe(rooms => this.updateRoomList(rooms)); + } + } + + updateRoomList(rooms: Room[]) { + this.rooms = rooms; + this.closedRooms = this.rooms.filter(room => room.closed); + this.isLoading = false; } } diff --git a/src/app/room-modification/room-modification.component.html b/src/app/room-modification/room-modification.component.html index e5b25370e0e7f0822a0a0973f865ada6f851b9a0..ec6dd5b7802775a7bc62b9958df6c6888bb5a74c 100644 --- a/src/app/room-modification/room-modification.component.html +++ b/src/app/room-modification/room-modification.component.html @@ -3,7 +3,7 @@ <input [(ngModel)]="editRoom.name" #roomName matInput/> </mat-form-field> <mat-form-field class="input-block"> - <input [(ngModel)]="editRoom.shortId" #roomShortID matInput/> + <input [(ngModel)]="editRoom.abbreviation" #roomAbbreviation matInput/> </mat-form-field> <mat-form-field class="input-block"> <textarea [(ngModel)]="editRoom.description" #roomDescription matInput matTextareaAutosize diff --git a/src/app/room.service.ts b/src/app/room.service.ts index 1c9f0c68b1f4138879acb305a0c3afd41b8014bd..323b2b6c6b9c184925a4d0adb6f1418f645dfeeb 100644 --- a/src/app/room.service.ts +++ b/src/app/room.service.ts @@ -7,51 +7,88 @@ import { ErrorHandlingService } from './error-handling.service'; import { AuthenticationService } from './authentication.service'; const httpOptions = { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }) + headers: new HttpHeaders({}) }; @Injectable() export class RoomService extends ErrorHandlingService { - private roomsUrl = 'api/rooms'; + private apiUrl = { + base: 'https://arsnova-staging.mni.thm.de/api', + rooms: '/room', + user: '/user', + findRooms: '/find' + }; + private joinDate = new Date(Date.now()); - constructor(private http: HttpClient) { + constructor(private http: HttpClient, + private authService: AuthenticationService) { super(); } - getRooms(): Observable<Room[]> { - return this.http.get<Room[]>(this.roomsUrl).pipe( - tap(_ => ''), + getCreatorRooms(): Observable<Room[]> { + const url = this.apiUrl.base + this.apiUrl.rooms + this.apiUrl.findRooms; + return this.http.post<Room[]>(url, { + properties: { ownerId: this.authService.getUser().id }, + externalFilters: {} + }).pipe( + tap(() => ''), catchError(this.handleError('getRooms', [])) ); } - addRoom(room: Room): Observable<Room> { - return this.http.post<Room>(this.roomsUrl, room, httpOptions).pipe( - tap(_ => ''), - catchError(this.handleError<Room>('addRoom')) + getParticipantRooms(): Observable<Room[]> { + const url = this.apiUrl.base + this.apiUrl.rooms + this.apiUrl.findRooms; + return this.http.post<Room[]>(url, { + properties: {}, + externalFilters: { inHistoryOfUserId: this.authService.getUser().id } + }).pipe( + tap(() => ''), + catchError(this.handleError('getRooms', [])) ); } + addRoom(room: Room): Observable<Room> { + const connectionUrl = this.apiUrl.base + this.apiUrl.rooms + '/'; + return this.http.post<Room>(connectionUrl, { + ownerId: this.authService.getUser().id, + abbreviation: room.abbreviation, name: room.name, closed: room.closed, description: room.description + }, httpOptions); + } + getRoom(id: string): Observable<Room> { - const url = `${this.roomsUrl}/${id}`; - return this.http.get<Room>(url).pipe( + const connectionUrl = `${ this.apiUrl.base }${ this.apiUrl.rooms }/~${id}`; + return this.http.get<Room>(connectionUrl).pipe( catchError(this.handleError<Room>(`getRoom id=${id}`)) ); } - updateRoom(room: Room): Observable<any> { - return this.http.put(this.roomsUrl, room, httpOptions).pipe( - tap(_ => ''), - catchError(this.handleError<any>('updateRoom')) + addToHistory(roomId: string): void { + const connectionUrl = `${ this.apiUrl.base }${ this.apiUrl.user }/${this.authService.getUser().id}/roomHistory`; + this.http.post(connectionUrl, { roomId: roomId, lastVisit: this.joinDate.getTime() }, httpOptions).subscribe(r => console.log(r)); + } + + getRoomById(id: string): Observable<Room> { + const connectionUrl = `${ this.apiUrl.base }${ this.apiUrl.rooms }/${id}`; + return this.http.get<Room>(connectionUrl).pipe( + catchError(this.handleError<Room>(`getRoom id=${id}`)) ); } - deleteRoom (room: Room | string): Observable<Room> { - const id = typeof room === 'string' ? room : room.id; - const url = `${this.roomsUrl}/${id}`; + updateRoom(room: Room): Observable<Room> { + const connectionUrl = `${ this.apiUrl.base }${this.apiUrl.rooms}/~${room.shortId}`; + return this.http.put(connectionUrl, { + ownerId: this.authService.getUser().id, + abbreviation: room.abbreviation, name: room.name, description: room.description + }, httpOptions).pipe( + tap(() => ''), + catchError(this.handleError<any>('updateRoom')) + ); + } - return this.http.delete<Room>(url, httpOptions).pipe( - tap(_ => ''), + deleteRoom(room: Room): Observable<Room> { + const connectionUrl = `${this.apiUrl.base}${this.apiUrl.rooms}/${room.id}`; + return this.http.delete<Room>(connectionUrl, httpOptions).pipe( + tap(() => ''), catchError(this.handleError<Room>('deleteRoom')) ); }