...
 
Commits (8)
......@@ -135,7 +135,6 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni
return;
} else {
if (result instanceof CommentSettingsDialog) {
console.log(result);
this.updateCommentSettings(result);
this.saveChanges();
}
......
......@@ -181,7 +181,6 @@ export class ModeratorCommentListComponent implements OnInit {
this.comments = this.comments.concat(c);
break;
}
console.log(msg);
this.filterComments(this.currentFilter);
this.sortComments(this.currentSort);
this.searchComments();
......
......@@ -14,6 +14,7 @@ import { Room } from '../../../models/room';
import { RoomService } from '../../../services/http/room.service';
import { VoteService } from '../../../services/http/vote.service';
import { NotificationService } from '../../../services/util/notification.service';
import { DatabaseService } from '../../../services/util/database.service';
@Component({
selector: 'app-comment-list',
......@@ -57,7 +58,8 @@ export class CommentListComponent implements OnInit {
private wsCommentService: WsCommentServiceService,
protected roomService: RoomService,
protected voteService: VoteService,
private notificationService: NotificationService
private notificationService: NotificationService,
private databaseService: DatabaseService
) {
langService.langEmitter.subscribe(lang => translateService.use(lang));
}
......@@ -91,11 +93,8 @@ export class CommentListComponent implements OnInit {
});
}
this.currentSort = this.votedesc;
this.commentService.getAckComments(this.roomId)
.subscribe(comments => {
this.comments = comments;
this.getComments();
});
this.sync();
this.getComments();
this.translateService.get('comment-list.search').subscribe(msg => {
this.searchPlaceholder = msg;
});
......@@ -156,7 +155,7 @@ export class CommentListComponent implements OnInit {
c.body = payload.body;
c.id = payload.id;
c.timestamp = payload.timestamp;
this.comments = this.comments.concat(c);
this.addComment(c);
break;
case 'CommentPatched':
// ToDo: Use a map for comments w/ key = commentId
......@@ -166,22 +165,24 @@ export class CommentListComponent implements OnInit {
switch (key) {
case this.read:
this.comments[i].read = <boolean>value;
this.updateDatabase();
break;
case this.correct:
this.comments[i].correct = <boolean>value;
this.updateDatabase();
break;
case this.favorite:
this.comments[i].favorite = <boolean>value;
this.updateDatabase();
break;
case 'score':
this.comments[i].score = <number>value;
this.updateDatabase();
break;
case this.ack:
const isNowAck = <boolean>value;
if (!isNowAck) {
this.comments = this.comments.filter(function (el) {
return el.id !== payload.id;
});
this.deleteComment(payload.id);
}
}
}
......@@ -193,14 +194,14 @@ export class CommentListComponent implements OnInit {
for (let i = 0; i < this.comments.length; i++) {
if (payload.id === this.comments[i].id) {
this.comments[i].highlighted = <boolean>payload.lights;
this.updateDatabase();
}
}
break;
case 'CommentDeleted':
for (let i = 0; i < this.comments.length; i++) {
this.comments = this.comments.filter(function (el) {
return el.id !== payload.id;
});
this.deleteComment(payload.id);
this.updateComments();
}
break;
}
......@@ -225,6 +226,34 @@ export class CommentListComponent implements OnInit {
});
}
addComment(comment: Comment): void {
this.databaseService.comments.add(comment);
this.updateComments();
}
deleteComment(id: string) {
this.databaseService.comments.delete(id);
this.updateComments();
}
async updateComments() {
this.comments = await this.databaseService.comments.toArray();
}
async sync() {
this.commentService.getAckComments(this.roomId)
.subscribe(newComments => {
this.comments = newComments;
this.updateDatabase();
this.updateComments();
});
}
async updateDatabase() {
this.databaseService.comments.bulkPut(this.comments);
}
send(comment: Comment): void {
let message;
if (this.moderationEnabled) {
......
......@@ -46,7 +46,7 @@ export class AuthenticationService {
let role = UserRole.PARTICIPANT;
const roleAsNumber: string = cA.substring(0, 1);
const roomId: string = cA.substring(2);
if (roleAsNumber === '1') {
if (roleAsNumber === '3') {
role = UserRole.CREATOR;
} else if (roleAsNumber === '2') {
role = UserRole.EXECUTIVE_MODERATOR;
......
import { TestBed } from '@angular/core/testing';
import { DatabaseService } from './database.service';
describe('DatabaseService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: DatabaseService = TestBed.get(DatabaseService);
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import Dexie from 'dexie';
import { Comment } from '../../models/comment';
@Injectable({
providedIn: 'root'
})
export class DatabaseService extends Dexie {
comments: Dexie.Table<Comment, string>;
constructor() {
super('indexedDB');
this.version(1).stores({
comments: 'id, roomId, userId, revision, body, read, correct, favorite, timestamp, score' +
'createdFromLecturer, highlighted, ack'
});
}
}
......@@ -25,7 +25,6 @@ export class WsCommentServiceService {
}
toggleRead(comment: Comment): Comment {
console.log(comment);
comment.read = !comment.read;
const changes = new TSMap<string, any>();
changes.set('read', comment.read);
......