Skip to content
Snippets Groups Projects
Commit e7ba82e9 authored by Lukas Maximilian Kimpel's avatar Lukas Maximilian Kimpel
Browse files

Merge branch '130-see-reed-comments-participant' into 'master'

Resolve "See reed comments (participant)"

Closes #130

See merge request swtp-block-ws17/arsnova-angular-frontend!77
parents 35497aa3 eb4c283a
Branches
Tags
No related merge requests found
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
{{comment.body}} {{comment.body}}
<div class="body-buttons" fxLayout="Column" fxLayoutGap="5px" fxLayoutAlign="end"> <div class="body-buttons">
<button *ngIf="!comment.read" mat-fab color="warn" matTooltip="Is not read" (click)="setRead(comment)"> <button *ngIf="!comment.read" mat-fab color="warn" matTooltip="Is not read" (click)="userRole === userRoleTemp && setRead(comment)">
<mat-icon>clear</mat-icon> <mat-icon>clear</mat-icon>
</button> </button>
<button *ngIf="comment.read" mat-fab color="primary" matTooltip="Is read" (click)="setRead(comment)"> <button *ngIf="comment.read" mat-fab color="primary" matTooltip="Is read" (click)="userRole === userRoleTemp && setRead(comment)">
<mat-icon>check</mat-icon> <mat-icon>check</mat-icon>
</button> </button>
<button class="trash-icon" mat-fab color="primary" matTooltip="Delete" (click)="delete(comment)"> <button *ngIf="userRole === userRoleTemp" class="trash-icon" mat-fab color="primary" matTooltip="Delete" (click)="delete(comment)">
<mat-icon>delete</mat-icon> <mat-icon>delete</mat-icon>
</button> </button>
</div> </div>
...@@ -27,6 +27,6 @@ ...@@ -27,6 +27,6 @@
</mat-card><br> </mat-card><br>
</div> </div>
<button class="back-button" mat-raised-button color="primary" (click)="goBack()">Back</button> <button *ngIf="userRole === userRoleTemp" mat-raised-button color="primary" (click)="goBack()">Back</button>
</div> </div>
</div> </div>
...@@ -16,10 +16,6 @@ mat-card:hover { ...@@ -16,10 +16,6 @@ mat-card:hover {
background: #F44336; background: #F44336;
} }
.back-button {
min-width: 800px;
}
.body-buttons { .body-buttons {
position: absolute; position: absolute;
top: 10%; top: 10%;
......
...@@ -5,6 +5,9 @@ import { Comment } from '../comment'; ...@@ -5,6 +5,9 @@ import { Comment } from '../comment';
import { CommentService } from '../comment.service'; import { CommentService } from '../comment.service';
import { RoomService } from '../room.service'; import { RoomService } from '../room.service';
import { NotificationService } from '../notification.service'; import { NotificationService } from '../notification.service';
import { AuthenticationService } from '../authentication.service';
import { UserRole } from '../user-roles.enum';
import { User } from '../user';
@Component({ @Component({
selector: 'app-comment-list', selector: 'app-comment-list',
...@@ -12,9 +15,13 @@ import { NotificationService } from '../notification.service'; ...@@ -12,9 +15,13 @@ import { NotificationService } from '../notification.service';
styleUrls: ['./comment-list.component.scss'] styleUrls: ['./comment-list.component.scss']
}) })
export class CommentListComponent implements OnInit { export class CommentListComponent implements OnInit {
userRoleTemp: any = UserRole.CREATOR;
userRole: UserRole;
user: User;
comments: Comment[]; comments: Comment[];
constructor( constructor(
protected authenticationService: AuthenticationService,
private route: ActivatedRoute, private route: ActivatedRoute,
private roomService: RoomService, private roomService: RoomService,
private location: Location, private location: Location,
...@@ -22,6 +29,8 @@ export class CommentListComponent implements OnInit { ...@@ -22,6 +29,8 @@ export class CommentListComponent implements OnInit {
private notification: NotificationService) { } private notification: NotificationService) { }
ngOnInit() { ngOnInit() {
this.userRole = this.authenticationService.getRole();
this.user = this.authenticationService.getUser();
this.route.params.subscribe(params => { this.route.params.subscribe(params => {
this.getRoom(params['roomId']); this.getRoom(params['roomId']);
}); });
...@@ -35,8 +44,13 @@ export class CommentListComponent implements OnInit { ...@@ -35,8 +44,13 @@ export class CommentListComponent implements OnInit {
} }
getComments(roomId: string): void { getComments(roomId: string): void {
this.commentService.getComments(roomId) if (this.userRole === UserRole.CREATOR) {
.subscribe(comments => this.comments = comments); this.commentService.getComments(roomId)
.subscribe(comments => this.comments = comments);
} else if (this.userRole === UserRole.PARTICIPANT) {
this.commentService.searchComments(roomId, this.user.id)
.subscribe(comments => this.comments = comments);
}
} }
setRead(comment: Comment): void { setRead(comment: Comment): void {
......
...@@ -40,6 +40,14 @@ export class CommentService extends ErrorHandlingService { ...@@ -40,6 +40,14 @@ export class CommentService extends ErrorHandlingService {
); );
} }
searchComments(roomId: string, userId: number): Observable<Comment[]> {
const url = `${this.commentsUrl}/?roomId=${roomId}&userId=${userId}`;
return this.http.get<Comment[]>(url).pipe(
tap (_ => ''),
catchError(this.handleError<Comment[]>('getComments', []))
);
}
updateComment(comment: Comment): Observable<any> { updateComment(comment: Comment): Observable<any> {
return this.http.put(this.commentsUrl, comment, httpOptions).pipe( return this.http.put(this.commentsUrl, comment, httpOptions).pipe(
tap(_ => ''), tap(_ => ''),
......
export class Comment { export class Comment {
id: string; id: string;
roomId: string; roomId: string;
userId: number;
revision: string; revision: string;
subject: string; subject: string;
body: string; body: string;
......
<div fxLayout="column" fxLayoutAlign="center" fxLayoutGap="10"> <div fxLayout="row" fxLayoutAlign="center">
<form> <div fxLayout="column" fxLayoutGap="20">
<mat-form-field class="input-block"> <form>
<input matInput #commentSubject type="text" maxlength="24" placeholder="Choose a title"> <mat-form-field class="input-block">
</mat-form-field> <input matInput #commentSubject type="text" maxlength="24" placeholder="Choose a title">
<mat-form-field class="input-block"> </mat-form-field>
<input matInput #commentBody> <mat-form-field class="input-block">
<textarea matInput placeholder="Add your comment"></textarea> <input matInput #commentBody>
</mat-form-field> <textarea matInput placeholder="Add your comment"></textarea>
</mat-form-field>
<button mat-raised-button color="primary" (click)="goBack()">Back</button> <button mat-raised-button color="primary" (click)="goBack()">Back</button>
<button mat-raised-button color="primary" (click)="send(commentSubject.value, commentBody.value)">Send</button> <button mat-raised-button color="primary" (click)="send(commentSubject.value, commentBody.value)">Send</button>
</form> </form>
</div>
</div> </div>
<app-comment-list></app-comment-list>
form {
min-width: 800px;
justify-content: center;
margin-bottom: 50px;
}
import { Component, OnInit, Input } from '@angular/core'; import { Component, OnInit, Input, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import { Room } from '../room'; import { Room } from '../room';
import { Comment } from '../comment'; import { Comment } from '../comment';
import { RoomService } from '../room.service'; import { RoomService } from '../room.service';
import { CommentService} from '../comment.service'; import { CommentService } from '../comment.service';
import { NotificationService } from '../notification.service'; import { NotificationService } from '../notification.service';
import { Router } from '@angular/router'; import { AuthenticationService } from '../authentication.service';
import { User } from '../user';
import { CommentListComponent } from '../comment-list/comment-list.component';
@Component({ @Component({
selector: 'app-create-comment', selector: 'app-create-comment',
...@@ -14,10 +16,12 @@ import { Router } from '@angular/router'; ...@@ -14,10 +16,12 @@ import { Router } from '@angular/router';
styleUrls: ['./create-comment.component.scss'] styleUrls: ['./create-comment.component.scss']
}) })
export class CreateCommentComponent implements OnInit { export class CreateCommentComponent implements OnInit {
@ViewChild(CommentListComponent) child: CommentListComponent;
@Input() room: Room; @Input() room: Room;
user: User;
constructor( constructor(
private router: Router, protected authenticationService: AuthenticationService,
private route: ActivatedRoute, private route: ActivatedRoute,
private roomService: RoomService, private roomService: RoomService,
private commentService: CommentService, private commentService: CommentService,
...@@ -25,6 +29,7 @@ export class CreateCommentComponent implements OnInit { ...@@ -25,6 +29,7 @@ export class CreateCommentComponent implements OnInit {
private notification: NotificationService) { } private notification: NotificationService) { }
ngOnInit(): void { ngOnInit(): void {
this.user = this.authenticationService.getUser();
this.route.params.subscribe(params => { this.route.params.subscribe(params => {
this.getRoom(params['roomId']); this.getRoom(params['roomId']);
}); });
...@@ -42,11 +47,12 @@ export class CreateCommentComponent implements OnInit { ...@@ -42,11 +47,12 @@ export class CreateCommentComponent implements OnInit {
} }
this.commentService.addComment({ this.commentService.addComment({
roomId: this.room.id, roomId: this.room.id,
userId: this.user.id,
subject: subject, subject: subject,
body: body, body: body,
creationTimestamp: new Date(Date.now()) creationTimestamp: new Date(Date.now())
} as Comment).subscribe(() => { } as Comment).subscribe(() => {
this.router.navigate([`/participant/room/${this.room.id}`]); this.child.getComments(this.room.id);
this.notification.show(`Comment '${subject}' successfully created.`); this.notification.show(`Comment '${subject}' successfully created.`);
}); });
} }
......
...@@ -56,6 +56,7 @@ export class InMemoryDataService implements InMemoryDbService { ...@@ -56,6 +56,7 @@ export class InMemoryDataService implements InMemoryDbService {
{ {
id: '1', id: '1',
roomId: '1', roomId: '1',
userId: '1',
revision: '', revision: '',
subject: 'testcomment', subject: 'testcomment',
body: 'adsasdasdasdasdas', body: 'adsasdasdasdasdas',
...@@ -65,6 +66,7 @@ export class InMemoryDataService implements InMemoryDbService { ...@@ -65,6 +66,7 @@ export class InMemoryDataService implements InMemoryDbService {
{ {
id: '2', id: '2',
roomId: '1', roomId: '1',
userId: '2',
revision: '', revision: '',
subject: 'asdaskldmaskld', subject: 'asdaskldmaskld',
body: 'knkdiasslkladskmdaskld', body: 'knkdiasslkladskmdaskld',
...@@ -74,6 +76,7 @@ export class InMemoryDataService implements InMemoryDbService { ...@@ -74,6 +76,7 @@ export class InMemoryDataService implements InMemoryDbService {
{ {
id: '3', id: '3',
roomId: '2', roomId: '2',
userId: '1',
revision: '', revision: '',
subject: 'testcomment', subject: 'testcomment',
body: 'adsasdasdasdasdas', body: 'adsasdasdasdasdas',
......
...@@ -23,9 +23,6 @@ ...@@ -23,9 +23,6 @@
<button mat-button color="primary" matTooltip="Join question round"> <button mat-button color="primary" matTooltip="Join question round">
Questions Questions
</button> </button>
<button mat-button color="primary" matTooltip="See room comments">
Comments
</button>
<button mat-button color="primary" matTooltip="Start personal question round"> <button mat-button color="primary" matTooltip="Start personal question round">
Learn Learn
</button> </button>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment