diff options
Diffstat (limited to 'client/src/app/videos/+video-edit/video-add.component.ts')
-rw-r--r-- | client/src/app/videos/+video-edit/video-add.component.ts | 30 |
1 files changed, 20 insertions, 10 deletions
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 2409acfda..2bbc3de17 100644 --- a/client/src/app/videos/+video-edit/video-add.component.ts +++ b/client/src/app/videos/+video-edit/video-add.component.ts | |||
@@ -5,6 +5,7 @@ import { Router } from '@angular/router' | |||
5 | import { NotificationsService } from 'angular2-notifications' | 5 | import { NotificationsService } from 'angular2-notifications' |
6 | import { VideoService } from 'app/shared/video/video.service' | 6 | import { VideoService } from 'app/shared/video/video.service' |
7 | import { VideoCreate } from '../../../../../shared' | 7 | import { VideoCreate } from '../../../../../shared' |
8 | import { VideoPrivacy } from '../../../../../shared/models/videos' | ||
8 | import { AuthService, ServerService } from '../../core' | 9 | import { AuthService, ServerService } from '../../core' |
9 | import { FormReactive } from '../../shared' | 10 | import { FormReactive } from '../../shared' |
10 | import { ValidatorMessage } from '../../shared/forms/form-validators' | 11 | import { ValidatorMessage } from '../../shared/forms/form-validators' |
@@ -25,6 +26,7 @@ export class VideoAddComponent extends FormReactive implements OnInit { | |||
25 | isUploadingVideo = false | 26 | isUploadingVideo = false |
26 | videoUploaded = false | 27 | videoUploaded = false |
27 | videoUploadPercents = 0 | 28 | videoUploadPercents = 0 |
29 | videoUploadedId = 0 | ||
28 | 30 | ||
29 | error: string = null | 31 | error: string = null |
30 | form: FormGroup | 32 | form: FormGroup |
@@ -33,8 +35,8 @@ export class VideoAddComponent extends FormReactive implements OnInit { | |||
33 | 35 | ||
34 | userVideoChannels = [] | 36 | userVideoChannels = [] |
35 | videoPrivacies = [] | 37 | videoPrivacies = [] |
36 | firstStepPrivacy = 0 | 38 | firstStepPrivacyId = 0 |
37 | firstStepChannel = 0 | 39 | firstStepChannelId = 0 |
38 | 40 | ||
39 | constructor ( | 41 | constructor ( |
40 | private formBuilder: FormBuilder, | 42 | private formBuilder: FormBuilder, |
@@ -59,7 +61,9 @@ export class VideoAddComponent extends FormReactive implements OnInit { | |||
59 | .subscribe( | 61 | .subscribe( |
60 | () => { | 62 | () => { |
61 | this.videoPrivacies = this.serverService.getVideoPrivacies() | 63 | this.videoPrivacies = this.serverService.getVideoPrivacies() |
62 | this.firstStepPrivacy = this.videoPrivacies[0].id | 64 | |
65 | // Public by default | ||
66 | this.firstStepPrivacyId = VideoPrivacy.PUBLIC | ||
63 | }) | 67 | }) |
64 | 68 | ||
65 | this.authService.userInformationLoaded | 69 | this.authService.userInformationLoaded |
@@ -72,7 +76,7 @@ export class VideoAddComponent extends FormReactive implements OnInit { | |||
72 | if (Array.isArray(videoChannels) === false) return | 76 | if (Array.isArray(videoChannels) === false) return |
73 | 77 | ||
74 | this.userVideoChannels = videoChannels.map(v => ({ id: v.id, label: v.name })) | 78 | this.userVideoChannels = videoChannels.map(v => ({ id: v.id, label: v.name })) |
75 | this.firstStepChannel = this.userVideoChannels[0].id | 79 | this.firstStepChannelId = this.userVideoChannels[0].id |
76 | } | 80 | } |
77 | ) | 81 | ) |
78 | } | 82 | } |
@@ -89,14 +93,15 @@ export class VideoAddComponent extends FormReactive implements OnInit { | |||
89 | 93 | ||
90 | uploadFirstStep () { | 94 | uploadFirstStep () { |
91 | const videofile = this.videofileInput.nativeElement.files[0] | 95 | const videofile = this.videofileInput.nativeElement.files[0] |
92 | const name = videofile.name | 96 | const name = videofile.name.replace(/\.[^/.]+$/, '') |
93 | const privacy = this.firstStepPrivacy.toString() | 97 | const privacy = this.firstStepPrivacyId.toString() |
94 | const nsfw = false | 98 | const nsfw = false |
95 | const channelId = this.firstStepChannel.toString() | 99 | const channelId = this.firstStepChannelId.toString() |
96 | 100 | ||
97 | const formData = new FormData() | 101 | const formData = new FormData() |
98 | formData.append('name', name) | 102 | formData.append('name', name) |
99 | formData.append('privacy', privacy.toString()) | 103 | // Put the video "private" -> we wait he validates the second step |
104 | formData.append('privacy', VideoPrivacy.PRIVATE.toString()) | ||
100 | formData.append('nsfw', '' + nsfw) | 105 | formData.append('nsfw', '' + nsfw) |
101 | formData.append('channelId', '' + channelId) | 106 | formData.append('channelId', '' + channelId) |
102 | formData.append('videofile', videofile) | 107 | formData.append('videofile', videofile) |
@@ -117,6 +122,8 @@ export class VideoAddComponent extends FormReactive implements OnInit { | |||
117 | console.log('Video uploaded.') | 122 | console.log('Video uploaded.') |
118 | 123 | ||
119 | this.videoUploaded = true | 124 | this.videoUploaded = true |
125 | |||
126 | this.videoUploadedId = event.body.video.id | ||
120 | } | 127 | } |
121 | }, | 128 | }, |
122 | 129 | ||
@@ -133,13 +140,16 @@ export class VideoAddComponent extends FormReactive implements OnInit { | |||
133 | return | 140 | return |
134 | } | 141 | } |
135 | 142 | ||
136 | const video = new VideoEdit(this.form.value) | 143 | const video = new VideoEdit() |
144 | video.patch(this.form.value) | ||
145 | video.channel = this.firstStepChannelId | ||
146 | video.id = this.videoUploadedId | ||
137 | 147 | ||
138 | this.videoService.updateVideo(video) | 148 | this.videoService.updateVideo(video) |
139 | .subscribe( | 149 | .subscribe( |
140 | () => { | 150 | () => { |
141 | this.notificationsService.success('Success', 'Video published.') | 151 | this.notificationsService.success('Success', 'Video published.') |
142 | this.router.navigate([ '/videos/watch', video.uuid ]) | 152 | this.router.navigate([ '/videos/watch', video.id ]) |
143 | }, | 153 | }, |
144 | 154 | ||
145 | err => { | 155 | err => { |