Fix human dates in result lists
This commit is contained in:
parent
915c5bbe53
commit
61bbc72775
|
@ -5,4 +5,3 @@ export * from './users'
|
||||||
export * from './video-abuse'
|
export * from './video-abuse'
|
||||||
export * from './video-blacklist'
|
export * from './video-blacklist'
|
||||||
export * from './shared.module'
|
export * from './shared.module'
|
||||||
export * from './utils'
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
|
// 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 { environment } from '../../../environments/environment'
|
||||||
import { AuthService } from '../../core/auth'
|
import { AuthService } from '../../core/auth'
|
||||||
|
|
||||||
|
@ -49,9 +50,20 @@ function getAbsoluteAPIUrl () {
|
||||||
return absoluteAPIUrl
|
return absoluteAPIUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const datePipe = new DatePipe('en')
|
||||||
|
function dateToHuman (date: string) {
|
||||||
|
return datePipe.transform(date, 'medium')
|
||||||
|
}
|
||||||
|
|
||||||
|
function isInMobileView () {
|
||||||
|
return window.innerWidth < 600
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
viewportHeight,
|
viewportHeight,
|
||||||
getParameterByName,
|
getParameterByName,
|
||||||
populateAsyncUserVideoChannels,
|
populateAsyncUserVideoChannels,
|
||||||
getAbsoluteAPIUrl
|
getAbsoluteAPIUrl,
|
||||||
|
dateToHuman,
|
||||||
|
isInMobileView
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { Injectable } from '@angular/core'
|
|
||||||
import { Observable } from 'rxjs/Observable'
|
|
||||||
import { HttpErrorResponse } from '@angular/common/http'
|
import { HttpErrorResponse } from '@angular/common/http'
|
||||||
|
import { Injectable } from '@angular/core'
|
||||||
import { Utils } from '../utils'
|
import { dateToHuman } from '@app/shared/misc/utils'
|
||||||
|
import { Observable } from 'rxjs/Observable'
|
||||||
import { ResultList } from '../../../../../shared'
|
import { ResultList } from '../../../../../shared'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -16,7 +15,7 @@ export class RestExtractor {
|
||||||
const data: T[] = result.data
|
const data: T[] = result.data
|
||||||
const newData: T[] = []
|
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 {
|
return {
|
||||||
total: result.total,
|
total: result.total,
|
||||||
|
@ -29,12 +28,9 @@ export class RestExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
convertDateToHuman (target: object, fieldsToConvert: string[]) {
|
convertDateToHuman (target: object, fieldsToConvert: string[]) {
|
||||||
const source = {}
|
fieldsToConvert.forEach(field => target[field] = dateToHuman(target[field]))
|
||||||
fieldsToConvert.forEach(field => {
|
|
||||||
source[field] = Utils.dateToHuman(target[field])
|
|
||||||
})
|
|
||||||
|
|
||||||
return Object.assign(target, source)
|
return target
|
||||||
}
|
}
|
||||||
|
|
||||||
handleError (err: HttpErrorResponse) {
|
handleError (err: HttpErrorResponse) {
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
import { DatePipe } from '@angular/common'
|
|
||||||
|
|
||||||
export class Utils {
|
|
||||||
|
|
||||||
static dateToHuman (date: Date) {
|
|
||||||
return new DatePipe('en').transform(date, 'medium')
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,9 +5,8 @@ import 'rxjs/add/operator/catch'
|
||||||
import 'rxjs/add/operator/map'
|
import 'rxjs/add/operator/map'
|
||||||
import { Observable } from 'rxjs/Observable'
|
import { Observable } from 'rxjs/Observable'
|
||||||
import { ResultList, VideoAbuse } from '../../../../../shared'
|
import { ResultList, VideoAbuse } from '../../../../../shared'
|
||||||
import { RestExtractor, RestPagination, RestService } from '../rest'
|
|
||||||
import { Utils } from '../utils'
|
|
||||||
import { environment } from '../../../environments/environment'
|
import { environment } from '../../../environments/environment'
|
||||||
|
import { RestExtractor, RestPagination, RestService } from '../rest'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VideoAbuseService {
|
export class VideoAbuseService {
|
||||||
|
@ -27,7 +26,6 @@ export class VideoAbuseService {
|
||||||
|
|
||||||
return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
|
return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
|
||||||
.map(res => this.restExtractor.convertResultListDateToHuman(res))
|
.map(res => this.restExtractor.convertResultListDateToHuman(res))
|
||||||
.map(res => this.restExtractor.applyToResultListData(res, this.formatVideoAbuse.bind(this)))
|
|
||||||
.catch(res => this.restExtractor.handleError(res))
|
.catch(res => this.restExtractor.handleError(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,11 +39,4 @@ export class VideoAbuseService {
|
||||||
.map(this.restExtractor.extractDataBool)
|
.map(this.restExtractor.extractDataBool)
|
||||||
.catch(res => this.restExtractor.handleError(res))
|
.catch(res => this.restExtractor.handleError(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
private formatVideoAbuse (videoAbuse: VideoAbuse) {
|
|
||||||
return Object.assign(videoAbuse, {
|
|
||||||
createdAt: Utils.dateToHuman(videoAbuse.createdAt)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import { Observable } from 'rxjs/Observable'
|
||||||
import { BlacklistedVideo, ResultList } from '../../../../../shared'
|
import { BlacklistedVideo, ResultList } from '../../../../../shared'
|
||||||
import { environment } from '../../../environments/environment'
|
import { environment } from '../../../environments/environment'
|
||||||
import { RestExtractor, RestPagination, RestService } from '../rest'
|
import { RestExtractor, RestPagination, RestService } from '../rest'
|
||||||
import { Utils } from '../utils'
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VideoBlacklistService {
|
export class VideoBlacklistService {
|
||||||
|
@ -25,7 +24,6 @@ export class VideoBlacklistService {
|
||||||
|
|
||||||
return this.authHttp.get<ResultList<BlacklistedVideo>>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params })
|
return this.authHttp.get<ResultList<BlacklistedVideo>>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params })
|
||||||
.map(res => this.restExtractor.convertResultListDateToHuman(res))
|
.map(res => this.restExtractor.convertResultListDateToHuman(res))
|
||||||
.map(res => this.restExtractor.applyToResultListData(res, this.formatBlacklistedVideo.bind(this)))
|
|
||||||
.catch(res => this.restExtractor.handleError(res))
|
.catch(res => this.restExtractor.handleError(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,10 +38,4 @@ export class VideoBlacklistService {
|
||||||
.map(this.restExtractor.extractDataBool)
|
.map(this.restExtractor.extractDataBool)
|
||||||
.catch(res => this.restExtractor.handleError(res))
|
.catch(res => this.restExtractor.handleError(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
private formatBlacklistedVideo (blacklistedVideo: BlacklistedVideo) {
|
|
||||||
return Object.assign(blacklistedVideo, {
|
|
||||||
createdAt: Utils.dateToHuman(blacklistedVideo.createdAt)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue