diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-16 14:32:15 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-16 14:32:15 +0200 |
commit | df98563e2104b82b119c00a3cd83cd0dc1242d25 (patch) | |
tree | a9720bf01bac9ad5646bd3d3c9bc7653617afdad /client/src/app/videos/video-edit | |
parent | 46757b477c1adb5f98060d15998a3852e18902a6 (diff) | |
download | PeerTube-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')
-rw-r--r-- | client/src/app/videos/video-edit/index.ts | 4 | ||||
-rw-r--r-- | client/src/app/videos/video-edit/video-add.component.ts | 159 | ||||
-rw-r--r-- | client/src/app/videos/video-edit/video-update.component.ts | 99 |
3 files changed, 128 insertions, 134 deletions
diff --git a/client/src/app/videos/video-edit/index.ts b/client/src/app/videos/video-edit/index.ts index 5ce4fb9b1..3b4a9cb87 100644 --- a/client/src/app/videos/video-edit/index.ts +++ b/client/src/app/videos/video-edit/index.ts | |||
@@ -1,2 +1,2 @@ | |||
1 | export * from './video-add.component'; | 1 | export * from './video-add.component' |
2 | export * from './video-update.component'; | 2 | export * from './video-update.component' |
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 @@ | |||
1 | import { Component, ElementRef, OnInit } from '@angular/core'; | 1 | import { Component, ElementRef, OnInit } from '@angular/core' |
2 | import { FormBuilder, FormGroup } from '@angular/forms'; | 2 | import { FormBuilder, FormGroup } from '@angular/forms' |
3 | import { Router } from '@angular/router'; | 3 | import { Router } from '@angular/router' |
4 | 4 | ||
5 | import { FileUploader } from 'ng2-file-upload/ng2-file-upload'; | 5 | import { FileUploader } from 'ng2-file-upload/ng2-file-upload' |
6 | import { NotificationsService } from 'angular2-notifications'; | 6 | import { NotificationsService } from 'angular2-notifications' |
7 | 7 | ||
8 | import { AuthService } from '../../core'; | 8 | import { AuthService } from '../../core' |
9 | import { | 9 | import { |
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' |
18 | import { VideoService } from '../shared'; | 18 | import { 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 | ||
26 | export class VideoAddComponent extends FormReactive implements OnInit { | 26 | export 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 | } |
diff --git a/client/src/app/videos/video-edit/video-update.component.ts b/client/src/app/videos/video-edit/video-update.component.ts index 933132cc0..9ee7ca6a8 100644 --- a/client/src/app/videos/video-edit/video-update.component.ts +++ b/client/src/app/videos/video-edit/video-update.component.ts | |||
@@ -1,11 +1,11 @@ | |||
1 | import { Component, ElementRef, OnInit } from '@angular/core'; | 1 | import { Component, ElementRef, OnInit } from '@angular/core' |
2 | import { FormBuilder, FormGroup } from '@angular/forms'; | 2 | import { FormBuilder, FormGroup } from '@angular/forms' |
3 | import { ActivatedRoute, Router } from '@angular/router'; | 3 | import { ActivatedRoute, Router } from '@angular/router' |
4 | 4 | ||
5 | import { FileUploader } from 'ng2-file-upload/ng2-file-upload'; | 5 | import { FileUploader } from 'ng2-file-upload/ng2-file-upload' |
6 | import { NotificationsService } from 'angular2-notifications'; | 6 | import { NotificationsService } from 'angular2-notifications' |
7 | 7 | ||
8 | import { AuthService } from '../../core'; | 8 | import { AuthService } from '../../core' |
9 | import { | 9 | import { |
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' |
18 | import { Video, VideoService } from '../shared'; | 18 | import { Video, VideoService } from '../shared' |
19 | 19 | ||
20 | @Component({ | 20 | @Component({ |
21 | selector: 'my-videos-update', | 21 | selector: 'my-videos-update', |
@@ -24,35 +24,35 @@ import { Video, VideoService } from '../shared'; | |||
24 | }) | 24 | }) |
25 | 25 | ||
26 | export class VideoUpdateComponent extends FormReactive implements OnInit { | 26 | export class VideoUpdateComponent extends FormReactive implements OnInit { |
27 | tags: string[] = []; | 27 | tags: string[] = [] |
28 | videoCategories = []; | 28 | videoCategories = [] |
29 | videoLicences = []; | 29 | videoLicences = [] |
30 | videoLanguages = []; | 30 | videoLanguages = [] |
31 | video: Video; | 31 | video: Video |
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 | fileError = ''; | 53 | fileError = '' |
54 | 54 | ||
55 | constructor( | 55 | constructor ( |
56 | private authService: AuthService, | 56 | private authService: AuthService, |
57 | private elementRef: ElementRef, | 57 | private elementRef: ElementRef, |
58 | private formBuilder: FormBuilder, | 58 | private formBuilder: FormBuilder, |
@@ -61,10 +61,10 @@ export class VideoUpdateComponent 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 | buildForm() { | 67 | buildForm () { |
68 | this.form = this.formBuilder.group({ | 68 | this.form = this.formBuilder.group({ |
69 | name: [ '', VIDEO_NAME.VALIDATORS ], | 69 | name: [ '', VIDEO_NAME.VALIDATORS ], |
70 | nsfw: [ false ], | 70 | nsfw: [ false ], |
@@ -73,60 +73,63 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { | |||
73 | language: [ '', VIDEO_LANGUAGE.VALIDATORS ], | 73 | language: [ '', VIDEO_LANGUAGE.VALIDATORS ], |
74 | description: [ '', VIDEO_DESCRIPTION.VALIDATORS ], | 74 | description: [ '', VIDEO_DESCRIPTION.VALIDATORS ], |
75 | tags: [ '' ] | 75 | tags: [ '' ] |
76 | }); | 76 | }) |
77 | 77 | ||
78 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)); | 78 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) |
79 | } | 79 | } |
80 | 80 | ||
81 | ngOnInit() { | 81 | ngOnInit () { |
82 | this.buildForm(); | 82 | this.buildForm() |
83 | 83 | ||
84 | this.videoCategories = this.videoService.videoCategories; | 84 | this.videoCategories = this.videoService.videoCategories |
85 | this.videoLicences = this.videoService.videoLicences; | 85 | this.videoLicences = this.videoService.videoLicences |
86 | this.videoLanguages = this.videoService.videoLanguages; | 86 | this.videoLanguages = this.videoService.videoLanguages |
87 | 87 | ||
88 | const id = this.route.snapshot.params['id']; | 88 | const id = this.route.snapshot.params['id'] |
89 | this.videoService.getVideo(id) | 89 | this.videoService.getVideo(id) |
90 | .subscribe( | 90 | .subscribe( |
91 | video => { | 91 | video => { |
92 | this.video = video; | 92 | this.video = video |
93 | 93 | ||
94 | this.hydrateFormFromVideo(); | 94 | this.hydrateFormFromVideo() |
95 | }, | 95 | }, |
96 | 96 | ||
97 | err => this.error = 'Cannot fetch video.' | 97 | err => { |
98 | ); | 98 | console.error(err) |
99 | this.error = 'Cannot fetch video.' | ||
100 | } | ||
101 | ) | ||
99 | } | 102 | } |
100 | 103 | ||
101 | checkForm() { | 104 | checkForm () { |
102 | this.forceCheck(); | 105 | this.forceCheck() |
103 | 106 | ||
104 | return this.form.valid; | 107 | return this.form.valid |
105 | } | 108 | } |
106 | 109 | ||
107 | update() { | 110 | update () { |
108 | if (this.checkForm() === false) { | 111 | if (this.checkForm() === false) { |
109 | return; | 112 | return |
110 | } | 113 | } |
111 | 114 | ||
112 | this.video.patch(this.form.value); | 115 | this.video.patch(this.form.value) |
113 | 116 | ||
114 | this.videoService.updateVideo(this.video) | 117 | this.videoService.updateVideo(this.video) |
115 | .subscribe( | 118 | .subscribe( |
116 | () => { | 119 | () => { |
117 | this.notificationsService.success('Success', 'Video updated.'); | 120 | this.notificationsService.success('Success', 'Video updated.') |
118 | this.router.navigate([ '/videos/watch', this.video.id ]); | 121 | this.router.navigate([ '/videos/watch', this.video.id ]) |
119 | }, | 122 | }, |
120 | 123 | ||
121 | err => { | 124 | err => { |
122 | this.error = 'Cannot update the video.'; | 125 | this.error = 'Cannot update the video.' |
123 | console.error(err); | 126 | console.error(err) |
124 | } | 127 | } |
125 | ); | 128 | ) |
126 | 129 | ||
127 | } | 130 | } |
128 | 131 | ||
129 | private hydrateFormFromVideo() { | 132 | private hydrateFormFromVideo () { |
130 | this.form.patchValue(this.video.toJSON()); | 133 | this.form.patchValue(this.video.toJSON()) |
131 | } | 134 | } |
132 | } | 135 | } |