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