aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/video-edit/video-add.component.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-16 14:32:15 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-16 14:32:15 +0200
commitdf98563e2104b82b119c00a3cd83cd0dc1242d25 (patch)
treea9720bf01bac9ad5646bd3d3c9bc7653617afdad /client/src/app/videos/video-edit/video-add.component.ts
parent46757b477c1adb5f98060d15998a3852e18902a6 (diff)
downloadPeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.tar.gz
PeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.tar.zst
PeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.zip
Use typescript standard and lint all files
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.ts159
1 files changed, 75 insertions, 84 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 e5eb9a9f4..0653f5ac4 100644
--- a/client/src/app/videos/video-edit/video-add.component.ts
+++ b/client/src/app/videos/video-edit/video-add.component.ts
@@ -1,11 +1,11 @@
1import { Component, ElementRef, OnInit } from '@angular/core'; 1import { Component, ElementRef, OnInit } from '@angular/core'
2import { FormBuilder, FormGroup } from '@angular/forms'; 2import { FormBuilder, FormGroup } from '@angular/forms'
3import { Router } from '@angular/router'; 3import { Router } from '@angular/router'
4 4
5import { FileUploader } from 'ng2-file-upload/ng2-file-upload'; 5import { FileUploader } from 'ng2-file-upload/ng2-file-upload'
6import { NotificationsService } from 'angular2-notifications'; 6import { NotificationsService } from 'angular2-notifications'
7 7
8import { AuthService } from '../../core'; 8import { AuthService } from '../../core'
9import { 9import {
10 FormReactive, 10 FormReactive,
11 VIDEO_NAME, 11 VIDEO_NAME,
@@ -14,8 +14,8 @@ import {
14 VIDEO_LANGUAGE, 14 VIDEO_LANGUAGE,
15 VIDEO_DESCRIPTION, 15 VIDEO_DESCRIPTION,
16 VIDEO_TAGS 16 VIDEO_TAGS
17} from '../../shared'; 17} from '../../shared'
18import { VideoService } from '../shared'; 18import { VideoService } from '../shared'
19 19
20@Component({ 20@Component({
21 selector: 'my-videos-add', 21 selector: 'my-videos-add',
@@ -24,36 +24,36 @@ import { VideoService } from '../shared';
24}) 24})
25 25
26export class VideoAddComponent extends FormReactive implements OnInit { 26export class VideoAddComponent extends FormReactive implements OnInit {
27 tags: string[] = []; 27 tags: string[] = []
28 uploader: FileUploader; 28 uploader: FileUploader
29 videoCategories = []; 29 videoCategories = []
30 videoLicences = []; 30 videoLicences = []
31 videoLanguages = []; 31 videoLanguages = []
32 32
33 tagValidators = VIDEO_TAGS.VALIDATORS; 33 tagValidators = VIDEO_TAGS.VALIDATORS
34 tagValidatorsMessages = VIDEO_TAGS.MESSAGES; 34 tagValidatorsMessages = VIDEO_TAGS.MESSAGES
35 35
36 error: string = null; 36 error: string = null
37 form: FormGroup; 37 form: FormGroup
38 formErrors = { 38 formErrors = {
39 name: '', 39 name: '',
40 category: '', 40 category: '',
41 licence: '', 41 licence: '',
42 language: '', 42 language: '',
43 description: '' 43 description: ''
44 }; 44 }
45 validationMessages = { 45 validationMessages = {
46 name: VIDEO_NAME.MESSAGES, 46 name: VIDEO_NAME.MESSAGES,
47 category: VIDEO_CATEGORY.MESSAGES, 47 category: VIDEO_CATEGORY.MESSAGES,
48 licence: VIDEO_LICENCE.MESSAGES, 48 licence: VIDEO_LICENCE.MESSAGES,
49 language: VIDEO_LANGUAGE.MESSAGES, 49 language: VIDEO_LANGUAGE.MESSAGES,
50 description: VIDEO_DESCRIPTION.MESSAGES 50 description: VIDEO_DESCRIPTION.MESSAGES
51 }; 51 }
52 52
53 // Special error messages 53 // Special error messages
54 fileError = ''; 54 fileError = ''
55 55
56 constructor( 56 constructor (
57 private authService: AuthService, 57 private authService: AuthService,
58 private elementRef: ElementRef, 58 private elementRef: ElementRef,
59 private formBuilder: FormBuilder, 59 private formBuilder: FormBuilder,
@@ -61,18 +61,18 @@ export class VideoAddComponent extends FormReactive implements OnInit {
61 private notificationsService: NotificationsService, 61 private notificationsService: NotificationsService,
62 private videoService: VideoService 62 private videoService: VideoService
63 ) { 63 ) {
64 super(); 64 super()
65 } 65 }
66 66
67 get filename() { 67 get filename () {
68 if (this.uploader.queue.length === 0) { 68 if (this.uploader.queue.length === 0) {
69 return null; 69 return null
70 } 70 }
71 71
72 return this.uploader.queue[0].file.name; 72 return this.uploader.queue[0].file.name
73 } 73 }
74 74
75 buildForm() { 75 buildForm () {
76 this.form = this.formBuilder.group({ 76 this.form = this.formBuilder.group({
77 name: [ '', VIDEO_NAME.VALIDATORS ], 77 name: [ '', VIDEO_NAME.VALIDATORS ],
78 nsfw: [ false ], 78 nsfw: [ false ],
@@ -81,115 +81,106 @@ export class VideoAddComponent extends FormReactive implements OnInit {
81 language: [ '', VIDEO_LANGUAGE.VALIDATORS ], 81 language: [ '', VIDEO_LANGUAGE.VALIDATORS ],
82 description: [ '', VIDEO_DESCRIPTION.VALIDATORS ], 82 description: [ '', VIDEO_DESCRIPTION.VALIDATORS ],
83 tags: [ ''] 83 tags: [ '']
84 }); 84 })
85 85
86 this.form.valueChanges.subscribe(data => this.onValueChanged(data)); 86 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
87 } 87 }
88 88
89 ngOnInit() { 89 ngOnInit () {
90 this.videoCategories = this.videoService.videoCategories; 90 this.videoCategories = this.videoService.videoCategories
91 this.videoLicences = this.videoService.videoLicences; 91 this.videoLicences = this.videoService.videoLicences
92 this.videoLanguages = this.videoService.videoLanguages; 92 this.videoLanguages = this.videoService.videoLanguages
93 93
94 this.uploader = new FileUploader({ 94 this.uploader = new FileUploader({
95 authToken: this.authService.getRequestHeaderValue(), 95 authToken: this.authService.getRequestHeaderValue(),
96 queueLimit: 1, 96 queueLimit: 1,
97 url: API_URL + '/api/v1/videos', 97 url: API_URL + '/api/v1/videos',
98 removeAfterUpload: true 98 removeAfterUpload: true
99 }); 99 })
100 100
101 this.uploader.onBuildItemForm = (item, form) => { 101 this.uploader.onBuildItemForm = (item, form) => {
102 const name = this.form.value['name']; 102 const name = this.form.value['name']
103 const nsfw = this.form.value['nsfw']; 103 const nsfw = this.form.value['nsfw']
104 const category = this.form.value['category']; 104 const category = this.form.value['category']
105 const licence = this.form.value['licence']; 105 const licence = this.form.value['licence']
106 const language = this.form.value['language']; 106 const language = this.form.value['language']
107 const description = this.form.value['description']; 107 const description = this.form.value['description']
108 const tags = this.form.value['tags']; 108 const tags = this.form.value['tags']
109 109
110 form.append('name', name); 110 form.append('name', name)
111 form.append('category', category); 111 form.append('category', category)
112 form.append('nsfw', nsfw); 112 form.append('nsfw', nsfw)
113 form.append('licence', licence); 113 form.append('licence', licence)
114 114
115 // Language is optional 115 // Language is optional
116 if (language) { 116 if (language) {
117 form.append('language', language); 117 form.append('language', language)
118 } 118 }
119 119
120 form.append('description', description); 120 form.append('description', description)
121 121
122 for (let i = 0; i < tags.length; i++) { 122 for (let i = 0; i < tags.length; i++) {
123 form.append(`tags[${i}]`, tags[i]); 123 form.append(`tags[${i}]`, tags[i])
124 } 124 }
125 }; 125 }
126 126
127 this.buildForm(); 127 this.buildForm()
128 } 128 }
129 129
130 checkForm() { 130 checkForm () {
131 this.forceCheck(); 131 this.forceCheck()
132 132
133 if (this.filename === null) { 133 if (this.filename === null) {
134 this.fileError = 'You did not add a file.'; 134 this.fileError = 'You did not add a file.'
135 } 135 }
136 136
137 return this.form.valid === true && this.fileError === ''; 137 return this.form.valid === true && this.fileError === ''
138 } 138 }
139 139
140 fileChanged() { 140 fileChanged () {
141 this.fileError = ''; 141 this.fileError = ''
142 } 142 }
143 143
144 removeFile() { 144 removeFile () {
145 this.uploader.clearQueue(); 145 this.uploader.clearQueue()
146 } 146 }
147 147
148 upload() { 148 upload () {
149 if (this.checkForm() === false) { 149 if (this.checkForm() === false) {
150 return; 150 return
151 } 151 }
152 152
153 const item = this.uploader.queue[0]; 153 const item = this.uploader.queue[0]
154 // TODO: wait for https://github.com/valor-software/ng2-file-upload/pull/242 154 // TODO: wait for https://github.com/valor-software/ng2-file-upload/pull/242
155 item.alias = 'videofile'; 155 item.alias = 'videofile'
156
157 // FIXME: remove
158 // Run detection change for progress bar
159 const interval = setInterval(() => { ; }, 250);
160 156
161 item.onSuccess = () => { 157 item.onSuccess = () => {
162 clearInterval(interval); 158 console.log('Video uploaded.')
163 159 this.notificationsService.success('Success', 'Video uploaded.')
164 console.log('Video uploaded.');
165 this.notificationsService.success('Success', 'Video uploaded.');
166
167 160
168 // Print all the videos once it's finished 161 // Print all the videos once it's finished
169 this.router.navigate(['/videos/list']); 162 this.router.navigate(['/videos/list'])
170 }; 163 }
171 164
172 item.onError = (response: string, status: number) => { 165 item.onError = (response: string, status: number) => {
173 clearInterval(interval);
174
175 // We need to handle manually these cases beceause we use the FileUpload component 166 // We need to handle manually these cases beceause we use the FileUpload component
176 if (status === 400) { 167 if (status === 400) {
177 this.error = response; 168 this.error = response
178 } else if (status === 401) { 169 } else if (status === 401) {
179 this.error = 'Access token was expired, refreshing token...'; 170 this.error = 'Access token was expired, refreshing token...'
180 this.authService.refreshAccessToken().subscribe( 171 this.authService.refreshAccessToken().subscribe(
181 () => { 172 () => {
182 // Update the uploader request header 173 // Update the uploader request header
183 this.uploader.authToken = this.authService.getRequestHeaderValue(); 174 this.uploader.authToken = this.authService.getRequestHeaderValue()
184 this.error += ' access token refreshed. Please retry your request.'; 175 this.error += ' access token refreshed. Please retry your request.'
185 } 176 }
186 ); 177 )
187 } else { 178 } else {
188 this.error = 'Unknow error'; 179 this.error = 'Unknow error'
189 console.error(this.error); 180 console.error(this.error)
190 } 181 }
191 }; 182 }
192 183
193 this.uploader.uploadAll(); 184 this.uploader.uploadAll()
194 } 185 }
195} 186}