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-create.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-create.component.ts')
-rw-r--r-- | client/src/app/my-account/my-account-video-channels/my-account-video-channel-create.component.ts | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/client/src/app/my-account/my-account-video-channels/my-account-video-channel-create.component.ts b/client/src/app/my-account/my-account-video-channels/my-account-video-channel-create.component.ts new file mode 100644 index 000000000..3cfe74752 --- /dev/null +++ b/client/src/app/my-account/my-account-video-channels/my-account-video-channel-create.component.ts | |||
@@ -0,0 +1,86 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | ||
2 | import { 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 { VideoChannelCreate } 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 | |||
16 | @Component({ | ||
17 | selector: 'my-account-video-channel-create', | ||
18 | templateUrl: './my-account-video-channel-edit.component.html', | ||
19 | styleUrls: [ './my-account-video-channel-edit.component.scss' ] | ||
20 | }) | ||
21 | export class MyAccountVideoChannelCreateComponent extends MyAccountVideoChannelEdit implements OnInit { | ||
22 | error: string | ||
23 | |||
24 | form: FormGroup | ||
25 | formErrors = { | ||
26 | 'display-name': '', | ||
27 | 'description': '', | ||
28 | 'support': '' | ||
29 | } | ||
30 | validationMessages = { | ||
31 | 'display-name': VIDEO_CHANNEL_DISPLAY_NAME.MESSAGES, | ||
32 | 'description': VIDEO_CHANNEL_DESCRIPTION.MESSAGES, | ||
33 | 'support': VIDEO_CHANNEL_SUPPORT.MESSAGES | ||
34 | } | ||
35 | |||
36 | constructor ( | ||
37 | private notificationsService: NotificationsService, | ||
38 | private router: Router, | ||
39 | private formBuilder: FormBuilder, | ||
40 | private videoChannelService: VideoChannelService | ||
41 | ) { | ||
42 | super() | ||
43 | } | ||
44 | |||
45 | buildForm () { | ||
46 | this.form = this.formBuilder.group({ | ||
47 | 'display-name': [ '', VIDEO_CHANNEL_DISPLAY_NAME.VALIDATORS ], | ||
48 | description: [ '', VIDEO_CHANNEL_DESCRIPTION.VALIDATORS ], | ||
49 | support: [ '', VIDEO_CHANNEL_SUPPORT.VALIDATORS ] | ||
50 | }) | ||
51 | |||
52 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
53 | } | ||
54 | |||
55 | ngOnInit () { | ||
56 | this.buildForm() | ||
57 | } | ||
58 | |||
59 | formValidated () { | ||
60 | this.error = undefined | ||
61 | |||
62 | const body = this.form.value | ||
63 | const videoChannelCreate: VideoChannelCreate = { | ||
64 | displayName: body['display-name'], | ||
65 | description: body.description, | ||
66 | support: body.support | ||
67 | } | ||
68 | |||
69 | this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe( | ||
70 | () => { | ||
71 | this.notificationsService.success('Success', `Video channel ${videoChannelCreate.displayName} created.`) | ||
72 | this.router.navigate([ '/my-account', 'video-channels' ]) | ||
73 | }, | ||
74 | |||
75 | err => this.error = err.message | ||
76 | ) | ||
77 | } | ||
78 | |||
79 | isCreation () { | ||
80 | return true | ||
81 | } | ||
82 | |||
83 | getFormButtonTitle () { | ||
84 | return 'Create this video channel' | ||
85 | } | ||
86 | } | ||