Skip to content
Snippets Groups Projects
Commit e52b9ba3 authored by Klaus-Dieter Quibeldey-Cirkel's avatar Klaus-Dieter Quibeldey-Cirkel
Browse files

Merge branch...

Merge branch '310-give-each-new-question-poser-a-consecutive-number-combined-with-an-icon-label-and-filter-questions-by-clicking-on-the-label' into 'master'

Give comment creators a 'userNumber', added as new filter

Closes #310

See merge request arsnova/frag.jetzt!280
parents 9ad00485 e72ca2ad
No related merge requests found
...@@ -149,7 +149,8 @@ ...@@ -149,7 +149,8 @@
<div *ngIf="!isLoading"> <div *ngIf="!isLoading">
<app-comment *ngFor="let current of hideCommentsList ? filteredComments : comments" [comment]="current" <app-comment *ngFor="let current of hideCommentsList ? filteredComments : comments" [comment]="current"
[parseVote]="getVote(current)" [userRole]="userRole" [moderator]="false" (clickedOnTag)="clickedOnTag($event)"> [parseVote]="getVote(current)" [userRole]="userRole" [moderator]="false"
(clickedOnTag)="clickedOnTag($event)" (clickedUserNumber)="clickedUserNumber($event)">
</app-comment> </app-comment>
</div> </div>
<!-- No Questions Present --> <!-- No Questions Present -->
......
...@@ -50,6 +50,7 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -50,6 +50,7 @@ export class CommentListComponent implements OnInit, OnDestroy {
wrong = 'wrong'; wrong = 'wrong';
ack = 'ack'; ack = 'ack';
tag = 'tag'; tag = 'tag';
userNumber = 'userNumber';
answer = 'answer'; answer = 'answer';
owner = 'owner'; owner = 'owner';
currentFilter = ''; currentFilter = '';
...@@ -195,6 +196,8 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -195,6 +196,8 @@ export class CommentListComponent implements OnInit, OnDestroy {
c.id = payload.id; c.id = payload.id;
c.timestamp = payload.timestamp; c.timestamp = payload.timestamp;
c.tag = payload.tag; c.tag = payload.tag;
c.creatorId = payload.creatorId;
c.userNumber = this.commentService.hashCode(c.creatorId);
this.announceNewComment(c.body); this.announceNewComment(c.body);
...@@ -307,7 +310,7 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -307,7 +310,7 @@ export class CommentListComponent implements OnInit, OnDestroy {
this.notificationService.show(message); this.notificationService.show(message);
} }
filterComments(type: string, tag?: string): void { filterComments(type: string, compare?: any): void {
this.currentFilter = type; this.currentFilter = type;
if (type === '') { if (type === '') {
this.filteredComments = this.comments; this.filteredComments = this.comments;
...@@ -328,7 +331,9 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -328,7 +331,9 @@ export class CommentListComponent implements OnInit, OnDestroy {
case this.unread: case this.unread:
return !c.read; return !c.read;
case this.tag: case this.tag:
return c.tag === tag; return c.tag === compare;
case this.userNumber:
return c.userNumber === compare;
case this.answer: case this.answer:
return c.answer; return c.answer;
case this.owner: case this.owner:
...@@ -365,6 +370,10 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -365,6 +370,10 @@ export class CommentListComponent implements OnInit, OnDestroy {
this.filterComments(this.tag, tag); this.filterComments(this.tag, tag);
} }
clickedUserNumber(usrNumber: number): void {
this.filterComments(this.userNumber, usrNumber);
}
pauseCommentStream() { pauseCommentStream() {
this.freeze = true; this.freeze = true;
this.commentStream.unsubscribe(); this.commentStream.unsubscribe();
......
...@@ -93,15 +93,21 @@ ...@@ -93,15 +93,21 @@
<div *ngIf="!isStudent" fxLayout="column" fxLayoutAlign="center"> <div *ngIf="!isStudent" fxLayout="column" fxLayoutAlign="center">
<span class="scoreCreator">{{comment.score}}</span> <span class="scoreCreator">{{comment.score}}</span>
</div> </div>
</div> </div>
<div (click)="this.clickedOnTag.emit(comment.tag)" *ngIf="comment.tag && comment.tag !== ''" class="comment-tags"> <div fxLayout="row" fxLayoutAlign="start center">
<span class="comment-tag-icon"> <div fxLayoutAlign="center center" (click)="this.clickedOnTag.emit(comment.tag)"
*ngIf="comment.tag && comment.tag !== ''" class="comment-tags">
<mat-icon svgIcon="comment_tag"></mat-icon> <mat-icon svgIcon="comment_tag"></mat-icon>
</span> <span>
<span class="comment-tag"> {{comment.tag}}
{{comment.tag}} </span>
</span> </div>
<div class="user-number" fxLayoutAlign="center center" (click)="this.clickedUserNumber.emit(comment.userNumber)">
<mat-icon class="user-icon">person</mat-icon>
<strong>
{{comment.userNumber}}
</strong>
</div>
</div> </div>
</div> </div>
</mat-card> </mat-card>
......
...@@ -112,14 +112,19 @@ user.role ...@@ -112,14 +112,19 @@ user.role
} }
.comment-tags { .comment-tags {
width: 140px;
margin-top: 1rem;
cursor: pointer; cursor: pointer;
color: var(--primary); color: var(--primary);
margin-right: 10px;
} }
.comment-tag { .user-number {
vertical-align: 5px; cursor: pointer;
color: var(--on-surface);
}
.user-icon {
margin-right: 5px;
} }
.voteUp { .voteUp {
......
...@@ -34,8 +34,8 @@ export class CommentComponent implements OnInit { ...@@ -34,8 +34,8 @@ export class CommentComponent implements OnInit {
@Input() comment: Comment; @Input() comment: Comment;
@Input() moderator: boolean; @Input() moderator: boolean;
@Input() userRole: UserRole; @Input() userRole: UserRole;
@Output() @Output() clickedOnTag = new EventEmitter<string>();
clickedOnTag = new EventEmitter<string>(); @Output() clickedUserNumber = new EventEmitter<number>();
isStudent = false; isStudent = false;
isCreator = false; isCreator = false;
isModerator = false; isModerator = false;
......
...@@ -16,6 +16,7 @@ export class Comment { ...@@ -16,6 +16,7 @@ export class Comment {
ack: boolean; ack: boolean;
tag: string; tag: string;
answer: string; answer: string;
userNumber: number;
constructor(roomId: string = '', constructor(roomId: string = '',
creatorId: string = '', creatorId: string = '',
...@@ -29,7 +30,8 @@ export class Comment { ...@@ -29,7 +30,8 @@ export class Comment {
highlighted: boolean = false, highlighted: boolean = false,
ack: boolean = true, ack: boolean = true,
tag: string = '', tag: string = '',
answer: string = '') { answer: string = '',
userNumber: number = 0) {
this.id = ''; this.id = '';
this.roomId = roomId; this.roomId = roomId;
this.creatorId = creatorId; this.creatorId = creatorId;
...@@ -45,5 +47,6 @@ export class Comment { ...@@ -45,5 +47,6 @@ export class Comment {
this.ack = ack; this.ack = ack;
this.tag = tag; this.tag = tag;
this.answer = answer; this.answer = answer;
this.userNumber = userNumber;
} }
} }
...@@ -3,8 +3,8 @@ import { environment } from './../environments/environment'; ...@@ -3,8 +3,8 @@ import { environment } from './../environments/environment';
export const ARSRxStompConfig: RxStompConfig = { export const ARSRxStompConfig: RxStompConfig = {
// Which server? // Which server?
brokerURL: (window.location.protocol === 'http:' ) ? brokerURL: ((window.location.protocol === 'http:') ? 'ws' : 'wss')
`ws://${window.location.hostname}:/api/ws/websocket` : `wss://${window.location.hostname}/api/ws/websocket`, + `://${window.location.host}/api/ws/websocket`,
connectHeaders: { connectHeaders: {
login: 'guest', login: 'guest',
......
...@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; ...@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { Comment } from '../../models/comment'; import { Comment } from '../../models/comment';
import { catchError, tap } from 'rxjs/operators'; import { catchError, tap, map } from 'rxjs/operators';
import { BaseHttpService } from './base-http.service'; import { BaseHttpService } from './base-http.service';
const httpOptions = { const httpOptions = {
...@@ -25,6 +25,7 @@ export class CommentService extends BaseHttpService { ...@@ -25,6 +25,7 @@ export class CommentService extends BaseHttpService {
getComment(commentId: string): Observable<Comment> { getComment(commentId: string): Observable<Comment> {
const connectionUrl = `${this.apiUrl.base}${this.apiUrl.comment}/${commentId}`; const connectionUrl = `${this.apiUrl.base}${this.apiUrl.comment}/${commentId}`;
return this.http.get<Comment>(connectionUrl, httpOptions).pipe( return this.http.get<Comment>(connectionUrl, httpOptions).pipe(
map(comment => this.parseUserNumber(comment)),
tap(_ => ''), tap(_ => ''),
catchError(this.handleError<Comment>('getComment')) catchError(this.handleError<Comment>('getComment'))
); );
...@@ -33,7 +34,8 @@ export class CommentService extends BaseHttpService { ...@@ -33,7 +34,8 @@ export class CommentService extends BaseHttpService {
addComment(comment: Comment): Observable<Comment> { addComment(comment: Comment): Observable<Comment> {
const connectionUrl = this.apiUrl.base + this.apiUrl.comment + '/'; const connectionUrl = this.apiUrl.base + this.apiUrl.comment + '/';
return this.http.post<Comment>(connectionUrl, return this.http.post<Comment>(connectionUrl,
{ roomId: comment.roomId, body: comment.body, {
roomId: comment.roomId, body: comment.body,
read: comment.read, creationTimestamp: comment.timestamp read: comment.read, creationTimestamp: comment.timestamp
}, httpOptions).pipe( }, httpOptions).pipe(
tap(_ => ''), tap(_ => ''),
...@@ -55,6 +57,9 @@ export class CommentService extends BaseHttpService { ...@@ -55,6 +57,9 @@ export class CommentService extends BaseHttpService {
properties: { roomId: roomId, ack: true }, properties: { roomId: roomId, ack: true },
externalFilters: {} externalFilters: {}
}, httpOptions).pipe( }, httpOptions).pipe(
map(commentList => {
return commentList.map(comment => this.parseUserNumber(comment));
}),
tap(_ => ''), tap(_ => ''),
catchError(this.handleError<Comment[]>('getComments', [])) catchError(this.handleError<Comment[]>('getComments', []))
); );
...@@ -66,6 +71,9 @@ export class CommentService extends BaseHttpService { ...@@ -66,6 +71,9 @@ export class CommentService extends BaseHttpService {
properties: { roomId: roomId, ack: false }, properties: { roomId: roomId, ack: false },
externalFilters: {} externalFilters: {}
}, httpOptions).pipe( }, httpOptions).pipe(
map(commentList => {
return commentList.map(comment => this.parseUserNumber(comment));
}),
tap(_ => ''), tap(_ => ''),
catchError(this.handleError<Comment[]>('getComments', [])) catchError(this.handleError<Comment[]>('getComments', []))
); );
...@@ -77,6 +85,9 @@ export class CommentService extends BaseHttpService { ...@@ -77,6 +85,9 @@ export class CommentService extends BaseHttpService {
properties: { roomId: roomId }, properties: { roomId: roomId },
externalFilters: {} externalFilters: {}
}, httpOptions).pipe( }, httpOptions).pipe(
map(commentList => {
return commentList.map(comment => this.parseUserNumber(comment));
}),
tap(_ => ''), tap(_ => ''),
catchError(this.handleError<Comment[]>('getComments', [])) catchError(this.handleError<Comment[]>('getComments', []))
); );
...@@ -108,4 +119,19 @@ export class CommentService extends BaseHttpService { ...@@ -108,4 +119,19 @@ export class CommentService extends BaseHttpService {
catchError(this.handleError<number>('countByRoomId', 0)) catchError(this.handleError<number>('countByRoomId', 0))
); );
} }
parseUserNumber(comment: Comment): Comment {
comment.userNumber = this.hashCode(comment.creatorId);
return comment;
}
hashCode(s) {
let hash;
for (let i = 0, h = 0; i < s.length; i++) {
hash = Math.abs(Math.imul(31, hash) + s.charCodeAt(i) | 0);
}
const userNumberString = String(hash);
hash = +userNumberString.substring(userNumberString.length - 4, userNumberString.length);
return hash;
}
} }
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
} }
], ],
"no-arg": true, "no-arg": true,
"no-bitwise": true, "no-bitwise": false,
"no-console": [ "no-console": [
true, true,
"debug", "debug",
......
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