]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-library/+my-video-channels/my-video-channel-update.component.ts
Resumable video uploads (#3933)
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / +my-video-channels / my-video-channel-update.component.ts
CommitLineData
67ed6552 1import { Subscription } from 'rxjs'
cdeddff1 2import { HttpErrorResponse } from '@angular/common/http'
c199c427 3import { Component, OnDestroy, OnInit } from '@angular/core'
08c1efbe 4import { ActivatedRoute, Router } from '@angular/router'
f8b2c1b4 5import { AuthService, Notifier, ServerService } from '@app/core'
f6d6e7f8 6import { genericUploadErrorHandler } from '@app/helpers'
7ed1edbb
C
7import {
8 VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
9 VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
10 VIDEO_CHANNEL_SUPPORT_VALIDATOR
11} from '@app/shared/form-validators/video-channel-validators'
12import { FormValidatorService } from '@app/shared/shared-forms'
67ed6552 13import { VideoChannel, VideoChannelService } from '@app/shared/shared-main'
67ed6552 14import { ServerConfig, VideoChannelUpdate } from '@shared/models'
17119e4a 15import { MyVideoChannelEdit } from './my-video-channel-edit'
08c1efbe
C
16
17@Component({
17119e4a
C
18 selector: 'my-video-channel-update',
19 templateUrl: './my-video-channel-edit.component.html',
20 styleUrls: [ './my-video-channel-edit.component.scss' ]
08c1efbe 21})
17119e4a 22export class MyVideoChannelUpdateComponent extends MyVideoChannelEdit implements OnInit, OnDestroy {
08c1efbe 23 error: string
27ec473f 24 videoChannel: VideoChannel
c199c427 25
08c1efbe 26 private paramsSub: Subscription
1e66b987 27 private oldSupportField: string
ba430d75 28 private serverConfig: ServerConfig
08c1efbe
C
29
30 constructor (
d18d6478 31 protected formValidatorService: FormValidatorService,
95166f9a 32 private authService: AuthService,
f8b2c1b4 33 private notifier: Notifier,
08c1efbe
C
34 private router: Router,
35 private route: ActivatedRoute,
b1d40cff 36 private videoChannelService: VideoChannelService,
52d9f792 37 private serverService: ServerService
08c1efbe
C
38 ) {
39 super()
40 }
41
08c1efbe 42 ngOnInit () {
ba430d75
C
43 this.serverConfig = this.serverService.getTmpConfig()
44 this.serverService.getConfig()
45 .subscribe(config => this.serverConfig = config)
46
d18d6478 47 this.buildForm({
7ed1edbb
C
48 'display-name': VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
49 description: VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
50 support: VIDEO_CHANNEL_SUPPORT_VALIDATOR,
1e66b987 51 bulkVideosSupportUpdate: null
d18d6478 52 })
08c1efbe
C
53
54 this.paramsSub = this.route.params.subscribe(routeParams => {
55 const videoChannelId = routeParams['videoChannelId']
56
57 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
58 videoChannelToUpdate => {
27ec473f 59 this.videoChannel = videoChannelToUpdate
08c1efbe 60
1e66b987
C
61 this.oldSupportField = videoChannelToUpdate.support
62
08c1efbe
C
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'],
360329cc 85 description: body.description || null,
1e66b987
C
86 support: body.support || null,
87 bulkVideosSupportUpdate: body.bulkVideosSupportUpdate || false
08c1efbe
C
88 }
89
27ec473f 90 this.videoChannelService.updateVideoChannel(this.videoChannel.name, videoChannelUpdate).subscribe(
08c1efbe 91 () => {
95166f9a 92 this.authService.refreshUserInformation()
f8b2c1b4 93
66357162 94 this.notifier.success($localize`Video channel ${videoChannelUpdate.displayName} updated.`)
f8b2c1b4 95
17119e4a 96 this.router.navigate([ '/my-library', 'video-channels' ])
08c1efbe
C
97 },
98
99 err => this.error = err.message
100 )
101 }
102
52d9f792 103 onAvatarChange (formData: FormData) {
27ec473f 104 this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'avatar')
52d9f792
C
105 .subscribe(
106 data => {
66357162 107 this.notifier.success($localize`Avatar changed.`)
52d9f792 108
27ec473f 109 this.videoChannel.updateAvatar(data.avatar)
52d9f792
C
110 },
111
f6d6e7f8 112 (err: HttpErrorResponse) => genericUploadErrorHandler({
1ea7da81
RK
113 err,
114 name: $localize`avatar`,
115 notifier: this.notifier
116 })
52d9f792
C
117 )
118 }
119
1ea7da81 120 onAvatarDelete () {
27ec473f 121 this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'avatar')
1ea7da81
RK
122 .subscribe(
123 data => {
124 this.notifier.success($localize`Avatar deleted.`)
125
27ec473f 126 this.videoChannel.resetAvatar()
1ea7da81
RK
127 },
128
129 err => this.notifier.error(err.message)
130 )
131 }
132
cdeddff1 133 onBannerChange (formData: FormData) {
27ec473f 134 this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'banner')
cdeddff1
C
135 .subscribe(
136 data => {
137 this.notifier.success($localize`Banner changed.`)
138
27ec473f 139 this.videoChannel.updateBanner(data.banner)
cdeddff1
C
140 },
141
f6d6e7f8 142 (err: HttpErrorResponse) => genericUploadErrorHandler({
cdeddff1
C
143 err,
144 name: $localize`banner`,
145 notifier: this.notifier
146 })
147 )
148 }
149
150 onBannerDelete () {
27ec473f 151 this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'banner')
cdeddff1
C
152 .subscribe(
153 data => {
154 this.notifier.success($localize`Banner deleted.`)
155
27ec473f 156 this.videoChannel.resetBanner()
cdeddff1
C
157 },
158
159 err => this.notifier.error(err.message)
160 )
161 }
162
52d9f792 163 get maxAvatarSize () {
ba430d75 164 return this.serverConfig.avatar.file.size.max
52d9f792
C
165 }
166
167 get avatarExtensions () {
ba430d75 168 return this.serverConfig.avatar.file.extensions.join(',')
52d9f792
C
169 }
170
08c1efbe
C
171 isCreation () {
172 return false
173 }
174
175 getFormButtonTitle () {
66357162 176 return $localize`Update`
08c1efbe 177 }
1e66b987
C
178
179 isBulkUpdateVideosDisplayed () {
180 if (this.oldSupportField === undefined) return false
181
182 return this.oldSupportField !== this.form.value['support']
183 }
08c1efbe 184}