diff options
author | Chocobozzz <me@florianbigard.com> | 2018-04-26 16:11:38 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-04-26 16:18:01 +0200 |
commit | 08c1efbe32244c321de28b0f2a6aaa3f99f46b58 (patch) | |
tree | 10a1b6c12f3e30a20f3d0dd66c698d9bae2aa41f /client/src/app/my-account/my-account-video-channels/my-account-video-channel-update.component.ts | |
parent | 7de6afdf542da6968d3f412df9c3318ba19ad229 (diff) | |
download | PeerTube-08c1efbe32244c321de28b0f2a6aaa3f99f46b58.tar.gz PeerTube-08c1efbe32244c321de28b0f2a6aaa3f99f46b58.tar.zst PeerTube-08c1efbe32244c321de28b0f2a6aaa3f99f46b58.zip |
Add video channel management
Diffstat (limited to 'client/src/app/my-account/my-account-video-channels/my-account-video-channel-update.component.ts')
-rw-r--r-- | client/src/app/my-account/my-account-video-channels/my-account-video-channel-update.component.ts | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/client/src/app/my-account/my-account-video-channels/my-account-video-channel-update.component.ts b/client/src/app/my-account/my-account-video-channels/my-account-video-channel-update.component.ts new file mode 100644 index 000000000..2b8415938 --- /dev/null +++ b/client/src/app/my-account/my-account-video-channels/my-account-video-channel-update.component.ts | |||
@@ -0,0 +1,116 @@ | |||
1 | import { Component, OnInit, OnDestroy } from '@angular/core' | ||
2 | import { ActivatedRoute, Router } from '@angular/router' | ||
3 | import { NotificationsService } from 'angular2-notifications' | ||
4 | import 'rxjs/add/observable/from' | ||
5 | import 'rxjs/add/operator/concatAll' | ||
6 | import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit' | ||
7 | import { FormBuilder, FormGroup } from '@angular/forms' | ||
8 | import { VideoChannelUpdate } from '../../../../../shared/models/videos' | ||
9 | import { | ||
10 | VIDEO_CHANNEL_DESCRIPTION, | ||
11 | VIDEO_CHANNEL_DISPLAY_NAME, | ||
12 | VIDEO_CHANNEL_SUPPORT | ||
13 | } from '@app/shared/forms/form-validators/video-channel' | ||
14 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' | ||
15 | import { Subscription } from 'rxjs/Subscription' | ||
16 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | ||
17 | |||
18 | @Component({ | ||
19 | selector: 'my-account-video-channel-update', | ||
20 | templateUrl: './my-account-video-channel-edit.component.html', | ||
21 | styleUrls: [ './my-account-video-channel-edit.component.scss' ] | ||
22 | }) | ||
23 | export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelEdit implements OnInit, OnDestroy { | ||
24 | error: string | ||
25 | |||
26 | form: FormGroup | ||
27 | formErrors = { | ||
28 | 'display-name': '', | ||
29 | 'description': '', | ||
30 | 'support': '' | ||
31 | } | ||
32 | validationMessages = { | ||
33 | 'display-name': VIDEO_CHANNEL_DISPLAY_NAME.MESSAGES, | ||
34 | 'description': VIDEO_CHANNEL_DESCRIPTION.MESSAGES, | ||
35 | 'support': VIDEO_CHANNEL_SUPPORT.MESSAGES | ||
36 | } | ||
37 | |||
38 | private videoChannelToUpdate: VideoChannel | ||
39 | private paramsSub: Subscription | ||
40 | |||
41 | constructor ( | ||
42 | private notificationsService: NotificationsService, | ||
43 | private router: Router, | ||
44 | private route: ActivatedRoute, | ||
45 | private formBuilder: FormBuilder, | ||
46 | private videoChannelService: VideoChannelService | ||
47 | ) { | ||
48 | super() | ||
49 | } | ||
50 | |||
51 | buildForm () { | ||
52 | this.form = this.formBuilder.group({ | ||
53 | 'display-name': [ '', VIDEO_CHANNEL_DISPLAY_NAME.VALIDATORS ], | ||
54 | description: [ '', VIDEO_CHANNEL_DESCRIPTION.VALIDATORS ], | ||
55 | support: [ '', VIDEO_CHANNEL_SUPPORT.VALIDATORS ] | ||
56 | }) | ||
57 | |||
58 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
59 | } | ||
60 | |||
61 | ngOnInit () { | ||
62 | this.buildForm() | ||
63 | |||
64 | this.paramsSub = this.route.params.subscribe(routeParams => { | ||
65 | const videoChannelId = routeParams['videoChannelId'] | ||
66 | |||
67 | this.videoChannelService.getVideoChannel(videoChannelId).subscribe( | ||
68 | videoChannelToUpdate => { | ||
69 | this.videoChannelToUpdate = videoChannelToUpdate | ||
70 | |||
71 | this.form.patchValue({ | ||
72 | 'display-name': videoChannelToUpdate.displayName, | ||
73 | description: videoChannelToUpdate.description, | ||
74 | support: videoChannelToUpdate.support | ||
75 | }) | ||
76 | }, | ||
77 | |||
78 | err => this.error = err.message | ||
79 | ) | ||
80 | }) | ||
81 | } | ||
82 | |||
83 | ngOnDestroy () { | ||
84 | if (this.paramsSub) this.paramsSub.unsubscribe() | ||
85 | } | ||
86 | |||
87 | formValidated () { | ||
88 | this.error = undefined | ||
89 | |||
90 | const body = this.form.value | ||
91 | const videoChannelUpdate: VideoChannelUpdate = { | ||
92 | displayName: body['display-name'], | ||
93 | description: body.description, | ||
94 | support: body.support | ||
95 | } | ||
96 | |||
97 | this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.uuid, videoChannelUpdate).subscribe( | ||
98 | () => { | ||
99 | this.notificationsService.success('Success', `Video channel ${videoChannelUpdate.displayName} updated.`) | ||
100 | this.router.navigate([ '/my-account', 'video-channels' ]) | ||
101 | }, | ||
102 | |||
103 | err => this.error = err.message | ||
104 | ) | ||
105 | } | ||
106 | |||
107 | isCreation () { | ||
108 | return false | ||
109 | } | ||
110 | |||
111 | getFormButtonTitle () { | ||
112 | return this.videoChannelToUpdate | ||
113 | ? 'Update ' + this.videoChannelToUpdate.displayName + ' video channel' | ||
114 | : 'Update' | ||
115 | } | ||
116 | } | ||