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'
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' ]
17 export class MyAccountVideoPlaylistCreateComponent extends MyAccountVideoPlaylistEdit implements OnInit {
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,
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,
42 this.form.get('privacy').valueChanges.subscribe(privacy => {
43 this.videoPlaylistValidatorsService.setChannelValidator(this.form.get('videoChannelId'), privacy)
46 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
47 .catch(err => console.error('Cannot populate user video channels.', err))
49 this.serverService.getVideoPlaylistPrivacies()
50 .subscribe(videoPlaylistPrivacies => {
51 this.videoPlaylistPrivacies = videoPlaylistPrivacies
53 this.form.patchValue({
54 privacy: VideoPlaylistPrivacy.PRIVATE
60 this.error = undefined
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
71 this.videoPlaylistService.createVideoPlaylist(videoPlaylistCreate).subscribe(
73 this.notifier.success(
74 this.i18n('Playlist {{playlistName}} created.', { playlistName: videoPlaylistCreate.displayName })
76 this.router.navigate([ '/my-account', 'video-playlists' ])
79 err => this.error = err.message
87 getFormButtonTitle () {
88 return this.i18n('Create')