]> 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
Add commentor name alongside fid for video comments
[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 22 private paramsSub: Subscription
1e66b987 23 private oldSupportField: string
08c1efbe
C
24
25 constructor (
d18d6478 26 protected formValidatorService: FormValidatorService,
95166f9a 27 private authService: AuthService,
e309822b 28 private videoChannelValidatorsService: VideoChannelValidatorsService,
f8b2c1b4 29 private notifier: Notifier,
08c1efbe
C
30 private router: Router,
31 private route: ActivatedRoute,
b1d40cff 32 private videoChannelService: VideoChannelService,
52d9f792
C
33 private i18n: I18n,
34 private serverService: ServerService
08c1efbe
C
35 ) {
36 super()
37 }
38
08c1efbe 39 ngOnInit () {
d18d6478 40 this.buildForm({
e309822b
C
41 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
42 description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION,
1e66b987
C
43 support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT,
44 bulkVideosSupportUpdate: null
d18d6478 45 })
08c1efbe
C
46
47 this.paramsSub = this.route.params.subscribe(routeParams => {
48 const videoChannelId = routeParams['videoChannelId']
49
50 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
51 videoChannelToUpdate => {
52 this.videoChannelToUpdate = videoChannelToUpdate
53
1e66b987
C
54 this.oldSupportField = videoChannelToUpdate.support
55
08c1efbe
C
56 this.form.patchValue({
57 'display-name': videoChannelToUpdate.displayName,
58 description: videoChannelToUpdate.description,
59 support: videoChannelToUpdate.support
60 })
61 },
62
63 err => this.error = err.message
64 )
65 })
66 }
67
68 ngOnDestroy () {
69 if (this.paramsSub) this.paramsSub.unsubscribe()
70 }
71
72 formValidated () {
73 this.error = undefined
74
75 const body = this.form.value
76 const videoChannelUpdate: VideoChannelUpdate = {
77 displayName: body['display-name'],
360329cc 78 description: body.description || null,
1e66b987
C
79 support: body.support || null,
80 bulkVideosSupportUpdate: body.bulkVideosSupportUpdate || false
08c1efbe
C
81 }
82
22a16e36 83 this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.name, videoChannelUpdate).subscribe(
08c1efbe 84 () => {
95166f9a 85 this.authService.refreshUserInformation()
f8b2c1b4
C
86
87 this.notifier.success(
25acef90 88 this.i18n('Video channel {{videoChannelName}} updated.', { videoChannelName: videoChannelUpdate.displayName })
b1d40cff 89 )
f8b2c1b4 90
08c1efbe
C
91 this.router.navigate([ '/my-account', 'video-channels' ])
92 },
93
94 err => this.error = err.message
95 )
96 }
97
52d9f792 98 onAvatarChange (formData: FormData) {
22a16e36 99 this.videoChannelService.changeVideoChannelAvatar(this.videoChannelToUpdate.name, formData)
52d9f792
C
100 .subscribe(
101 data => {
f8b2c1b4 102 this.notifier.success(this.i18n('Avatar changed.'))
52d9f792
C
103
104 this.videoChannelToUpdate.updateAvatar(data.avatar)
105 },
106
f8b2c1b4 107 err => this.notifier.error(err.message)
52d9f792
C
108 )
109 }
110
111 get maxAvatarSize () {
112 return this.serverService.getConfig().avatar.file.size.max
113 }
114
115 get avatarExtensions () {
116 return this.serverService.getConfig().avatar.file.extensions.join(',')
117 }
118
08c1efbe
C
119 isCreation () {
120 return false
121 }
122
123 getFormButtonTitle () {
b1d40cff 124 return this.i18n('Update')
08c1efbe 125 }
1e66b987
C
126
127 isBulkUpdateVideosDisplayed () {
128 if (this.oldSupportField === undefined) return false
129
130 return this.oldSupportField !== this.form.value['support']
131 }
08c1efbe 132}