From 61bbc7277501692d1520a421dff5af5d38ba6cf4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 31 Jan 2018 10:41:44 +0100 Subject: [PATCH] Fix human dates in result lists --- client/src/app/shared/index.ts | 1 - client/src/app/shared/misc/utils.ts | 14 +++++++++++++- .../src/app/shared/rest/rest-extractor.service.ts | 14 +++++--------- client/src/app/shared/utils.ts | 8 -------- .../app/shared/video-abuse/video-abuse.service.ts | 11 +---------- .../video-blacklist/video-blacklist.service.ts | 8 -------- 6 files changed, 19 insertions(+), 37 deletions(-) delete mode 100644 client/src/app/shared/utils.ts diff --git a/client/src/app/shared/index.ts b/client/src/app/shared/index.ts index 413dda16a..136730c91 100644 --- a/client/src/app/shared/index.ts +++ b/client/src/app/shared/index.ts @@ -5,4 +5,3 @@ export * from './users' export * from './video-abuse' export * from './video-blacklist' export * from './shared.module' -export * from './utils' diff --git a/client/src/app/shared/misc/utils.ts b/client/src/app/shared/misc/utils.ts index 23b46812b..0e6e6b366 100644 --- a/client/src/app/shared/misc/utils.ts +++ b/client/src/app/shared/misc/utils.ts @@ -1,5 +1,6 @@ // Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript +import { DatePipe } from '@angular/common' import { environment } from '../../../environments/environment' import { AuthService } from '../../core/auth' @@ -49,9 +50,20 @@ function getAbsoluteAPIUrl () { return absoluteAPIUrl } +const datePipe = new DatePipe('en') +function dateToHuman (date: string) { + return datePipe.transform(date, 'medium') +} + +function isInMobileView () { + return window.innerWidth < 600 +} + export { viewportHeight, getParameterByName, populateAsyncUserVideoChannels, - getAbsoluteAPIUrl + getAbsoluteAPIUrl, + dateToHuman, + isInMobileView } diff --git a/client/src/app/shared/rest/rest-extractor.service.ts b/client/src/app/shared/rest/rest-extractor.service.ts index 1b475da89..ad08a32f8 100644 --- a/client/src/app/shared/rest/rest-extractor.service.ts +++ b/client/src/app/shared/rest/rest-extractor.service.ts @@ -1,8 +1,7 @@ +import { HttpErrorResponse } from '@angular/common/http' import { Injectable } from '@angular/core' +import { dateToHuman } from '@app/shared/misc/utils' import { Observable } from 'rxjs/Observable' -import { HttpErrorResponse } from '@angular/common/http' - -import { Utils } from '../utils' import { ResultList } from '../../../../../shared' @Injectable() @@ -16,7 +15,7 @@ export class RestExtractor { const data: T[] = result.data const newData: T[] = [] - data.forEach(d => newData.push(fun.call(this, d, additionalArgs))) + data.forEach(d => newData.push(fun.apply(this, [ d ].concat(additionalArgs)))) return { total: result.total, @@ -29,12 +28,9 @@ export class RestExtractor { } convertDateToHuman (target: object, fieldsToConvert: string[]) { - const source = {} - fieldsToConvert.forEach(field => { - source[field] = Utils.dateToHuman(target[field]) - }) + fieldsToConvert.forEach(field => target[field] = dateToHuman(target[field])) - return Object.assign(target, source) + return target } handleError (err: HttpErrorResponse) { diff --git a/client/src/app/shared/utils.ts b/client/src/app/shared/utils.ts deleted file mode 100644 index 7c8ae2e3e..000000000 --- a/client/src/app/shared/utils.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { DatePipe } from '@angular/common' - -export class Utils { - - static dateToHuman (date: Date) { - return new DatePipe('en').transform(date, 'medium') - } -} diff --git a/client/src/app/shared/video-abuse/video-abuse.service.ts b/client/src/app/shared/video-abuse/video-abuse.service.ts index 96a1f1fd2..ae00c4c45 100644 --- a/client/src/app/shared/video-abuse/video-abuse.service.ts +++ b/client/src/app/shared/video-abuse/video-abuse.service.ts @@ -5,9 +5,8 @@ import 'rxjs/add/operator/catch' import 'rxjs/add/operator/map' import { Observable } from 'rxjs/Observable' import { ResultList, VideoAbuse } from '../../../../../shared' -import { RestExtractor, RestPagination, RestService } from '../rest' -import { Utils } from '../utils' import { environment } from '../../../environments/environment' +import { RestExtractor, RestPagination, RestService } from '../rest' @Injectable() export class VideoAbuseService { @@ -27,7 +26,6 @@ export class VideoAbuseService { return this.authHttp.get>(url, { params }) .map(res => this.restExtractor.convertResultListDateToHuman(res)) - .map(res => this.restExtractor.applyToResultListData(res, this.formatVideoAbuse.bind(this))) .catch(res => this.restExtractor.handleError(res)) } @@ -41,11 +39,4 @@ export class VideoAbuseService { .map(this.restExtractor.extractDataBool) .catch(res => this.restExtractor.handleError(res)) } - - private formatVideoAbuse (videoAbuse: VideoAbuse) { - return Object.assign(videoAbuse, { - createdAt: Utils.dateToHuman(videoAbuse.createdAt) - }) - } - } diff --git a/client/src/app/shared/video-blacklist/video-blacklist.service.ts b/client/src/app/shared/video-blacklist/video-blacklist.service.ts index 1231690aa..14c8b5dc0 100644 --- a/client/src/app/shared/video-blacklist/video-blacklist.service.ts +++ b/client/src/app/shared/video-blacklist/video-blacklist.service.ts @@ -7,7 +7,6 @@ import { Observable } from 'rxjs/Observable' import { BlacklistedVideo, ResultList } from '../../../../../shared' import { environment } from '../../../environments/environment' import { RestExtractor, RestPagination, RestService } from '../rest' -import { Utils } from '../utils' @Injectable() export class VideoBlacklistService { @@ -25,7 +24,6 @@ export class VideoBlacklistService { return this.authHttp.get>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params }) .map(res => this.restExtractor.convertResultListDateToHuman(res)) - .map(res => this.restExtractor.applyToResultListData(res, this.formatBlacklistedVideo.bind(this))) .catch(res => this.restExtractor.handleError(res)) } @@ -40,10 +38,4 @@ export class VideoBlacklistService { .map(this.restExtractor.extractDataBool) .catch(res => this.restExtractor.handleError(res)) } - - private formatBlacklistedVideo (blacklistedVideo: BlacklistedVideo) { - return Object.assign(blacklistedVideo, { - createdAt: Utils.dateToHuman(blacklistedVideo.createdAt) - }) - } } -- 2.25.1