diff options
-rw-r--r-- | client/src/app/shared/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/shared/misc/utils.ts | 14 | ||||
-rw-r--r-- | client/src/app/shared/rest/rest-extractor.service.ts | 14 | ||||
-rw-r--r-- | client/src/app/shared/utils.ts | 8 | ||||
-rw-r--r-- | client/src/app/shared/video-abuse/video-abuse.service.ts | 11 | ||||
-rw-r--r-- | client/src/app/shared/video-blacklist/video-blacklist.service.ts | 8 |
6 files changed, 19 insertions, 37 deletions
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' | |||
5 | export * from './video-abuse' | 5 | export * from './video-abuse' |
6 | export * from './video-blacklist' | 6 | export * from './video-blacklist' |
7 | export * from './shared.module' | 7 | export * from './shared.module' |
8 | 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 @@ | |||
1 | // Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript | 1 | // Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript |
2 | 2 | ||
3 | import { DatePipe } from '@angular/common' | ||
3 | import { environment } from '../../../environments/environment' | 4 | import { environment } from '../../../environments/environment' |
4 | import { AuthService } from '../../core/auth' | 5 | import { AuthService } from '../../core/auth' |
5 | 6 | ||
@@ -49,9 +50,20 @@ function getAbsoluteAPIUrl () { | |||
49 | return absoluteAPIUrl | 50 | return absoluteAPIUrl |
50 | } | 51 | } |
51 | 52 | ||
53 | const datePipe = new DatePipe('en') | ||
54 | function dateToHuman (date: string) { | ||
55 | return datePipe.transform(date, 'medium') | ||
56 | } | ||
57 | |||
58 | function isInMobileView () { | ||
59 | return window.innerWidth < 600 | ||
60 | } | ||
61 | |||
52 | export { | 62 | export { |
53 | viewportHeight, | 63 | viewportHeight, |
54 | getParameterByName, | 64 | getParameterByName, |
55 | populateAsyncUserVideoChannels, | 65 | populateAsyncUserVideoChannels, |
56 | getAbsoluteAPIUrl | 66 | getAbsoluteAPIUrl, |
67 | dateToHuman, | ||
68 | isInMobileView | ||
57 | } | 69 | } |
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 @@ | |||
1 | import { HttpErrorResponse } from '@angular/common/http' | ||
1 | import { Injectable } from '@angular/core' | 2 | import { Injectable } from '@angular/core' |
3 | import { dateToHuman } from '@app/shared/misc/utils' | ||
2 | import { Observable } from 'rxjs/Observable' | 4 | import { Observable } from 'rxjs/Observable' |
3 | import { HttpErrorResponse } from '@angular/common/http' | ||
4 | |||
5 | import { Utils } from '../utils' | ||
6 | import { ResultList } from '../../../../../shared' | 5 | import { ResultList } from '../../../../../shared' |
7 | 6 | ||
8 | @Injectable() | 7 | @Injectable() |
@@ -16,7 +15,7 @@ export class RestExtractor { | |||
16 | const data: T[] = result.data | 15 | const data: T[] = result.data |
17 | const newData: T[] = [] | 16 | const newData: T[] = [] |
18 | 17 | ||
19 | data.forEach(d => newData.push(fun.call(this, d, additionalArgs))) | 18 | data.forEach(d => newData.push(fun.apply(this, [ d ].concat(additionalArgs)))) |
20 | 19 | ||
21 | return { | 20 | return { |
22 | total: result.total, | 21 | total: result.total, |
@@ -29,12 +28,9 @@ export class RestExtractor { | |||
29 | } | 28 | } |
30 | 29 | ||
31 | convertDateToHuman (target: object, fieldsToConvert: string[]) { | 30 | convertDateToHuman (target: object, fieldsToConvert: string[]) { |
32 | const source = {} | 31 | fieldsToConvert.forEach(field => target[field] = dateToHuman(target[field])) |
33 | fieldsToConvert.forEach(field => { | ||
34 | source[field] = Utils.dateToHuman(target[field]) | ||
35 | }) | ||
36 | 32 | ||
37 | return Object.assign(target, source) | 33 | return target |
38 | } | 34 | } |
39 | 35 | ||
40 | handleError (err: HttpErrorResponse) { | 36 | 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 @@ | |||
1 | import { DatePipe } from '@angular/common' | ||
2 | |||
3 | export class Utils { | ||
4 | |||
5 | static dateToHuman (date: Date) { | ||
6 | return new DatePipe('en').transform(date, 'medium') | ||
7 | } | ||
8 | } | ||
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' | |||
5 | import 'rxjs/add/operator/map' | 5 | import 'rxjs/add/operator/map' |
6 | import { Observable } from 'rxjs/Observable' | 6 | import { Observable } from 'rxjs/Observable' |
7 | import { ResultList, VideoAbuse } from '../../../../../shared' | 7 | import { ResultList, VideoAbuse } from '../../../../../shared' |
8 | import { RestExtractor, RestPagination, RestService } from '../rest' | ||
9 | import { Utils } from '../utils' | ||
10 | import { environment } from '../../../environments/environment' | 8 | import { environment } from '../../../environments/environment' |
9 | import { RestExtractor, RestPagination, RestService } from '../rest' | ||
11 | 10 | ||
12 | @Injectable() | 11 | @Injectable() |
13 | export class VideoAbuseService { | 12 | export class VideoAbuseService { |
@@ -27,7 +26,6 @@ export class VideoAbuseService { | |||
27 | 26 | ||
28 | return this.authHttp.get<ResultList<VideoAbuse>>(url, { params }) | 27 | return this.authHttp.get<ResultList<VideoAbuse>>(url, { params }) |
29 | .map(res => this.restExtractor.convertResultListDateToHuman(res)) | 28 | .map(res => this.restExtractor.convertResultListDateToHuman(res)) |
30 | .map(res => this.restExtractor.applyToResultListData(res, this.formatVideoAbuse.bind(this))) | ||
31 | .catch(res => this.restExtractor.handleError(res)) | 29 | .catch(res => this.restExtractor.handleError(res)) |
32 | } | 30 | } |
33 | 31 | ||
@@ -41,11 +39,4 @@ export class VideoAbuseService { | |||
41 | .map(this.restExtractor.extractDataBool) | 39 | .map(this.restExtractor.extractDataBool) |
42 | .catch(res => this.restExtractor.handleError(res)) | 40 | .catch(res => this.restExtractor.handleError(res)) |
43 | } | 41 | } |
44 | |||
45 | private formatVideoAbuse (videoAbuse: VideoAbuse) { | ||
46 | return Object.assign(videoAbuse, { | ||
47 | createdAt: Utils.dateToHuman(videoAbuse.createdAt) | ||
48 | }) | ||
49 | } | ||
50 | |||
51 | } | 42 | } |
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' | |||
7 | import { BlacklistedVideo, ResultList } from '../../../../../shared' | 7 | import { BlacklistedVideo, ResultList } from '../../../../../shared' |
8 | import { environment } from '../../../environments/environment' | 8 | import { environment } from '../../../environments/environment' |
9 | import { RestExtractor, RestPagination, RestService } from '../rest' | 9 | import { RestExtractor, RestPagination, RestService } from '../rest' |
10 | import { Utils } from '../utils' | ||
11 | 10 | ||
12 | @Injectable() | 11 | @Injectable() |
13 | export class VideoBlacklistService { | 12 | export class VideoBlacklistService { |
@@ -25,7 +24,6 @@ export class VideoBlacklistService { | |||
25 | 24 | ||
26 | return this.authHttp.get<ResultList<BlacklistedVideo>>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params }) | 25 | return this.authHttp.get<ResultList<BlacklistedVideo>>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params }) |
27 | .map(res => this.restExtractor.convertResultListDateToHuman(res)) | 26 | .map(res => this.restExtractor.convertResultListDateToHuman(res)) |
28 | .map(res => this.restExtractor.applyToResultListData(res, this.formatBlacklistedVideo.bind(this))) | ||
29 | .catch(res => this.restExtractor.handleError(res)) | 27 | .catch(res => this.restExtractor.handleError(res)) |
30 | } | 28 | } |
31 | 29 | ||
@@ -40,10 +38,4 @@ export class VideoBlacklistService { | |||
40 | .map(this.restExtractor.extractDataBool) | 38 | .map(this.restExtractor.extractDataBool) |
41 | .catch(res => this.restExtractor.handleError(res)) | 39 | .catch(res => this.restExtractor.handleError(res)) |
42 | } | 40 | } |
43 | |||
44 | private formatBlacklistedVideo (blacklistedVideo: BlacklistedVideo) { | ||
45 | return Object.assign(blacklistedVideo, { | ||
46 | createdAt: Utils.dateToHuman(blacklistedVideo.createdAt) | ||
47 | }) | ||
48 | } | ||
49 | } | 41 | } |