export * from './video-abuse'
export * from './video-blacklist'
export * from './shared.module'
-export * from './utils'
// 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'
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
}
+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()
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,
}
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) {
+++ /dev/null
-import { DatePipe } from '@angular/common'
-
-export class Utils {
-
- static dateToHuman (date: Date) {
- return new DatePipe('en').transform(date, 'medium')
- }
-}
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 {
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))
}
.map(this.restExtractor.extractDataBool)
.catch(res => this.restExtractor.handleError(res))
}
-
- private formatVideoAbuse (videoAbuse: VideoAbuse) {
- return Object.assign(videoAbuse, {
- createdAt: Utils.dateToHuman(videoAbuse.createdAt)
- })
- }
-
}
import { BlacklistedVideo, ResultList } from '../../../../../shared'
import { environment } from '../../../environments/environment'
import { RestExtractor, RestPagination, RestService } from '../rest'
-import { Utils } from '../utils'
@Injectable()
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))
}
.map(this.restExtractor.extractDataBool)
.catch(res => this.restExtractor.handleError(res))
}
-
- private formatBlacklistedVideo (blacklistedVideo: BlacklistedVideo) {
- return Object.assign(blacklistedVideo, {
- createdAt: Utils.dateToHuman(blacklistedVideo.createdAt)
- })
- }
}