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