diff options
Diffstat (limited to 'client/src/app/videos/shared')
-rw-r--r-- | client/src/app/videos/shared/video.service.ts | 63 |
1 files changed, 28 insertions, 35 deletions
diff --git a/client/src/app/videos/shared/video.service.ts b/client/src/app/videos/shared/video.service.ts index 7658d8ff0..dc12c0637 100644 --- a/client/src/app/videos/shared/video.service.ts +++ b/client/src/app/videos/shared/video.service.ts | |||
@@ -16,7 +16,13 @@ import { | |||
16 | UserService | 16 | UserService |
17 | } from '../../shared' | 17 | } from '../../shared' |
18 | import { Video } from './video.model' | 18 | import { Video } from './video.model' |
19 | import { UserVideoRate, VideoRateType } from '../../../../../shared' | 19 | import { |
20 | UserVideoRate, | ||
21 | VideoRateType, | ||
22 | VideoUpdate, | ||
23 | VideoAbuseCreate, | ||
24 | UserVideoRateUpdate | ||
25 | } from '../../../../../shared' | ||
20 | 26 | ||
21 | @Injectable() | 27 | @Injectable() |
22 | export class VideoService { | 28 | export class VideoService { |
@@ -35,42 +41,15 @@ export class VideoService { | |||
35 | ) {} | 41 | ) {} |
36 | 42 | ||
37 | loadVideoCategories () { | 43 | loadVideoCategories () { |
38 | return this.http.get(VideoService.BASE_VIDEO_URL + 'categories') | 44 | return this.loadVideoAttributeEnum('categories', this.videoCategories) |
39 | .map(this.restExtractor.extractDataGet) | ||
40 | .subscribe(data => { | ||
41 | Object.keys(data).forEach(categoryKey => { | ||
42 | this.videoCategories.push({ | ||
43 | id: parseInt(categoryKey, 10), | ||
44 | label: data[categoryKey] | ||
45 | }) | ||
46 | }) | ||
47 | }) | ||
48 | } | 45 | } |
49 | 46 | ||
50 | loadVideoLicences () { | 47 | loadVideoLicences () { |
51 | return this.http.get(VideoService.BASE_VIDEO_URL + 'licences') | 48 | return this.loadVideoAttributeEnum('licences', this.videoLicences) |
52 | .map(this.restExtractor.extractDataGet) | ||
53 | .subscribe(data => { | ||
54 | Object.keys(data).forEach(licenceKey => { | ||
55 | this.videoLicences.push({ | ||
56 | id: parseInt(licenceKey, 10), | ||
57 | label: data[licenceKey] | ||
58 | }) | ||
59 | }) | ||
60 | }) | ||
61 | } | 49 | } |
62 | 50 | ||
63 | loadVideoLanguages () { | 51 | loadVideoLanguages () { |
64 | return this.http.get(VideoService.BASE_VIDEO_URL + 'languages') | 52 | return this.loadVideoAttributeEnum('languages', this.videoLanguages) |
65 | .map(this.restExtractor.extractDataGet) | ||
66 | .subscribe(data => { | ||
67 | Object.keys(data).forEach(languageKey => { | ||
68 | this.videoLanguages.push({ | ||
69 | id: parseInt(languageKey, 10), | ||
70 | label: data[languageKey] | ||
71 | }) | ||
72 | }) | ||
73 | }) | ||
74 | } | 53 | } |
75 | 54 | ||
76 | getVideo (id: string): Observable<Video> { | 55 | getVideo (id: string): Observable<Video> { |
@@ -83,13 +62,14 @@ export class VideoService { | |||
83 | updateVideo (video: Video) { | 62 | updateVideo (video: Video) { |
84 | const language = video.language ? video.language : null | 63 | const language = video.language ? video.language : null |
85 | 64 | ||
86 | const body = { | 65 | const body: VideoUpdate = { |
87 | name: video.name, | 66 | name: video.name, |
88 | category: video.category, | 67 | category: video.category, |
89 | licence: video.licence, | 68 | licence: video.licence, |
90 | language, | 69 | language, |
91 | description: video.description, | 70 | description: video.description, |
92 | tags: video.tags | 71 | tags: video.tags, |
72 | nsfw: video.nsfw | ||
93 | } | 73 | } |
94 | 74 | ||
95 | const headers = new Headers({ 'Content-Type': 'application/json' }) | 75 | const headers = new Headers({ 'Content-Type': 'application/json' }) |
@@ -128,7 +108,7 @@ export class VideoService { | |||
128 | 108 | ||
129 | reportVideo (id: string, reason: string) { | 109 | reportVideo (id: string, reason: string) { |
130 | const url = VideoService.BASE_VIDEO_URL + id + '/abuse' | 110 | const url = VideoService.BASE_VIDEO_URL + id + '/abuse' |
131 | const body = { | 111 | const body: VideoAbuseCreate = { |
132 | reason | 112 | reason |
133 | } | 113 | } |
134 | 114 | ||
@@ -161,7 +141,7 @@ export class VideoService { | |||
161 | 141 | ||
162 | private setVideoRate (id: string, rateType: VideoRateType) { | 142 | private setVideoRate (id: string, rateType: VideoRateType) { |
163 | const url = VideoService.BASE_VIDEO_URL + id + '/rate' | 143 | const url = VideoService.BASE_VIDEO_URL + id + '/rate' |
164 | const body = { | 144 | const body: UserVideoRateUpdate = { |
165 | rating: rateType | 145 | rating: rateType |
166 | } | 146 | } |
167 | 147 | ||
@@ -180,4 +160,17 @@ export class VideoService { | |||
180 | 160 | ||
181 | return { videos, totalVideos } | 161 | return { videos, totalVideos } |
182 | } | 162 | } |
163 | |||
164 | private loadVideoAttributeEnum (attributeName: 'categories' | 'licences' | 'languages', hashToPopulate: { id: number, label: string }[]) { | ||
165 | return this.http.get(VideoService.BASE_VIDEO_URL + attributeName) | ||
166 | .map(this.restExtractor.extractDataGet) | ||
167 | .subscribe(data => { | ||
168 | Object.keys(data).forEach(dataKey => { | ||
169 | hashToPopulate.push({ | ||
170 | id: parseInt(dataKey, 10), | ||
171 | label: data[dataKey] | ||
172 | }) | ||
173 | }) | ||
174 | }) | ||
175 | } | ||
183 | } | 176 | } |