diff --git a/src/app/components/creator/comment-creator-page/comment-creator-page.component.html b/src/app/components/creator/comment-creator-page/comment-creator-page.component.html index cb304da36e93923b448b9828927e96afbd907ab6..2445a6fcae34f3159b6597b46220b8fe37935acc 100644 --- a/src/app/components/creator/comment-creator-page/comment-creator-page.component.html +++ b/src/app/components/creator/comment-creator-page/comment-creator-page.component.html @@ -1,3 +1 @@ -<div fxLayout="row" fxLayoutAlign="center"> - <app-comment-list></app-comment-list> -</div> +<app-comment-page></app-comment-page> diff --git a/src/app/components/participant/comment-create-page/comment-create-page.component.html b/src/app/components/participant/comment-create-page/comment-create-page.component.html deleted file mode 100644 index 15f1a94f992f3905d07b32dbcfa26964dfd73334..0000000000000000000000000000000000000000 --- a/src/app/components/participant/comment-create-page/comment-create-page.component.html +++ /dev/null @@ -1,22 +0,0 @@ -<div fxLayout="column" fxLayoutAlign="center" fxLayoutGap="20px"> - <div fxLayout="row" fxLayoutAlign="center"> - <form> - <mat-form-field class="input-block"> - <input matInput #commentSubject type="text" maxlength="25" - placeholder="{{ 'comment-page.enter-title' | translate}}" onkeypress="return event.keyCode !=13;" - [formControl]="subjectForm"> - <mat-hint align="end">{{commentSubject.value.length}} / 25</mat-hint> - </mat-form-field> - <mat-form-field class="input-block"> - <textarea matInput #commentBody placeholder="{{ 'comment-page.enter-comment' | translate}}" - matAutosizeMinRows=2 matAutosizeMaxRows=5 maxlength="255" [formControl]="bodyForm"></textarea> - <mat-hint align="end">{{commentBody.value.length}} / 255</mat-hint> - </mat-form-field> - <button mat-raised-button color="accent" - (click)="send(commentSubject.value, commentBody.value)">{{ 'comment-page.send' | translate}}</button> - </form> - </div> - <div fxLayout="row" fxLayoutAlign="center"> - <app-comment-list></app-comment-list> - </div> -</div> diff --git a/src/app/components/participant/comment-create-page/comment-create-page.component.ts b/src/app/components/participant/comment-create-page/comment-create-page.component.ts deleted file mode 100644 index cc9a856544b82c240dd9b5a82583696266feb1dc..0000000000000000000000000000000000000000 --- a/src/app/components/participant/comment-create-page/comment-create-page.component.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { Component, OnInit, ViewChild } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; -import { FormControl, Validators } from '@angular/forms'; -import { TranslateService } from '@ngx-translate/core'; -import { Comment } from '../../../models/comment'; -import { CommentService } from '../../../services/http/comment.service'; -import { NotificationService } from '../../../services/util/notification.service'; -import { AuthenticationService } from '../../../services/http/authentication.service'; -import { User } from '../../../models/user'; -import { CommentListComponent } from '../../shared/comment-list/comment-list.component'; - -@Component({ - selector: 'app-comment-create-page', - templateUrl: './comment-create-page.component.html', - styleUrls: ['./comment-create-page.component.scss'] -}) -export class CommentCreatePageComponent implements OnInit { - @ViewChild(CommentListComponent) child: CommentListComponent; - roomId: string; - roomShortId: string; - user: User; - private date = new Date(Date.now()); - subjectForm = new FormControl('', [Validators.required]); - bodyForm = new FormControl('', [Validators.required]); - - - constructor( - protected authenticationService: AuthenticationService, - private route: ActivatedRoute, - private commentService: CommentService, - private notification: NotificationService, - private translationService: TranslateService) { } - - ngOnInit(): void { - this.user = this.authenticationService.getUser(); - this.roomShortId = this.route.snapshot.paramMap.get('roomId'); - this.roomId = localStorage.getItem(`roomId`); - } - - send(subject: string, body: string): void { - subject = subject.trim(); - body = body.trim(); - if (!subject && !body) { - this.translationService.get('comment-page.error-both-fields').subscribe(message => { - this.notification.show(message); - }); - return; - } - if (!subject) { - this.translationService.get('comment-page.error-title').subscribe(message => { - this.notification.show(message); - }); - return; - } - if (!body) { - this.translationService.get('comment-page.error-comment').subscribe(message => { - this.notification.show(message); - }); - return; - } - this.commentService.addComment({ - id: '', - roomId: this.roomId, - userId: this.user.id, - subject: subject, - body: body, - creationTimestamp: this.date.getTime(), - read: false, - revision: '' - } as Comment).subscribe(() => { - this.child.getComments(); - this.notification.show(`Comment '${subject}' successfully created.`); - }); - } -} diff --git a/src/app/components/participant/comment-participant-page/comment-participant-page.component.html b/src/app/components/participant/comment-participant-page/comment-participant-page.component.html new file mode 100644 index 0000000000000000000000000000000000000000..2445a6fcae34f3159b6597b46220b8fe37935acc --- /dev/null +++ b/src/app/components/participant/comment-participant-page/comment-participant-page.component.html @@ -0,0 +1 @@ +<app-comment-page></app-comment-page> diff --git a/src/app/components/participant/comment-participant-page/comment-participant-page.component.scss b/src/app/components/participant/comment-participant-page/comment-participant-page.component.scss new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/app/components/participant/comment-participant-page/comment-participant-page.component.spec.ts b/src/app/components/participant/comment-participant-page/comment-participant-page.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..6287f88a12f29bf8718cfa17ad8ef9dc0ea7b490 --- /dev/null +++ b/src/app/components/participant/comment-participant-page/comment-participant-page.component.spec.ts @@ -0,0 +1,27 @@ +/* +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CommentParticipantPageComponent } from './comment-participant-page.component'; + +describe('CommentParticipantPageComponent', () => { + let component: CommentParticipantPageComponent; + let fixture: ComponentFixture<CommentParticipantPageComponent>; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CommentParticipantPageComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CommentParticipantPageComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); +*/ diff --git a/src/app/components/participant/comment-participant-page/comment-participant-page.component.ts b/src/app/components/participant/comment-participant-page/comment-participant-page.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..e652a59ef795450533ed4f834ce437bfe4545ee8 --- /dev/null +++ b/src/app/components/participant/comment-participant-page/comment-participant-page.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-comment-participant-page', + templateUrl: './comment-participant-page.component.html', + styleUrls: ['./comment-participant-page.component.scss'] +}) +export class CommentParticipantPageComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/components/participant/participant-routing.module.ts b/src/app/components/participant/participant-routing.module.ts index b4b33c4e59fc1066fbfb6dae8a08a82d82ccb22b..1b6054cae8add874cad84fa73b8b247118b9549c 100644 --- a/src/app/components/participant/participant-routing.module.ts +++ b/src/app/components/participant/participant-routing.module.ts @@ -4,11 +4,11 @@ import { HomeParticipantPageComponent } from './home-participant-page/home-parti import { AuthenticationGuard } from '../../guards/authentication.guard'; import { UserRole } from '../../models/user-roles.enum'; import { RoomParticipantPageComponent } from './room-participant-page/room-participant-page.component'; -import { CommentCreatePageComponent } from './comment-create-page/comment-create-page.component'; import { FeedbackBarometerPageComponent } from '../shared/feedback-barometer-page/feedback-barometer-page.component'; import { ParticipantContentCarouselPageComponent } from './participant-content-carousel-page/participant-content-carousel-page.component'; import { StatisticsPageComponent } from '../shared/statistics-page/statistics-page.component'; import { StatisticComponent } from '../shared/statistic/statistic.component'; +import { CommentParticipantPageComponent } from './comment-participant-page/comment-participant-page.component'; const routes: Routes = [ { @@ -36,8 +36,8 @@ const routes: Routes = [ data: { roles: [UserRole.PARTICIPANT] } }, { - path: 'room/:roomId/create-comment', - component: CommentCreatePageComponent, + path: 'room/:roomId/comments', + component: CommentParticipantPageComponent, canActivate: [AuthenticationGuard], data: { roles: [UserRole.PARTICIPANT] } }, diff --git a/src/app/components/participant/participant.module.ts b/src/app/components/participant/participant.module.ts index 77d5bb07717cd9433c3260a33bf96838a0bd9fda..640952e86f8c4ee683e67d86574822321a401f5f 100644 --- a/src/app/components/participant/participant.module.ts +++ b/src/app/components/participant/participant.module.ts @@ -11,6 +11,7 @@ import { ParticipantContentCarouselPageComponent } from './participant-content-c import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; import { HttpClient } from '@angular/common/http'; import { TranslateHttpLoader } from '@ngx-translate/http-loader'; +import { CommentParticipantPageComponent } from './comment-participant-page/comment-participant-page.component'; @NgModule({ imports: [ @@ -32,7 +33,8 @@ import { TranslateHttpLoader } from '@ngx-translate/http-loader'; ContentTextParticipantComponent, HomeParticipantPageComponent, RoomParticipantPageComponent, - ParticipantContentCarouselPageComponent + ParticipantContentCarouselPageComponent, + CommentParticipantPageComponent ] }) export class ParticipantModule { diff --git a/src/app/components/participant/room-participant-page/room-participant-page.component.html b/src/app/components/participant/room-participant-page/room-participant-page.component.html index c361e9994ecc4f6cb84c41cc0c8c464e4ef89283..1688c13b407b0ee678043692e076a096f8f2b316 100644 --- a/src/app/components/participant/room-participant-page/room-participant-page.component.html +++ b/src/app/components/participant/room-participant-page/room-participant-page.component.html @@ -24,7 +24,7 @@ <mat-grid-list cols="3" rowHeight="2:1"> <mat-grid-tile> <button mat-icon-button color="primary" matTooltip="{{ 'room-page.create-comment' | translate}}" - routerLink="/participant/room/{{ room.id }}/create-comment"> + routerLink="/participant/room/{{ room.shortId }}/comments"> <mat-icon>question_answer</mat-icon> </button> </mat-grid-tile> diff --git a/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.html b/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.html new file mode 100644 index 0000000000000000000000000000000000000000..ac95224c073f242c673681e05e688c0f5763b55d --- /dev/null +++ b/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.html @@ -0,0 +1,21 @@ +<div fxLayout="column" fxLayoutAlign="center" fxLayoutGap="20px"> + <div fxLayout="row" fxLayoutAlign="center"> + <form> + <mat-form-field class="input-block"> + <input matInput #commentSubject type="text" maxlength="25" + placeholder="{{ 'comment-page.enter-title' | translate}}" onkeypress="return event.keyCode !=13;" + [formControl]="subjectForm"> + <mat-hint align="end">{{commentSubject.value.length}} / 25</mat-hint> + </mat-form-field> + <mat-form-field class="input-block"> + <textarea matInput #commentBody placeholder="{{ 'comment-page.enter-comment' | translate}}" + matAutosizeMinRows=2 matAutosizeMaxRows=5 maxlength="255" [formControl]="bodyForm"></textarea> + <mat-hint align="end">{{commentBody.value.length}} / 255</mat-hint> + </mat-form-field> + <button mat-raised-button color="warn" + (click)="onNoClick()">{{ 'comment-page.abort' | translate}}</button> + <button mat-raised-button color="accent" + (click)="closeDialog(commentSubject.value, commentBody.value)">{{ 'comment-page.send' | translate}}</button> + </form> + </div> +</div> diff --git a/src/app/components/participant/comment-create-page/comment-create-page.component.scss b/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.scss similarity index 80% rename from src/app/components/participant/comment-create-page/comment-create-page.component.scss rename to src/app/components/shared/_dialogs/submit-comment/submit-comment.component.scss index 1f1de2f029615a8edeffb46607ba3e95c63eb6a8..64d37795cb2553d976925ff104209d2908273552 100644 --- a/src/app/components/participant/comment-create-page/comment-create-page.component.scss +++ b/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.scss @@ -1,3 +1,8 @@ +button { + margin-right: 20px; + min-width: 80px; +} + form { display: block; width: 100%; diff --git a/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.spec.ts b/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..730881f3daa422eb190a18e9dc1b3e73fbdd6d99 --- /dev/null +++ b/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.spec.ts @@ -0,0 +1,27 @@ +/* +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { SubmitCommentComponent } from './submit-comment.component'; + +describe('SubmitCommentComponent', () => { + let component: SubmitCommentComponent; + let fixture: ComponentFixture<SubmitCommentComponent>; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ SubmitCommentComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(SubmitCommentComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); +*/ diff --git a/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.ts b/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..6e2f2fb70c95335c43892a35bbf823f87307f434 --- /dev/null +++ b/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.ts @@ -0,0 +1,81 @@ +import { Component, Inject, OnInit } from '@angular/core'; +import { Comment } from '../../../../models/comment'; +import { ActivatedRoute } from '@angular/router'; +import { NotificationService } from '../../../../services/util/notification.service'; +import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material'; +import { TranslateService } from '@ngx-translate/core'; +import { CommentPageComponent } from '../../comment-page/comment-page.component'; +import { AuthenticationService } from '../../../../services/http/authentication.service'; +import { FormControl, Validators } from '@angular/forms'; +import { User } from '../../../../models/user'; + + +@Component({ + selector: 'app-submit-comment', + templateUrl: './submit-comment.component.html', + styleUrls: ['./submit-comment.component.scss'] +}) +export class SubmitCommentComponent implements OnInit { + + comment: Comment; + + user: User; + + subjectForm = new FormControl('', [Validators.required]); + bodyForm = new FormControl('', [Validators.required]); + private date = new Date(Date.now()); + + constructor(private route: ActivatedRoute, + private notification: NotificationService, + public dialogRef: MatDialogRef<CommentPageComponent>, + private translateService: TranslateService, + protected authenticationService: AuthenticationService, + public dialog: MatDialog, + private translationService: TranslateService, + @Inject(MAT_DIALOG_DATA) public data: any) { + } + + ngOnInit() { + this.translateService.use(localStorage.getItem('currentLang')); + this.user = this.authenticationService.getUser(); + } + + onNoClick(): void { + this.dialogRef.close(); + } + + checkInputData(subject: string, body: string): boolean { + subject = subject.trim(); + body = body.trim(); + if (!subject && !body) { + this.translationService.get('comment-page.error-both-fields').subscribe(message => { + this.notification.show(message); + }); + return false; + } + if (!subject) { + this.translationService.get('comment-page.error-title').subscribe(message => { + this.notification.show(message); + }); + return false; + } + if (!body) { + this.translationService.get('comment-page.error-comment').subscribe(message => { + this.notification.show(message); + }); + return false; + } + return true; + } + + closeDialog(subject: string, body: string) { + if (this.checkInputData(subject, body) === true) { + const comment = new Comment(); + comment.roomId = localStorage.getItem(`roomId`); + comment.subject = subject; + comment.body = body; + comment.userId = this.user.id; + this.dialogRef.close(comment); + } + } +} 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 c08119116161a855547715a19a1411dc3a1a0925..e0954c5d50aae7784f6dc7f0229d9f2f22539a1e 100644 --- a/src/app/components/shared/comment-list/comment-list.component.scss +++ b/src/app/components/shared/comment-list/comment-list.component.scss @@ -7,6 +7,15 @@ app-comment { overflow: auto; overflow-wrap: break-word; } +mat-card-content>:first-child { + margin-top: 20px; +} + +mat-toolbar { + border-radius: 10px; + margin-bottom: 20px; + background-color: #bbdefb; +} .card-container { background-color: #b2dfdb; 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 4984c231307fedeef55ead29cacbb0f388da571c..29fd368e1e7efef1501959bee7f609c227cc8b86 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -1,15 +1,8 @@ import { Component, OnInit } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; -import { Location } from '@angular/common'; import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators'; import { Observable, Subject } from 'rxjs'; 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'; @@ -19,30 +12,19 @@ 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; private searchTerms = new Subject<string>(); comments$: Observable<Comment[]>; - 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.comments$ = this.searchTerms.pipe( diff --git a/src/app/components/shared/comment-page/comment-page.component.html b/src/app/components/shared/comment-page/comment-page.component.html new file mode 100644 index 0000000000000000000000000000000000000000..a0d67ae5eaf0e03312cd2cc9770003e902c23c40 --- /dev/null +++ b/src/app/components/shared/comment-page/comment-page.component.html @@ -0,0 +1,13 @@ +<div fxLayout="column" fxLayoutAlign="center" fxLayoutGap="20px"> + <div fxLayout="row" fxLayoutAlign="center"> + <mat-toolbar>List of Questions + <span class="fill-remaining-space"></span> + <button mat-icon-button color="primary" (click)="openSubmitDialog()"> + <mat-icon>add_circle</mat-icon> + </button></mat-toolbar> + </div> + <div fxLayout="row" fxLayoutAlign="center"> + <app-comment-list></app-comment-list> + </div> +</div> + diff --git a/src/app/components/shared/comment-page/comment-page.component.scss b/src/app/components/shared/comment-page/comment-page.component.scss new file mode 100644 index 0000000000000000000000000000000000000000..3eeff504832295d9e4654f7e2acf0a6193f9c196 --- /dev/null +++ b/src/app/components/shared/comment-page/comment-page.component.scss @@ -0,0 +1,24 @@ +app-comment-list { + width: 100%; + max-width: 800px; +} + +.mat-icon-button { + width: 50px; + height: 50px; + margin-bottom: 20px; + margin-top: 20px; +} + +mat-icon { + font-size: 50px; + height: 50px; + width: 50px; + line-height: 100%!important; +} + +mat-toolbar { + border-radius: 10px; + background-color: #bbdefb; + max-width: 800px; +} diff --git a/src/app/components/participant/comment-create-page/comment-create-page.component.spec.ts b/src/app/components/shared/comment-page/comment-page.component.spec.ts similarity index 51% rename from src/app/components/participant/comment-create-page/comment-create-page.component.spec.ts rename to src/app/components/shared/comment-page/comment-page.component.spec.ts index 5db9a7cbab98cfbc030de539c2b687a12c506703..de9e0a549095b50aebd1bcd4d020a2a1b99510ca 100644 --- a/src/app/components/participant/comment-create-page/comment-create-page.component.spec.ts +++ b/src/app/components/shared/comment-page/comment-page.component.spec.ts @@ -1,20 +1,20 @@ /* import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { CommentCreatePageComponent } from './comment-create-page.component'; +import { CommentPageComponent } from './comment-page.component'; -describe('CommentCreatePageComponent', () => { - let component: CommentCreatePageComponent; - let fixture: ComponentFixture<CommentCreatePageComponent>; +describe('CommentPageComponent', () => { + let component: CommentPageComponent; + let fixture: ComponentFixture<CommentPageComponent>; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ CommentCreatePageComponent ] + declarations: [ CommentPageComponent ] }) .compileComponents(); })); beforeEach(() => { - fixture = TestBed.createComponent(CommentCreatePageComponent); + fixture = TestBed.createComponent(CommentPageComponent); component = fixture.componentInstance; fixture.detectChanges(); }); diff --git a/src/app/components/shared/comment-page/comment-page.component.ts b/src/app/components/shared/comment-page/comment-page.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..bb09927e14b6cfbc1ad1c9cc155f9106a22622b8 --- /dev/null +++ b/src/app/components/shared/comment-page/comment-page.component.ts @@ -0,0 +1,56 @@ +import { Component, OnInit, ViewChild } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { Comment } from '../../../models/comment'; +import { CommentService } from '../../../services/http/comment.service'; +import { NotificationService } from '../../../services/util/notification.service'; +import { CommentListComponent } from '../comment-list/comment-list.component'; +import { MatDialog } from '@angular/material'; +import { SubmitCommentComponent } from '../_dialogs/submit-comment/submit-comment.component'; + +@Component({ + selector: 'app-comment-page', + templateUrl: './comment-page.component.html', + styleUrls: ['./comment-page.component.scss'] +}) +export class CommentPageComponent implements OnInit { + @ViewChild(CommentListComponent) child: CommentListComponent; + + constructor(private route: ActivatedRoute, + private commentService: CommentService, + private notification: NotificationService, + public dialog: MatDialog) { } + + ngOnInit(): void { + } + + openSubmitDialog(): void { + const dialogRef = this.dialog.open(SubmitCommentComponent, { + width: '400px' + }); + dialogRef.afterClosed() + .subscribe(result => { + if (result) { + this.send(result); + } else { + return; + } + }); + } + + send(comment: Comment): void { + this.commentService.addComment({ + id: '', + roomId: comment.roomId, + userId: comment.userId, + subject: comment.subject, + body: comment.body, + creationTimestamp: comment.creationTimestamp, + read: false, + revision: '' + } as Comment).subscribe(() => { + this.child.getComments(); + this.notification.show(`Comment '${comment.subject}' successfully created.`); + }); + + } +} 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/components/shared/shared.module.ts b/src/app/components/shared/shared.module.ts index 7370a65112733d2088832c348afd509a1aab15c6..a392ad54b6d5208dc6b747b4ed448a411053179f 100644 --- a/src/app/components/shared/shared.module.ts +++ b/src/app/components/shared/shared.module.ts @@ -11,7 +11,7 @@ import { RoomPageComponent } from './room-page/room-page.component'; import { StatisticsPageComponent } from './statistics-page/statistics-page.component'; import { AnswerEditComponent } from '../creator/_dialogs/answer-edit/answer-edit.component'; import { ContentDeleteComponent } from '../creator/_dialogs/content-delete/content-delete.component'; -import { CommentCreatePageComponent } from '../participant/comment-create-page/comment-create-page.component'; +import { CommentPageComponent } from './comment-page/comment-page.component'; import { EssentialsModule } from '../essentials/essentials.module'; import { SharedRoutingModule } from './shared-routing.module'; import { ListStatisticComponent } from './list-statistic/list-statistic.component'; @@ -22,6 +22,7 @@ import { RoomCreateComponent } from './_dialogs/room-create/room-create.componen import { LoginComponent } from './login/login.component'; import { StatisticHelpComponent } from './_dialogs/statistic-help/statistic-help.component'; import { CommentComponent } from './comment/comment.component'; +import { SubmitCommentComponent } from './_dialogs/submit-comment/submit-comment.component'; @NgModule({ imports: [ @@ -42,7 +43,7 @@ import { CommentComponent } from './comment/comment.component'; FeedbackBarometerPageComponent, FooterComponent, FeedbackBarometerPageComponent, - CommentCreatePageComponent, + CommentPageComponent, CommentListComponent, StatisticsPageComponent, ListStatisticComponent, @@ -50,7 +51,8 @@ import { CommentComponent } from './comment/comment.component'; RoomCreateComponent, LoginComponent, StatisticHelpComponent, - CommentComponent + CommentComponent, + SubmitCommentComponent ], exports: [ RoomJoinComponent, @@ -64,14 +66,16 @@ import { CommentComponent } from './comment/comment.component'; FeedbackBarometerPageComponent, FooterComponent, FeedbackBarometerPageComponent, - CommentCreatePageComponent, + CommentPageComponent, CommentListComponent, - StatisticsPageComponent + StatisticsPageComponent, + SubmitCommentComponent ], entryComponents: [ RoomCreateComponent, LoginComponent, - StatisticHelpComponent + StatisticHelpComponent, + SubmitCommentComponent ] }) export class SharedModule { diff --git a/src/app/models/comment.ts b/src/app/models/comment.ts index f13906b2c77f00e9b483ad0470e2dadf375f48d0..14e32bda25f4953022fd905d46062bc33448a9ee 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 = false, + correct: boolean = false, + favorite: boolean = false, + creationTimestamp: number = 0) { + 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; + } } diff --git a/src/assets/i18n/creator/de.json b/src/assets/i18n/creator/de.json index fc217ecfe13da1f97bd4153c2faa4fe244ab9ddd..f494d47d6f12901634200c242e69358cf1b86742 100644 --- a/src/assets/i18n/creator/de.json +++ b/src/assets/i18n/creator/de.json @@ -74,5 +74,14 @@ "good": "Gut", "improvable": "Luft nach oben", "no-answers": "Keine Antworten" + }, + "comment-page": { + "enter-title": "Titel", + "enter-comment": "Kommentar", + "send": "Senden", + "abort": "Abbrechen", + "error-comment": "Bitte geben Sie ein Kommentar ein!", + "error-title": "Bitte geben Sie einen Titel ein!", + "error-both-fields": "Bitte füllen Sie alle Felder aus!" } } diff --git a/src/assets/i18n/creator/en.json b/src/assets/i18n/creator/en.json index 5e41476d28f485686cbfa9061de0142afb769fef..39316b0f55af67d71404bb6e410152bf39411707 100644 --- a/src/assets/i18n/creator/en.json +++ b/src/assets/i18n/creator/en.json @@ -74,5 +74,14 @@ "good": "Good", "improvable": "Improvable", "no-answers": "No answers" + }, + "comment-page": { + "enter-title": "Title", + "enter-comment": "Comment", + "send": "Send", + "abort": "Cancel", + "error-title": "Please enter a title!", + "error-comment": "Please enter a comment!", + "error-both-fields": "Please fill in all fields!" } } diff --git a/src/assets/i18n/participant/de.json b/src/assets/i18n/participant/de.json index 37260531ecbbabbcfe1dba8ea17049b874574c55..37a0e47f17754894c3533dfc589607e011595723 100644 --- a/src/assets/i18n/participant/de.json +++ b/src/assets/i18n/participant/de.json @@ -18,6 +18,7 @@ "enter-title": "Titel", "enter-comment": "Kommentar", "send": "Senden", + "abort": "Abbrechen", "error-comment": "Bitte geben Sie einen Kommentartext ein", "error-title": "Bitte geben Sie einen Titel ein", "error-both-fields": "Bitte füllen Sie alle Felder aus" @@ -43,4 +44,4 @@ "improvable": "Luft nach oben", "no-answers": "Keine Antworten" } -} \ No newline at end of file +} diff --git a/src/assets/i18n/participant/en.json b/src/assets/i18n/participant/en.json index 7afd3e44034a3907c971ad70476b5b309e0fda15..9fb7c9f2b49c1c8071968c5276664187a3afa8fb 100644 --- a/src/assets/i18n/participant/en.json +++ b/src/assets/i18n/participant/en.json @@ -18,6 +18,7 @@ "enter-title": "Title", "enter-comment": "Comment", "send": "Send", + "abort": "Cancel", "error-title": "Please enter a title", "error-comment": "Please enter a comment-text", "error-both-fields": "Please fill in all fields"