diff --git a/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts b/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts index 5b59abbd66917d4b8d2741c3b0ab9f4bb7d55fa2..1e38a67d87d1cfe1e6c944b5ee4634c436d760cd 100644 --- a/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts +++ b/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts @@ -57,6 +57,7 @@ export class ModeratorCommentListComponent implements OnInit { searchPlaceholder = ''; periodsList = Object.values(Period); period: Period = Period.TWOWEEKS; + fromNow: number; constructor( private commentService: CommentService, @@ -296,14 +297,21 @@ export class ModeratorCommentListComponent implements OnInit { } this.router.navigate([`/${role}/room/${this.room.shortId}/comments`]); } - - setTimePeriod(period: Period) { - this.period = period; + setTimePeriod(period?: Period) { + if (period) { + this.period = period; + this.fromNow = null; + } const currentTime = new Date(); const hourInSeconds = 3600000; let periodInSeconds; - if (period !== Period.ALL) { - switch (period) { + if (this.period !== Period.ALL) { + switch (this.period) { + case Period.FROMNOW: + if (!this.fromNow) { + this.fromNow = new Date().getTime(); + } + break; case Period.ONEHOUR: periodInSeconds = hourInSeconds; break; @@ -315,9 +323,14 @@ export class ModeratorCommentListComponent implements OnInit { break; case Period.ONEWEEK: periodInSeconds = hourInSeconds * 168; + break; + case Period.TWOWEEKS: + periodInSeconds = hourInSeconds * 336; + break; } 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 { this.commentsFilteredByTime = this.comments; } 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 986bba3ec84ef89c0c276f5ec316ce1aa8b39bd7..771890ee20911728992cb2422213d6da8e2d9108 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -25,6 +25,7 @@ import { Title } from '@angular/platform-browser'; import { TitleService } from '../../../services/util/title.service'; export enum Period { + FROMNOW = 'from-now', ONEHOUR = 'time-1h', THREEHOURS = 'time-3h', ONEDAY = 'time-1d', @@ -84,6 +85,7 @@ export class CommentListComponent implements OnInit, OnDestroy { commentStream: Subscription; periodsList = Object.values(Period); period: Period = Period.TWOWEEKS; + fromNow: number; constructor( private commentService: CommentService, @@ -214,7 +216,7 @@ export class CommentListComponent implements OnInit, OnDestroy { this.setComments(this.comments.filter(x => x.score >= commentThreshold)); } } - this.setTimePeriod(this.period); + this.setTimePeriod(); } getVote(comment: Comment): Vote { @@ -277,7 +279,7 @@ export class CommentListComponent implements OnInit, OnDestroy { this.comments = this.comments.filter(function (el) { return el.id !== payload.id; }); - this.setTimePeriod(this.period); + this.setTimePeriod(); } break; case this.tag: @@ -307,7 +309,7 @@ export class CommentListComponent implements OnInit, OnDestroy { } break; } - this.setTimePeriod(this.period); + this.setTimePeriod(); if (this.hideCommentsList) { this.searchComments(); } @@ -484,13 +486,21 @@ export class CommentListComponent implements OnInit, OnDestroy { }, 450); } - setTimePeriod(period: Period) { - this.period = period; + public setTimePeriod(period?: Period) { + if (period) { + this.period = period; + this.fromNow = null; + } const currentTime = new Date(); const hourInSeconds = 3600000; let periodInSeconds; - if (period !== Period.ALL) { - switch (period) { + if (this.period !== Period.ALL) { + switch (this.period) { + case Period.FROMNOW: + if (!this.fromNow) { + this.fromNow = new Date().getTime(); + } + break; case Period.ONEHOUR: periodInSeconds = hourInSeconds; break; @@ -508,7 +518,8 @@ export class CommentListComponent implements OnInit, OnDestroy { break; } 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 { this.commentsFilteredByTime = this.comments; } diff --git a/src/assets/i18n/creator/de.json b/src/assets/i18n/creator/de.json index 6c2c9a052f3579245665f1223c0ec5f3e8de4b26..c45c41a2c8700a69ead6bf26d82d84f96968a346 100644 --- a/src/assets/i18n/creator/de.json +++ b/src/assets/i18n/creator/de.json @@ -57,6 +57,7 @@ "switch-to-comment-list": "Zur öffentlichen Fragenliste", "switch-to-moderation-list": "Zum Index", "select-time": "Zeitraum auswählen", + "select-from-now": "Ab jetzt", "select-time-1h": "Letzte Stunde", "select-time-3h": "Letzte 2 Stunden", "select-time-1d": "Letzte 24 Stunden", diff --git a/src/assets/i18n/creator/en.json b/src/assets/i18n/creator/en.json index 5a70e57d84b12dbec78ce9ee12d56afb7416182b..2bfb74dfb8cc0978d2b5eb9c54bdb2621ec9b965 100644 --- a/src/assets/i18n/creator/en.json +++ b/src/assets/i18n/creator/en.json @@ -58,6 +58,7 @@ "switch-to-comment-list": "Switch to public question board", "switch-to-moderation-list": "Switch to index", "select-time": "Select time period", + "select-from-now": "From now", "select-time-1h": "Last hour", "select-time-3h": "Last 2 hours", "select-time-1d": "Last 24 hours", diff --git a/src/assets/i18n/participant/de.json b/src/assets/i18n/participant/de.json index 385e2bf47a38545c50b4aaf289b627adac1de288..fb11cc01e2530ea75312c4b0f8a185f6845f8afe 100644 --- a/src/assets/i18n/participant/de.json +++ b/src/assets/i18n/participant/de.json @@ -58,6 +58,7 @@ "wrong": "Verneint", "really-delete": "Willst du die Frage wirklich löschen?", "select-time": "Zeitraum auswählen", + "select-from-now": "Ab jetzt", "select-time-1h": "Letzte Stunde", "select-time-3h": "Letzte 2 Stunden", "select-time-1d": "Letzte 24 Stunden", diff --git a/src/assets/i18n/participant/en.json b/src/assets/i18n/participant/en.json index 0c55e64bb5a28bceb553f6f6c211c83d2279cb7a..fd28f9f8ec92ba2fb39a6842f0b3238dcae0d896 100644 --- a/src/assets/i18n/participant/en.json +++ b/src/assets/i18n/participant/en.json @@ -68,6 +68,7 @@ "wrong": "Marked as wrong", "really-delete": "Do you really want to delete this question?", "select-time": "Select time period", + "select-from-now": "From now", "select-time-1h": "Last hour", "select-time-3h": "Last 2 hours", "select-time-1d": "Last 24 hours",