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/video-update.component.ts | |
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/video-update.component.ts')
-rw-r--r-- | client/src/app/videos/video-edit/video-update.component.ts | 99 |
1 files changed, 51 insertions, 48 deletions
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 | } |