]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts
fix CONTRIBUTING.md command order (#3305)
[github/Chocobozzz/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 { populateAsyncUserVideoChannels } from '@app/helpers'
5 import {
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'
17
18 @Component({
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' ]
22 })
23 export class MyAccountVideoPlaylistCreateComponent extends MyAccountVideoPlaylistEdit implements OnInit {
24 error: string
25
26 constructor (
27 protected formValidatorService: FormValidatorService,
28 private authService: AuthService,
29 private notifier: Notifier,
30 private router: Router,
31 private videoPlaylistService: VideoPlaylistService,
32 private serverService: ServerService
33 ) {
34 super()
35 }
36
37 ngOnInit () {
38 this.buildForm({
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,
43 thumbnailfile: null
44 })
45
46 this.form.get('privacy').valueChanges.subscribe(privacy => {
47 setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy)
48 })
49
50 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
51 .catch(err => console.error('Cannot populate user video channels.', err))
52
53 this.serverService.getVideoPlaylistPrivacies()
54 .subscribe(videoPlaylistPrivacies => {
55 this.videoPlaylistPrivacies = videoPlaylistPrivacies
56
57 this.form.patchValue({
58 privacy: VideoPlaylistPrivacy.PRIVATE
59 })
60 })
61 }
62
63 formValidated () {
64 this.error = undefined
65
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
73 }
74
75 this.videoPlaylistService.createVideoPlaylist(videoPlaylistCreate).subscribe(
76 () => {
77 this.notifier.success($localize`Playlist ${videoPlaylistCreate.displayName} created.`)
78 this.router.navigate([ '/my-account', 'video-playlists' ])
79 },
80
81 err => this.error = err.message
82 )
83 }
84
85 isCreation () {
86 return true
87 }
88
89 getFormButtonTitle () {
90 return $localize`Create`
91 }
92 }