Skip to content
Snippets Groups Projects
Commit bb631648 authored by Lukas Mauß's avatar Lukas Mauß
Browse files

Add new time period filter 'from now'

Users are now able to filter the comments from now. If an user has selected this option all comments disappear and only comments created from now will be displayed.
If the user selects another time period or the 'from now' option again, the period will reset so that the comments will disappear again.
parent cfc34601
No related merge requests found
...@@ -57,6 +57,7 @@ export class ModeratorCommentListComponent implements OnInit { ...@@ -57,6 +57,7 @@ export class ModeratorCommentListComponent implements OnInit {
searchPlaceholder = ''; searchPlaceholder = '';
periodsList = Object.values(Period); periodsList = Object.values(Period);
period: Period = Period.TWOWEEKS; period: Period = Period.TWOWEEKS;
fromNow: number;
constructor( constructor(
private commentService: CommentService, private commentService: CommentService,
...@@ -290,14 +291,21 @@ export class ModeratorCommentListComponent implements OnInit { ...@@ -290,14 +291,21 @@ export class ModeratorCommentListComponent implements OnInit {
} }
this.router.navigate([`/${role}/room/${this.room.shortId}/comments`]); this.router.navigate([`/${role}/room/${this.room.shortId}/comments`]);
} }
setTimePeriod(period?: Period) {
setTimePeriod(period: Period) { if (period) {
this.period = period; this.period = period;
this.fromNow = null;
}
const currentTime = new Date(); const currentTime = new Date();
const hourInSeconds = 3600000; const hourInSeconds = 3600000;
let periodInSeconds; let periodInSeconds;
if (period !== Period.ALL) { if (this.period !== Period.ALL) {
switch (period) { switch (this.period) {
case Period.FROMNOW:
if (!this.fromNow) {
this.fromNow = new Date().getTime();
}
break;
case Period.ONEHOUR: case Period.ONEHOUR:
periodInSeconds = hourInSeconds; periodInSeconds = hourInSeconds;
break; break;
...@@ -309,9 +317,14 @@ export class ModeratorCommentListComponent implements OnInit { ...@@ -309,9 +317,14 @@ export class ModeratorCommentListComponent implements OnInit {
break; break;
case Period.ONEWEEK: case Period.ONEWEEK:
periodInSeconds = hourInSeconds * 168; periodInSeconds = hourInSeconds * 168;
break;
case Period.TWOWEEKS:
periodInSeconds = hourInSeconds * 336;
break;
} }
this.commentsFilteredByTime = this.comments this.commentsFilteredByTime = this.comments
.filter(c => new Date(c.timestamp).getTime() >= (currentTime.getTime() - periodInSeconds)); .filter(c => new Date(c.timestamp).getTime() >=
(this.period === Period.FROMNOW ? this.fromNow : (currentTime.getTime() - periodInSeconds)));
} else { } else {
this.commentsFilteredByTime = this.comments; this.commentsFilteredByTime = this.comments;
} }
......
...@@ -25,6 +25,7 @@ import { Title } from '@angular/platform-browser'; ...@@ -25,6 +25,7 @@ import { Title } from '@angular/platform-browser';
import { TitleService } from '../../../services/util/title.service'; import { TitleService } from '../../../services/util/title.service';
export enum Period { export enum Period {
FROMNOW = 'from-now',
ONEHOUR = 'time-1h', ONEHOUR = 'time-1h',
THREEHOURS = 'time-3h', THREEHOURS = 'time-3h',
ONEDAY = 'time-1d', ONEDAY = 'time-1d',
...@@ -84,6 +85,7 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -84,6 +85,7 @@ export class CommentListComponent implements OnInit, OnDestroy {
commentStream: Subscription; commentStream: Subscription;
periodsList = Object.values(Period); periodsList = Object.values(Period);
period: Period = Period.TWOWEEKS; period: Period = Period.TWOWEEKS;
fromNow: number;
constructor( constructor(
private commentService: CommentService, private commentService: CommentService,
...@@ -208,7 +210,7 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -208,7 +210,7 @@ export class CommentListComponent implements OnInit, OnDestroy {
this.setComments(this.comments.filter(x => x.score >= commentThreshold)); this.setComments(this.comments.filter(x => x.score >= commentThreshold));
} }
} }
this.setTimePeriod(this.period); this.setTimePeriod();
} }
getVote(comment: Comment): Vote { getVote(comment: Comment): Vote {
...@@ -271,7 +273,7 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -271,7 +273,7 @@ export class CommentListComponent implements OnInit, OnDestroy {
this.comments = this.comments.filter(function (el) { this.comments = this.comments.filter(function (el) {
return el.id !== payload.id; return el.id !== payload.id;
}); });
this.setTimePeriod(this.period); this.setTimePeriod();
} }
break; break;
case this.tag: case this.tag:
...@@ -301,7 +303,7 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -301,7 +303,7 @@ export class CommentListComponent implements OnInit, OnDestroy {
} }
break; break;
} }
this.setTimePeriod(this.period); this.setTimePeriod();
if (this.hideCommentsList) { if (this.hideCommentsList) {
this.searchComments(); this.searchComments();
} }
...@@ -478,13 +480,21 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -478,13 +480,21 @@ export class CommentListComponent implements OnInit, OnDestroy {
}, 450); }, 450);
} }
setTimePeriod(period: Period) { public setTimePeriod(period?: Period) {
this.period = period; if (period) {
this.period = period;
this.fromNow = null;
}
const currentTime = new Date(); const currentTime = new Date();
const hourInSeconds = 3600000; const hourInSeconds = 3600000;
let periodInSeconds; let periodInSeconds;
if (period !== Period.ALL) { if (this.period !== Period.ALL) {
switch (period) { switch (this.period) {
case Period.FROMNOW:
if (!this.fromNow) {
this.fromNow = new Date().getTime();
}
break;
case Period.ONEHOUR: case Period.ONEHOUR:
periodInSeconds = hourInSeconds; periodInSeconds = hourInSeconds;
break; break;
...@@ -502,7 +512,8 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -502,7 +512,8 @@ export class CommentListComponent implements OnInit, OnDestroy {
break; break;
} }
this.commentsFilteredByTime = this.comments this.commentsFilteredByTime = this.comments
.filter(c => new Date(c.timestamp).getTime() >= (currentTime.getTime() - periodInSeconds)); .filter(c => new Date(c.timestamp).getTime() >=
(this.period === Period.FROMNOW ? this.fromNow : (currentTime.getTime() - periodInSeconds)));
} else { } else {
this.commentsFilteredByTime = this.comments; this.commentsFilteredByTime = this.comments;
} }
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
"switch-to-comment-list": "Zur öffentlichen Fragenliste", "switch-to-comment-list": "Zur öffentlichen Fragenliste",
"switch-to-moderation-list": "Zum Index", "switch-to-moderation-list": "Zum Index",
"select-time": "Zeitraum auswählen", "select-time": "Zeitraum auswählen",
"select-from-now": "Ab jetzt",
"select-time-1h": "Letzte Stunde", "select-time-1h": "Letzte Stunde",
"select-time-3h": "Letzte 2 Stunden", "select-time-3h": "Letzte 2 Stunden",
"select-time-1d": "Letzte 24 Stunden", "select-time-1d": "Letzte 24 Stunden",
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
"switch-to-comment-list": "Switch to public question board", "switch-to-comment-list": "Switch to public question board",
"switch-to-moderation-list": "Switch to index", "switch-to-moderation-list": "Switch to index",
"select-time": "Select time period", "select-time": "Select time period",
"select-from-now": "From now",
"select-time-1h": "Last hour", "select-time-1h": "Last hour",
"select-time-3h": "Last 2 hours", "select-time-3h": "Last 2 hours",
"select-time-1d": "Last 24 hours", "select-time-1d": "Last 24 hours",
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
"wrong": "Verneint", "wrong": "Verneint",
"really-delete": "Willst du die Frage wirklich löschen?", "really-delete": "Willst du die Frage wirklich löschen?",
"select-time": "Zeitraum auswählen", "select-time": "Zeitraum auswählen",
"select-from-now": "Ab jetzt",
"select-time-1h": "Letzte Stunde", "select-time-1h": "Letzte Stunde",
"select-time-3h": "Letzte 2 Stunden", "select-time-3h": "Letzte 2 Stunden",
"select-time-1d": "Letzte 24 Stunden", "select-time-1d": "Letzte 24 Stunden",
......
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
"wrong": "Marked as wrong", "wrong": "Marked as wrong",
"really-delete": "Do you really want to delete this question?", "really-delete": "Do you really want to delete this question?",
"select-time": "Select time period", "select-time": "Select time period",
"select-from-now": "From now",
"select-time-1h": "Last hour", "select-time-1h": "Last hour",
"select-time-3h": "Last 2 hours", "select-time-3h": "Last 2 hours",
"select-time-1d": "Last 24 hours", "select-time-1d": "Last 24 hours",
......
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