]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-video-channels/my-account-video-channel-update.component.ts
Server: Bulk update videos support field
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-video-channels / my-account-video-channel-update.component.ts
CommitLineData
c199c427 1import { Component, OnDestroy, OnInit } from '@angular/core'
08c1efbe 2import { ActivatedRoute, Router } from '@angular/router'
f8b2c1b4 3import { AuthService, Notifier, ServerService } from '@app/core'
08c1efbe 4import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit'
08c1efbe 5import { VideoChannelUpdate } from '../../../../../shared/models/videos'
08c1efbe 6import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
db400f44 7import { Subscription } from 'rxjs'
08c1efbe 8import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
b1d40cff 9import { I18n } from '@ngx-translate/i18n-polyfill'
d18d6478 10import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
e309822b 11import { VideoChannelValidatorsService } from '@app/shared/forms/form-validators/video-channel-validators.service'
08c1efbe
C
12
13@Component({
14 selector: 'my-account-video-channel-update',
15 templateUrl: './my-account-video-channel-edit.component.html',
16 styleUrls: [ './my-account-video-channel-edit.component.scss' ]
17})
18export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelEdit implements OnInit, OnDestroy {
19 error: string
e1807a94 20 videoChannelToUpdate: VideoChannel
c199c427 21
08c1efbe
C
22 private paramsSub: Subscription
23
24 constructor (
d18d6478 25 protected formValidatorService: FormValidatorService,
95166f9a 26 private authService: AuthService,
e309822b 27 private videoChannelValidatorsService: VideoChannelValidatorsService,
f8b2c1b4 28 private notifier: Notifier,
08c1efbe
C
29 private router: Router,
30 private route: ActivatedRoute,
b1d40cff 31 private videoChannelService: VideoChannelService,
52d9f792
C
32 private i18n: I18n,
33 private serverService: ServerService
08c1efbe
C
34 ) {
35 super()
36 }
37
08c1efbe 38 ngOnInit () {
d18d6478 39 this.buildForm({
e309822b
C
40 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
41 description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION,
42 support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT
d18d6478 43 })
08c1efbe
C
44
45 this.paramsSub = this.route.params.subscribe(routeParams => {
46 const videoChannelId = routeParams['videoChannelId']
47
48 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
49 videoChannelToUpdate => {
50 this.videoChannelToUpdate = videoChannelToUpdate
51
52 this.form.patchValue({
53 'display-name': videoChannelToUpdate.displayName,
54 description: videoChannelToUpdate.description,
55 support: videoChannelToUpdate.support
56 })
57 },
58
59 err => this.error = err.message
60 )
61 })
62 }
63
64 ngOnDestroy () {
65 if (this.paramsSub) this.paramsSub.unsubscribe()
66 }
67
68 formValidated () {
69 this.error = undefined
70
71 const body = this.form.value
72 const videoChannelUpdate: VideoChannelUpdate = {
73 displayName: body['display-name'],
360329cc
C
74 description: body.description || null,
75 support: body.support || null
08c1efbe
C
76 }
77
22a16e36 78 this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.name, videoChannelUpdate).subscribe(
08c1efbe 79 () => {
95166f9a 80 this.authService.refreshUserInformation()
f8b2c1b4
C
81
82 this.notifier.success(
25acef90 83 this.i18n('Video channel {{videoChannelName}} updated.', { videoChannelName: videoChannelUpdate.displayName })
b1d40cff 84 )
f8b2c1b4 85
08c1efbe
C
86 this.router.navigate([ '/my-account', 'video-channels' ])
87 },
88
89 err => this.error = err.message
90 )
91 }
92
52d9f792 93 onAvatarChange (formData: FormData) {
22a16e36 94 this.videoChannelService.changeVideoChannelAvatar(this.videoChannelToUpdate.name, formData)
52d9f792
C
95 .subscribe(
96 data => {
f8b2c1b4 97 this.notifier.success(this.i18n('Avatar changed.'))
52d9f792
C
98
99 this.videoChannelToUpdate.updateAvatar(data.avatar)
100 },
101
f8b2c1b4 102 err => this.notifier.error(err.message)
52d9f792
C
103 )
104 }
105
106 get maxAvatarSize () {
107 return this.serverService.getConfig().avatar.file.size.max
108 }
109
110 get avatarExtensions () {
111 return this.serverService.getConfig().avatar.file.extensions.join(',')
112 }
113
08c1efbe
C
114 isCreation () {
115 return false
116 }
117
118 getFormButtonTitle () {
b1d40cff 119 return this.i18n('Update')
08c1efbe
C
120 }
121}