]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - 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
1import { Subscription } from 'rxjs'
2import { HttpErrorResponse } from '@angular/common/http'
3import { Component, OnDestroy, OnInit } from '@angular/core'
4import { ActivatedRoute, Router } from '@angular/router'
5import { AuthService, Notifier, ServerService } from '@app/core'
6import { genericUploadErrorHandler } from '@app/helpers'
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'
13import { VideoChannel, VideoChannelService } from '@app/shared/shared-main'
14import { ServerConfig, VideoChannelUpdate } from '@shared/models'
15import { MyVideoChannelEdit } from './my-video-channel-edit'
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})
22export class MyVideoChannelUpdateComponent extends MyVideoChannelEdit implements OnInit, OnDestroy {
23 error: string
24 videoChannel: 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.videoChannel = 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.videoChannel.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.changeVideoChannelImage(this.videoChannel.name, formData, 'avatar')
105 .subscribe(
106 data => {
107 this.notifier.success($localize`Avatar changed.`)
108
109 this.videoChannel.updateAvatar(data.avatar)
110 },
111
112 (err: HttpErrorResponse) => genericUploadErrorHandler({
113 err,
114 name: $localize`avatar`,
115 notifier: this.notifier
116 })
117 )
118 }
119
120 onAvatarDelete () {
121 this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'avatar')
122 .subscribe(
123 data => {
124 this.notifier.success($localize`Avatar deleted.`)
125
126 this.videoChannel.resetAvatar()
127 },
128
129 err => this.notifier.error(err.message)
130 )
131 }
132
133 onBannerChange (formData: FormData) {
134 this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'banner')
135 .subscribe(
136 data => {
137 this.notifier.success($localize`Banner changed.`)
138
139 this.videoChannel.updateBanner(data.banner)
140 },
141
142 (err: HttpErrorResponse) => genericUploadErrorHandler({
143 err,
144 name: $localize`banner`,
145 notifier: this.notifier
146 })
147 )
148 }
149
150 onBannerDelete () {
151 this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'banner')
152 .subscribe(
153 data => {
154 this.notifier.success($localize`Banner deleted.`)
155
156 this.videoChannel.resetBanner()
157 },
158
159 err => this.notifier.error(err.message)
160 )
161 }
162
163 get maxAvatarSize () {
164 return this.serverConfig.avatar.file.size.max
165 }
166
167 get avatarExtensions () {
168 return this.serverConfig.avatar.file.extensions.join(',')
169 }
170
171 isCreation () {
172 return false
173 }
174
175 getFormButtonTitle () {
176 return $localize`Update`
177 }
178
179 isBulkUpdateVideosDisplayed () {
180 if (this.oldSupportField === undefined) return false
181
182 return this.oldSupportField !== this.form.value['support']
183 }
184}