1 import { Component, OnInit } from '@angular/core'
2 import { Router } from '@angular/router'
3 import { AuthService, Notifier, ServerService } from '@app/core'
4 import { populateAsyncUserVideoChannels } from '@app/helpers'
6 setPlaylistChannelValidator,
7 VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR,
8 VIDEO_PLAYLIST_DESCRIPTION_VALIDATOR,
9 VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR,
10 VIDEO_PLAYLIST_PRIVACY_VALIDATOR
11 } from '@app/shared/form-validators/video-playlist-validators'
12 import { FormValidatorService } from '@app/shared/shared-forms'
13 import { VideoPlaylistService } from '@app/shared/shared-video-playlist'
14 import { VideoPlaylistCreate } from '@shared/models/videos/playlist/video-playlist-create.model'
15 import { VideoPlaylistPrivacy } from '@shared/models/videos/playlist/video-playlist-privacy.model'
16 import { MyAccountVideoPlaylistEdit } from './my-account-video-playlist-edit'
19 selector: 'my-account-video-playlist-create',
20 templateUrl: './my-account-video-playlist-edit.component.html',
21 styleUrls: [ './my-account-video-playlist-edit.component.scss' ]
23 export class MyAccountVideoPlaylistCreateComponent extends MyAccountVideoPlaylistEdit implements OnInit {
27 protected formValidatorService: FormValidatorService,
28 private authService: AuthService,
29 private notifier: Notifier,
30 private router: Router,
31 private videoPlaylistService: VideoPlaylistService,
32 private serverService: ServerService
39 displayName: VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR,
40 privacy: VIDEO_PLAYLIST_PRIVACY_VALIDATOR,
41 description: VIDEO_PLAYLIST_DESCRIPTION_VALIDATOR,
42 videoChannelId: VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR,
46 this.form.get('privacy').valueChanges.subscribe(privacy => {
47 setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy)
50 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
51 .catch(err => console.error('Cannot populate user video channels.', err))
53 this.serverService.getVideoPlaylistPrivacies()
54 .subscribe(videoPlaylistPrivacies => {
55 this.videoPlaylistPrivacies = videoPlaylistPrivacies
57 this.form.patchValue({
58 privacy: VideoPlaylistPrivacy.PRIVATE
64 this.error = undefined
66 const body = this.form.value
67 const videoPlaylistCreate: VideoPlaylistCreate = {
68 displayName: body.displayName,
69 privacy: body.privacy,
70 description: body.description || null,
71 videoChannelId: body.videoChannelId || null,
72 thumbnailfile: body.thumbnailfile || null
75 this.videoPlaylistService.createVideoPlaylist(videoPlaylistCreate).subscribe(
77 this.notifier.success($localize`Playlist ${videoPlaylistCreate.displayName} created.`)
78 this.router.navigate([ '/my-account', 'video-playlists' ])
81 err => this.error = err.message
89 getFormButtonTitle () {
90 return $localize`Create`