aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/videos')
-rw-r--r--client/src/app/videos/shared/video.service.ts63
-rw-r--r--client/src/app/videos/video-edit/video-add.component.ts27
2 files changed, 43 insertions, 47 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'
18import { Video } from './video.model' 18import { Video } from './video.model'
19import { UserVideoRate, VideoRateType } from '../../../../../shared' 19import {
20 UserVideoRate,
21 VideoRateType,
22 VideoUpdate,
23 VideoAbuseCreate,
24 UserVideoRateUpdate
25} from '../../../../../shared'
20 26
21@Injectable() 27@Injectable()
22export class VideoService { 28export 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}
diff --git a/client/src/app/videos/video-edit/video-add.component.ts b/client/src/app/videos/video-edit/video-add.component.ts
index 0653f5ac4..5d6c0e0c7 100644
--- a/client/src/app/videos/video-edit/video-add.component.ts
+++ b/client/src/app/videos/video-edit/video-add.component.ts
@@ -16,6 +16,7 @@ import {
16 VIDEO_TAGS 16 VIDEO_TAGS
17} from '../../shared' 17} from '../../shared'
18import { VideoService } from '../shared' 18import { VideoService } from '../shared'
19import { VideoCreate } from '../../../../../shared'
19 20
20@Component({ 21@Component({
21 selector: 'my-videos-add', 22 selector: 'my-videos-add',
@@ -98,23 +99,25 @@ export class VideoAddComponent extends FormReactive implements OnInit {
98 removeAfterUpload: true 99 removeAfterUpload: true
99 }) 100 })
100 101
101 this.uploader.onBuildItemForm = (item, form) => { 102 this.uploader.onBuildItemForm = (item, form: FormData) => {
102 const name = this.form.value['name'] 103 const formValue: VideoCreate = this.form.value
103 const nsfw = this.form.value['nsfw'] 104
104 const category = this.form.value['category'] 105 const name = formValue.name
105 const licence = this.form.value['licence'] 106 const nsfw = formValue.nsfw
106 const language = this.form.value['language'] 107 const category = formValue.category
107 const description = this.form.value['description'] 108 const licence = formValue.licence
108 const tags = this.form.value['tags'] 109 const language = formValue.language
110 const description = formValue.description
111 const tags = formValue.tags
109 112
110 form.append('name', name) 113 form.append('name', name)
111 form.append('category', category) 114 form.append('category', '' + category)
112 form.append('nsfw', nsfw) 115 form.append('nsfw', '' + nsfw)
113 form.append('licence', licence) 116 form.append('licence', '' + licence)
114 117
115 // Language is optional 118 // Language is optional
116 if (language) { 119 if (language) {
117 form.append('language', language) 120 form.append('language', '' + language)
118 } 121 }
119 122
120 form.append('description', description) 123 form.append('description', description)