allow limiting video-comments rss feeds to an account or video channel
[oweals/peertube.git] / client / src / app / +my-account / my-account-video-playlists / my-account-video-playlist-create.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { Router } from '@angular/router'
3 import { AuthService, Notifier, ServerService } from '@app/core'
4 import { FormValidatorService, VideoPlaylistValidatorsService } from '@app/shared/shared-forms'
5 import { VideoPlaylistService } from '@app/shared/shared-video-playlist'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
7 import { VideoPlaylistCreate } from '@shared/models/videos/playlist/video-playlist-create.model'
8 import { VideoPlaylistPrivacy } from '@shared/models/videos/playlist/video-playlist-privacy.model'
9 import { MyAccountVideoPlaylistEdit } from './my-account-video-playlist-edit'
10 import { populateAsyncUserVideoChannels } from '@app/helpers'
11
12 @Component({
13   selector: 'my-account-video-playlist-create',
14   templateUrl: './my-account-video-playlist-edit.component.html',
15   styleUrls: [ './my-account-video-playlist-edit.component.scss' ]
16 })
17 export class MyAccountVideoPlaylistCreateComponent extends MyAccountVideoPlaylistEdit implements OnInit {
18   error: string
19
20   constructor (
21     protected formValidatorService: FormValidatorService,
22     private authService: AuthService,
23     private videoPlaylistValidatorsService: VideoPlaylistValidatorsService,
24     private notifier: Notifier,
25     private router: Router,
26     private videoPlaylistService: VideoPlaylistService,
27     private serverService: ServerService,
28     private i18n: I18n
29   ) {
30     super()
31   }
32
33   ngOnInit () {
34     this.buildForm({
35       displayName: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME,
36       privacy: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_PRIVACY,
37       description: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DESCRIPTION,
38       videoChannelId: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_CHANNEL_ID,
39       thumbnailfile: null
40     })
41
42     this.form.get('privacy').valueChanges.subscribe(privacy => {
43       this.videoPlaylistValidatorsService.setChannelValidator(this.form.get('videoChannelId'), privacy)
44     })
45
46     populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
47       .catch(err => console.error('Cannot populate user video channels.', err))
48
49     this.serverService.getVideoPlaylistPrivacies()
50         .subscribe(videoPlaylistPrivacies => {
51           this.videoPlaylistPrivacies = videoPlaylistPrivacies
52
53           this.form.patchValue({
54             privacy: VideoPlaylistPrivacy.PRIVATE
55           })
56         })
57   }
58
59   formValidated () {
60     this.error = undefined
61
62     const body = this.form.value
63     const videoPlaylistCreate: VideoPlaylistCreate = {
64       displayName: body.displayName,
65       privacy: body.privacy,
66       description: body.description || null,
67       videoChannelId: body.videoChannelId || null,
68       thumbnailfile: body.thumbnailfile || null
69     }
70
71     this.videoPlaylistService.createVideoPlaylist(videoPlaylistCreate).subscribe(
72       () => {
73         this.notifier.success(
74           this.i18n('Playlist {{playlistName}} created.', { playlistName: videoPlaylistCreate.displayName })
75         )
76         this.router.navigate([ '/my-account', 'video-playlists' ])
77       },
78
79       err => this.error = err.message
80     )
81   }
82
83   isCreation () {
84     return true
85   }
86
87   getFormButtonTitle () {
88     return this.i18n('Create')
89   }
90 }