]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts
Merge remote-tracking branch 'weblate/develop' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / my-video-playlists / my-video-playlist-create.component.ts
CommitLineData
830b4faf
C
1import { Component, OnInit } from '@angular/core'
2import { Router } from '@angular/router'
3import { AuthService, Notifier, ServerService } from '@app/core'
9556ce48 4import { listUserChannels } from '@app/helpers'
7ed1edbb
C
5import {
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'
12import { FormValidatorService } from '@app/shared/shared-forms'
67ed6552 13import { VideoPlaylistService } from '@app/shared/shared-video-playlist'
830b4faf 14import { VideoPlaylistCreate } from '@shared/models/videos/playlist/video-playlist-create.model'
830b4faf 15import { VideoPlaylistPrivacy } from '@shared/models/videos/playlist/video-playlist-privacy.model'
17119e4a 16import { MyVideoPlaylistEdit } from './my-video-playlist-edit'
830b4faf
C
17
18@Component({
17119e4a
C
19 templateUrl: './my-video-playlist-edit.component.html',
20 styleUrls: [ './my-video-playlist-edit.component.scss' ]
830b4faf 21})
17119e4a 22export class MyVideoPlaylistCreateComponent extends MyVideoPlaylistEdit implements OnInit {
830b4faf 23 error: string
830b4faf
C
24
25 constructor (
26 protected formValidatorService: FormValidatorService,
27 private authService: AuthService,
830b4faf
C
28 private notifier: Notifier,
29 private router: Router,
30 private videoPlaylistService: VideoPlaylistService,
66357162 31 private serverService: ServerService
9df52d66 32 ) {
830b4faf
C
33 super()
34 }
35
36 ngOnInit () {
37 this.buildForm({
7ed1edbb
C
38 displayName: VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR,
39 privacy: VIDEO_PLAYLIST_PRIVACY_VALIDATOR,
40 description: VIDEO_PLAYLIST_DESCRIPTION_VALIDATOR,
41 videoChannelId: VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR,
830b4faf
C
42 thumbnailfile: null
43 })
44
978c9d49 45 this.form.get('privacy').valueChanges.subscribe(privacy => {
7ed1edbb 46 setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy)
978c9d49
C
47 })
48
9556ce48
C
49 listUserChannels(this.authService)
50 .subscribe(channels => this.userVideoChannels = channels)
830b4faf 51
ba430d75
C
52 this.serverService.getVideoPlaylistPrivacies()
53 .subscribe(videoPlaylistPrivacies => {
54 this.videoPlaylistPrivacies = videoPlaylistPrivacies
830b4faf 55
ba430d75
C
56 this.form.patchValue({
57 privacy: VideoPlaylistPrivacy.PRIVATE
58 })
830b4faf 59 })
830b4faf
C
60 }
61
62 formValidated () {
63 this.error = undefined
64
65 const body = this.form.value
66 const videoPlaylistCreate: VideoPlaylistCreate = {
978c9d49 67 displayName: body.displayName,
830b4faf
C
68 privacy: body.privacy,
69 description: body.description || null,
70 videoChannelId: body.videoChannelId || null,
71 thumbnailfile: body.thumbnailfile || null
72 }
73
1378c0d3
C
74 this.videoPlaylistService.createVideoPlaylist(videoPlaylistCreate)
75 .subscribe({
76 next: () => {
77 this.notifier.success($localize`Playlist ${videoPlaylistCreate.displayName} created.`)
78 this.router.navigate([ '/my-library', 'video-playlists' ])
79 },
830b4faf 80
9df52d66
C
81 error: err => {
82 this.error = err.message
83 }
1378c0d3 84 })
830b4faf
C
85 }
86
87 isCreation () {
88 return true
89 }
90
91 getFormButtonTitle () {
66357162 92 return $localize`Create`
830b4faf
C
93 }
94}