Fix human dates in result lists

pull/277/head
Chocobozzz 2018-01-31 10:41:44 +01:00
parent 915c5bbe53
commit 61bbc72775
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
6 changed files with 20 additions and 38 deletions

View File

@ -5,4 +5,3 @@ export * from './users'
export * from './video-abuse'
export * from './video-blacklist'
export * from './shared.module'
export * from './utils'

View File

@ -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
}

View File

@ -1,8 +1,7 @@
import { Injectable } from '@angular/core'
import { Observable } from 'rxjs/Observable'
import { HttpErrorResponse } from '@angular/common/http'
import { Utils } from '../utils'
import { Injectable } from '@angular/core'
import { dateToHuman } from '@app/shared/misc/utils'
import { Observable } from 'rxjs/Observable'
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) {

View File

@ -1,8 +0,0 @@
import { DatePipe } from '@angular/common'
export class Utils {
static dateToHuman (date: Date) {
return new DatePipe('en').transform(date, 'medium')
}
}

View File

@ -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<ResultList<VideoAbuse>>(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)
})
}
}

View File

@ -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<ResultList<BlacklistedVideo>>(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)
})
}
}