]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-library/+my-video-channels/my-video-channel-update.component.ts
chore: add manifest in light build
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / +my-video-channels / my-video-channel-update.component.ts
CommitLineData
67ed6552 1import { Subscription } from 'rxjs'
c199c427 2import { Component, OnDestroy, OnInit } from '@angular/core'
08c1efbe 3import { ActivatedRoute, Router } from '@angular/router'
f8b2c1b4 4import { AuthService, Notifier, ServerService } from '@app/core'
7ed1edbb
C
5import {
6 VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
7 VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
8 VIDEO_CHANNEL_SUPPORT_VALIDATOR
9} from '@app/shared/form-validators/video-channel-validators'
10import { FormValidatorService } from '@app/shared/shared-forms'
67ed6552 11import { VideoChannel, VideoChannelService } from '@app/shared/shared-main'
67ed6552 12import { ServerConfig, VideoChannelUpdate } from '@shared/models'
17119e4a 13import { MyVideoChannelEdit } from './my-video-channel-edit'
08c1efbe
C
14
15@Component({
17119e4a
C
16 selector: 'my-video-channel-update',
17 templateUrl: './my-video-channel-edit.component.html',
18 styleUrls: [ './my-video-channel-edit.component.scss' ]
08c1efbe 19})
17119e4a 20export class MyVideoChannelUpdateComponent extends MyVideoChannelEdit implements OnInit, OnDestroy {
08c1efbe 21 error: string
e1807a94 22 videoChannelToUpdate: VideoChannel
c199c427 23
08c1efbe 24 private paramsSub: Subscription
1e66b987 25 private oldSupportField: string
ba430d75 26 private serverConfig: ServerConfig
08c1efbe
C
27
28 constructor (
d18d6478 29 protected formValidatorService: FormValidatorService,
95166f9a 30 private authService: AuthService,
f8b2c1b4 31 private notifier: Notifier,
08c1efbe
C
32 private router: Router,
33 private route: ActivatedRoute,
b1d40cff 34 private videoChannelService: VideoChannelService,
52d9f792 35 private serverService: ServerService
08c1efbe
C
36 ) {
37 super()
38 }
39
08c1efbe 40 ngOnInit () {
ba430d75
C
41 this.serverConfig = this.serverService.getTmpConfig()
42 this.serverService.getConfig()
43 .subscribe(config => this.serverConfig = config)
44
d18d6478 45 this.buildForm({
7ed1edbb
C
46 'display-name': VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
47 description: VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
48 support: VIDEO_CHANNEL_SUPPORT_VALIDATOR,
1e66b987 49 bulkVideosSupportUpdate: null
d18d6478 50 })
08c1efbe
C
51
52 this.paramsSub = this.route.params.subscribe(routeParams => {
53 const videoChannelId = routeParams['videoChannelId']
54
55 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
56 videoChannelToUpdate => {
57 this.videoChannelToUpdate = videoChannelToUpdate
58
1e66b987
C
59 this.oldSupportField = videoChannelToUpdate.support
60
08c1efbe
C
61 this.form.patchValue({
62 'display-name': videoChannelToUpdate.displayName,
63 description: videoChannelToUpdate.description,
64 support: videoChannelToUpdate.support
65 })
66 },
67
68 err => this.error = err.message
69 )
70 })
71 }
72
73 ngOnDestroy () {
74 if (this.paramsSub) this.paramsSub.unsubscribe()
75 }
76
77 formValidated () {
78 this.error = undefined
79
80 const body = this.form.value
81 const videoChannelUpdate: VideoChannelUpdate = {
82 displayName: body['display-name'],
360329cc 83 description: body.description || null,
1e66b987
C
84 support: body.support || null,
85 bulkVideosSupportUpdate: body.bulkVideosSupportUpdate || false
08c1efbe
C
86 }
87
22a16e36 88 this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.name, videoChannelUpdate).subscribe(
08c1efbe 89 () => {
95166f9a 90 this.authService.refreshUserInformation()
f8b2c1b4 91
66357162 92 this.notifier.success($localize`Video channel ${videoChannelUpdate.displayName} updated.`)
f8b2c1b4 93
17119e4a 94 this.router.navigate([ '/my-library', 'video-channels' ])
08c1efbe
C
95 },
96
97 err => this.error = err.message
98 )
99 }
100
52d9f792 101 onAvatarChange (formData: FormData) {
22a16e36 102 this.videoChannelService.changeVideoChannelAvatar(this.videoChannelToUpdate.name, formData)
52d9f792
C
103 .subscribe(
104 data => {
66357162 105 this.notifier.success($localize`Avatar changed.`)
52d9f792
C
106
107 this.videoChannelToUpdate.updateAvatar(data.avatar)
108 },
109
f8b2c1b4 110 err => this.notifier.error(err.message)
52d9f792
C
111 )
112 }
113
114 get maxAvatarSize () {
ba430d75 115 return this.serverConfig.avatar.file.size.max
52d9f792
C
116 }
117
118 get avatarExtensions () {
ba430d75 119 return this.serverConfig.avatar.file.extensions.join(',')
52d9f792
C
120 }
121
08c1efbe
C
122 isCreation () {
123 return false
124 }
125
126 getFormButtonTitle () {
66357162 127 return $localize`Update`
08c1efbe 128 }
1e66b987
C
129
130 isBulkUpdateVideosDisplayed () {
131 if (this.oldSupportField === undefined) return false
132
133 return this.oldSupportField !== this.form.value['support']
134 }
08c1efbe 135}