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