diff --git a/src/app/components/shared/comment-list/comment-list.component.html b/src/app/components/shared/comment-list/comment-list.component.html index d354898592fe69fc14e0a901ba76bf6aaf2b7404..7dc78df32d5c92b3cc447133e9593ca8783ce604 100644 --- a/src/app/components/shared/comment-list/comment-list.component.html +++ b/src/app/components/shared/comment-list/comment-list.component.html @@ -1,4 +1,4 @@ <mat-toolbar >List of Questions</mat-toolbar> -<mat-card class="outer-card"> +<mat-card> <app-comment *ngFor="let current of comments" [comment]="current"> </app-comment> </mat-card> diff --git a/src/app/components/shared/comment-list/comment-list.component.scss b/src/app/components/shared/comment-list/comment-list.component.scss index 49f857654aa1538adaa7a7eb21b3c8892f10c5a3..d139cec51fb40e51e11e9efcbbd42618e5243698 100644 --- a/src/app/components/shared/comment-list/comment-list.component.scss +++ b/src/app/components/shared/comment-list/comment-list.component.scss @@ -1,10 +1,7 @@ mat-card { margin-bottom: 20px; background-color: #b2ebf2; -} - -mat-card-content>:first-child { - margin-top: 20px; + border-radius: 8px; } mat-toolbar { @@ -12,7 +9,3 @@ mat-toolbar { margin-bottom: 20px; background-color: #bbdefb; } - -.outer-card { - border-radius: 8px; -} diff --git a/src/app/components/shared/comment-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts index 4c4dd71762068a2af36b8a195f6c81bc5e0a072f..2ddda0f5e2493edc87ff47aa9bded231d02ec400 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -1,13 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; -import { Location } from '@angular/common'; import { Comment } from '../../../models/comment'; import { CommentService } from '../../../services/http/comment.service'; -import { RoomService } from '../../../services/http/room.service'; -import { NotificationService } from '../../../services/util/notification.service'; -import { AuthenticationService } from '../../../services/http/authentication.service'; -import { UserRole } from '../../../models/user-roles.enum'; -import { User } from '../../../models/user'; import { TranslateService } from '@ngx-translate/core'; import { LanguageService } from '../../../services/util/language.service'; @@ -17,28 +10,17 @@ import { LanguageService } from '../../../services/util/language.service'; styleUrls: ['./comment-list.component.scss'] }) export class CommentListComponent implements OnInit { - userRole: UserRole; - user: User; comments: Comment[]; isLoading = true; roomId: string; - roomShortId: string; - constructor(protected authenticationService: AuthenticationService, - private route: ActivatedRoute, - private roomService: RoomService, - private location: Location, - private commentService: CommentService, - private notification: NotificationService, + constructor(private commentService: CommentService, private translateService: TranslateService, protected langService: LanguageService) { langService.langEmitter.subscribe(lang => translateService.use(lang)); } ngOnInit() { - this.userRole = this.authenticationService.getRole(); - this.user = this.authenticationService.getUser(); - this.roomShortId = this.route.snapshot.paramMap.get('roomId'); this.roomId = localStorage.getItem(`roomId`); this.getComments(); this.translateService.use(localStorage.getItem('currentLang')); diff --git a/src/app/components/shared/comment/comment.component.html b/src/app/components/shared/comment/comment.component.html index 5293d2f6504fad0399b72aaf98d9a64c266f64b4..c5632f8306b4751e440fdbeb144d0a135a1b1d03 100644 --- a/src/app/components/shared/comment/comment.component.html +++ b/src/app/components/shared/comment/comment.component.html @@ -2,9 +2,15 @@ <div fxLayout="row" fxLayoutAlign="center center"> <mat-card-title>{{comment.subject}}</mat-card-title> <span class="fill-remaining-space"></span> - <button mat-icon-button [disabled]="userRole === 0" (click)="setCorrect(comment)" [matTooltip]="comment.correct ? 'Anwort richtig' : null"> + <button mat-icon-button [disabled]="isCreator" (click)="setCorrect(comment)" [matTooltip]="comment.correct ? 'Unmark as correct' : 'Mark as correct'"> <mat-icon [ngClass]="{'correct-icon' : comment.correct === true}">check_circle</mat-icon> </button> + <button mat-icon-button [disabled]="isCreator" (click)="setFavorite(comment)" [matTooltip]="comment.favorite ? 'Mark as not favorite' : 'Mark as favorite'"> + <mat-icon [ngClass]="{'favorite-icon' : comment.favorite === true}">star</mat-icon> + </button> + <button mat-icon-button [disabled]="isCreator" (click)="setRead(comment)" [matTooltip]="comment.read ? 'Mark as unread' : 'Mark as read'"> + <mat-icon [ngClass]="{'read-icon' : comment.read === true}">visibility</mat-icon> + </button> </div> <mat-divider></mat-divider> <mat-card-content> diff --git a/src/app/components/shared/comment/comment.component.scss b/src/app/components/shared/comment/comment.component.scss index 52e87c8f4d46dd26bbe4eadcc2af352633c54a62..5b2b2e943000acee64474d83954a59110c35fb67 100644 --- a/src/app/components/shared/comment/comment.component.scss +++ b/src/app/components/shared/comment/comment.component.scss @@ -1,6 +1,7 @@ mat-card { margin-bottom: 20px; - background-color: #b2ebf2; + background-color: #4dd0e1; + cursor: pointer; } mat-card-content>:first-child { @@ -13,28 +14,18 @@ mat-toolbar { background-color: #bbdefb; } -.card-container { - background-color: #4dd0e1; - opacity: 0.7; - border-radius: 2px; -} - -.outer-card { - border-radius: 8px; -} - mat-icon { color: white; } -.incorrect-icon { - color: white; -} - .correct-icon { color: green; } -mat-card-title { - margin: 0px; +.read-icon { + color: blue; +} + +.favorite-icon { + color: #fdd835; } diff --git a/src/app/components/shared/comment/comment.component.ts b/src/app/components/shared/comment/comment.component.ts index dbbff9b61a1231e154d6ca05efa0ab971d2e0721..0a7b94d7b03ccd714d9ece9b3213bd20b238fbf9 100644 --- a/src/app/components/shared/comment/comment.component.ts +++ b/src/app/components/shared/comment/comment.component.ts @@ -1,7 +1,5 @@ import { Component, Input, OnInit } from '@angular/core'; import { Comment } from '../../../models/comment'; -import { UserRole } from '../../../models/user-roles.enum'; -import { User } from '../../../models/user'; import { AuthenticationService } from '../../../services/http/authentication.service'; import { ActivatedRoute } from '@angular/router'; import { Location } from '@angular/common'; @@ -17,8 +15,7 @@ import { LanguageService } from '../../../services/util/language.service'; }) export class CommentComponent implements OnInit { @Input() comment: Comment; - userRole: UserRole; - user: User; + isCreator = false; isLoading = true; constructor(protected authenticationService: AuthenticationService, @@ -31,12 +28,14 @@ export class CommentComponent implements OnInit { langService.langEmitter.subscribe(lang => translateService.use(lang)); } ngOnInit() { - this.userRole = this.authenticationService.getRole(); - this.user = this.authenticationService.getUser(); + if (this.authenticationService.getRole() === 0) { + this.isCreator = true; + } this.translateService.use(localStorage.getItem('currentLang')); } setRead(comment: Comment): void { + comment.read = !comment.read; this.commentService.updateComment(comment).subscribe(); } @@ -45,6 +44,11 @@ export class CommentComponent implements OnInit { this.commentService.updateComment(comment).subscribe(); } + setFavorite(comment: Comment): void { + comment.favorite = !comment.favorite; + this.commentService.updateComment(comment).subscribe(); + } + delete(comment: Comment): void { this.commentService.deleteComment(comment.id).subscribe(room => { this.notification.show(`Comment '${comment.subject}' successfully deleted.`); diff --git a/src/app/models/comment.ts b/src/app/models/comment.ts index f13906b2c77f00e9b483ad0470e2dadf375f48d0..d9560745a18b931c5c95f97ece5d410ea7ded5cc 100644 --- a/src/app/models/comment.ts +++ b/src/app/models/comment.ts @@ -7,5 +7,26 @@ export class Comment { body: string; read: boolean; correct: boolean; + favorite: boolean; creationTimestamp: number; + + constructor(roomId: string, + userId: string, + subject: string, + body: string, + read: boolean, + correct: boolean, + favorite: boolean, + creationTimestamp: number) { + this.id = ''; + this.roomId = roomId; + this.userId = userId; + this.revision = ''; + this.subject = subject; + this.body = body; + this.read = read; + this.correct = correct; + this.favorite = favorite; + this.creationTimestamp = creationTimestamp; + } }