]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix human dates in result lists
authorChocobozzz <me@florianbigard.com>
Wed, 31 Jan 2018 09:41:44 +0000 (10:41 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 31 Jan 2018 09:41:44 +0000 (10:41 +0100)
client/src/app/shared/index.ts
client/src/app/shared/misc/utils.ts
client/src/app/shared/rest/rest-extractor.service.ts
client/src/app/shared/utils.ts [deleted file]
client/src/app/shared/video-abuse/video-abuse.service.ts
client/src/app/shared/video-blacklist/video-blacklist.service.ts

index 413dda16acb63a65f2fc2cebd0bed90cc2e35389..136730c91a36a8b8315f38824b546234ac45cbe1 100644 (file)
@@ -5,4 +5,3 @@ export * from './users'
 export * from './video-abuse'
 export * from './video-blacklist'
 export * from './shared.module'
-export * from './utils'
index 23b46812b5a330e77abe7f83db087d7a2f10d83d..0e6e6b3661eb6fbe4bffcf7989bc98fd374a51e9 100644 (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
 }
index 1b475da89adc8f1c0f4089f2897388de4628a781..ad08a32f80b7bfcb7dcaef59a0fc9f4dd9d30170 100644 (file)
@@ -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 (file)
index 7c8ae2e..0000000
+++ /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')
-  }
-}
index 96a1f1fd2eadb3cf4a8fa626f5489d95e2bc13cd..ae00c4c45d48245354026d4980d9c2c47402afe2 100644 (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)
-    })
-  }
-
 }
index 1231690aa1663aeb93f8389a638cc9c2f19d910d..14c8b5dc06252f54fff7a0647f14af61fd861f7d 100644 (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)
-    })
-  }
 }