diff --git a/src/app/components/creator/_dialogs/room-edit/room-edit.component.html b/src/app/components/creator/_dialogs/room-edit/room-edit.component.html index e0fc698113c12ce6e128023f7478b54006a07bab..6654079e0cfcfec2bdd0558806cef1dca4dd6573 100644 --- a/src/app/components/creator/_dialogs/room-edit/room-edit.component.html +++ b/src/app/components/creator/_dialogs/room-edit/room-edit.component.html @@ -19,7 +19,7 @@ <div fxLayout="row"> <mat-label>Threshold for visible comments:</mat-label> <span class="fill-remaining-space"></span> - <mat-label>{{editRoom.commentThreshold | number}}</mat-label> + <mat-label>{{commentThreshold | number}}</mat-label> </div> <mat-slider id="commentSlider" min="-50" max="50" step="1" value="0" color="accent" [(ngModel)]="editRoom.commentThreshold" (input)="onSliderChange($event)"></mat-slider> diff --git a/src/app/components/creator/_dialogs/room-edit/room-edit.component.ts b/src/app/components/creator/_dialogs/room-edit/room-edit.component.ts index f99b317cfa958400499b4c93bf9ec7efb57463ff..2e57892c63a6c4b500aaede5307aaf89ea38c859 100644 --- a/src/app/components/creator/_dialogs/room-edit/room-edit.component.ts +++ b/src/app/components/creator/_dialogs/room-edit/room-edit.component.ts @@ -2,6 +2,7 @@ import { Component, Inject, OnInit } from '@angular/core'; import { Room } from '../../../../models/room'; import { RoomCreateComponent } from '../../../shared/_dialogs/room-create/room-create.component'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; +import { TSMap } from 'typescript-map'; @Component({ selector: 'app-room-edit', @@ -10,6 +11,7 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; }) export class RoomEditComponent implements OnInit { editRoom: Room; + commentThreshold: number; constructor(public dialogRef: MatDialogRef<RoomCreateComponent>, @Inject(MAT_DIALOG_DATA) public data: any) { @@ -20,10 +22,21 @@ export class RoomEditComponent implements OnInit { } ngOnInit() { - + // ToDo: implement a more robust way + // ToDo: have a default comment threshold defined in config files + if (this.editRoom.extensions != null) { + const commentExtension = this.editRoom.extensions.get('comments'); + if ((commentExtension != null) && commentExtension.get('threshold') != null) { + this.commentThreshold = commentExtension.get('threshold'); + } else { + this.commentThreshold = -10; + } + } else { + this.commentThreshold = -10; + } } onSliderChange(event: any) { - this.editRoom.commentThreshold = event.value; + this.commentThreshold = event.value; } } diff --git a/src/app/components/creator/room-creator-page/room-creator-page.component.ts b/src/app/components/creator/room-creator-page/room-creator-page.component.ts index 895ec931fa5cffbe6f68e7dc3f0ff1f319ef6768..a0c050507a8341b06b83bfe741852b7ab27d0ad8 100644 --- a/src/app/components/creator/room-creator-page/room-creator-page.component.ts +++ b/src/app/components/creator/room-creator-page/room-creator-page.component.ts @@ -10,6 +10,7 @@ import { RoomDeleteComponent } from '../_dialogs/room-delete/room-delete.compone import { RoomEditComponent } from '../_dialogs/room-edit/room-edit.component'; import { TranslateService } from '@ngx-translate/core'; import { LanguageService } from '../../../services/util/language.service'; +import { TSMap } from 'typescript-map'; @Component({ selector: 'app-room-creator-page', @@ -20,6 +21,8 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni room: Room; updRoom: Room; themeClass = localStorage.getItem('classNameOfTheme'); + commentThreshold: number; + updCommentThreshold: number; constructor(protected roomService: RoomService, protected notification: NotificationService, @@ -45,14 +48,19 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni updateRoom(): void { if ((this.updRoom.name === this.room.name) && (this.updRoom.description === this.room.description) && - (this.updRoom.commentThreshold === this.room.commentThreshold) + (this.commentThreshold === this.updCommentThreshold) ) { this.notification.show('There were no changes'); return; } else { this.room.name = this.updRoom.name; this.room.description = this.updRoom.description; - this.room.commentThreshold = this.updRoom.commentThreshold; + if (this.room.extensions === null) { + this.room.extensions = new TSMap(); + } + const commentExtension: TSMap<string, any> = new TSMap(); + commentExtension.set('threshold', this.updCommentThreshold); + this.room.extensions.set('comments', commentExtension); this.roomService.updateRoom(this.room) .subscribe(() => { this.notification.show('Changes are made'); @@ -84,15 +92,12 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni } showEditDialog(): void { - this.updRoom = new Room(); - this.updRoom.name = this.room.name; - this.updRoom.shortId = this.room.shortId; - this.updRoom.description = this.room.description; - this.updRoom.commentThreshold = this.room.commentThreshold; + this.updRoom = this.room; const dialogRef = this.dialog.open(RoomEditComponent, { width: '400px' }); dialogRef.componentInstance.editRoom = this.updRoom; + dialogRef.componentInstance.commentThreshold = this.updCommentThreshold; dialogRef.afterClosed() .subscribe(result => { if (result === 'abort') { diff --git a/src/app/components/shared/_dialogs/room-create/room-create.component.ts b/src/app/components/shared/_dialogs/room-create/room-create.component.ts index d0ad04a1217ccc042871df3b721decb2fc0b1be2..2c277d0322ef804df42ce82c38109ea7a190fe6e 100644 --- a/src/app/components/shared/_dialogs/room-create/room-create.component.ts +++ b/src/app/components/shared/_dialogs/room-create/room-create.component.ts @@ -6,6 +6,7 @@ import { NotificationService } from '../../../../services/util/notification.serv import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; import { ContentService } from '../../../../services/http/content.service'; import { TranslateService } from '@ngx-translate/core'; +import { TSMap } from 'typescript-map'; @Component({ selector: 'app-room-create', @@ -46,12 +47,14 @@ export class RoomCreateComponent implements OnInit { this.emptyInputs = true; return; } - this.roomService.addRoom({ - name: longRoomName, - abbreviation: '00000000', - description: description, - commentThreshold: commentThreshold - } as Room).subscribe(room => { + const newRoom = new Room(); + newRoom.name = longRoomName; + newRoom.abbreviation = '00000000'; + newRoom.description = description; + const commentExtension: TSMap<string, any> = new TSMap(); + commentExtension.set('commentThreshold', commentThreshold); + newRoom.extensions.set('comments', commentExtension); + this.roomService.addRoom(newRoom).subscribe(room => { this.room = room; let msg1: string; let msg2: string; 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 fc55fb67a60bef5f5bc818391e0aa04501465b4b..46965aa3bf34f0212cb888b24357e07955e21a97 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -73,10 +73,18 @@ export class CommentListComponent implements OnInit { } getCommentsCreator(): Comment[] { + // ToDo: get a default comment threshold from config settings file + let commentThreshold = -10; + if ( + (this.room.extensions.get('comments') != null) && + (this.room.extensions.get('comments').get('commentThreshold')) + ) { + commentThreshold = this.room.extensions.get('comments').get('commentThreshold'); + } if (this.hideCommentsList) { - return this.filteredComments.filter( x => x.score >= this.room.commentThreshold ); + return this.filteredComments.filter( x => x.score >= commentThreshold ); } else { - return this.comments.filter( x => x.score >= this.room.commentThreshold ); + return this.comments.filter( x => x.score >= commentThreshold ); } } diff --git a/src/app/models/room.ts b/src/app/models/room.ts index a635783346841f5693383424b6f01a0c288eb7a3..1ce435e6e64017bea7e59d6953d8ac4728fb4cbb 100644 --- a/src/app/models/room.ts +++ b/src/app/models/room.ts @@ -1,13 +1,36 @@ import { ContentGroup } from './content-group'; +import { TSMap } from 'typescript-map'; export class Room { id: string; revision: string; + ownerId: string; shortId: string; abbreviation: string; name: string; description: string; closed: boolean; - commentThreshold: number; contentGroups: ContentGroup[]; + extensions: TSMap<string, TSMap<string, any>>; + + constructor( + ownerId: string = '', + shortId: string = '', + abbreviation: string = '', + name: string = '', + description: string = '', + closed: boolean = false, + contentGroups: ContentGroup[] = [], + extensions: TSMap<string, TSMap<string, any>> = new TSMap() + ) { + this.id = '', + this.ownerId = ownerId; + this.shortId = shortId; + this.abbreviation = abbreviation; + this.name = name, + this.description = description; + this.closed = closed; + this.contentGroups = contentGroups; + this.extensions = extensions; + } } diff --git a/src/app/services/http/room.service.ts b/src/app/services/http/room.service.ts index b1e9903cd9b920fd8e5b658835190e7935d2b30f..544f7848da4cfb43c1f1358912a50daf0be82c5b 100644 --- a/src/app/services/http/room.service.ts +++ b/src/app/services/http/room.service.ts @@ -48,12 +48,11 @@ export class RoomService extends BaseHttpService { } addRoom(room: Room): Observable<Room> { + delete room.id; + delete room.revision; 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, - commentThreshold: room.commentThreshold - }, httpOptions); + room.ownerId = this.authService.getUser().id; + return this.http.post<Room>(connectionUrl, room, httpOptions); } getRoom(id: string): Observable<Room> {