]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-video-channels/my-account-video-channel-update.component.ts
API: Add ability to update video channel avatar
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-video-channels / my-account-video-channel-update.component.ts
CommitLineData
db400f44 1import { Component, OnDestroy, OnInit } from '@angular/core'
08c1efbe
C
2import { ActivatedRoute, Router } from '@angular/router'
3import { NotificationsService } from 'angular2-notifications'
08c1efbe 4import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit'
08c1efbe 5import { VideoChannelUpdate } from '../../../../../shared/models/videos'
08c1efbe 6import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
db400f44 7import { Subscription } from 'rxjs'
08c1efbe 8import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
95166f9a 9import { AuthService } from '@app/core'
b1d40cff 10import { I18n } from '@ngx-translate/i18n-polyfill'
d18d6478 11import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
e309822b 12import { VideoChannelValidatorsService } from '@app/shared/forms/form-validators/video-channel-validators.service'
08c1efbe
C
13
14@Component({
15 selector: 'my-account-video-channel-update',
16 templateUrl: './my-account-video-channel-edit.component.html',
17 styleUrls: [ './my-account-video-channel-edit.component.scss' ]
18})
19export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelEdit implements OnInit, OnDestroy {
20 error: string
21
08c1efbe
C
22 private videoChannelToUpdate: VideoChannel
23 private paramsSub: Subscription
24
25 constructor (
d18d6478 26 protected formValidatorService: FormValidatorService,
95166f9a 27 private authService: AuthService,
e309822b 28 private videoChannelValidatorsService: VideoChannelValidatorsService,
08c1efbe
C
29 private notificationsService: NotificationsService,
30 private router: Router,
31 private route: ActivatedRoute,
b1d40cff
C
32 private videoChannelService: VideoChannelService,
33 private i18n: I18n
08c1efbe
C
34 ) {
35 super()
36 }
37
08c1efbe 38 ngOnInit () {
d18d6478 39 this.buildForm({
e309822b
C
40 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
41 description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION,
42 support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT
d18d6478 43 })
08c1efbe
C
44
45 this.paramsSub = this.route.params.subscribe(routeParams => {
46 const videoChannelId = routeParams['videoChannelId']
47
48 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
49 videoChannelToUpdate => {
50 this.videoChannelToUpdate = videoChannelToUpdate
51
52 this.form.patchValue({
53 'display-name': videoChannelToUpdate.displayName,
54 description: videoChannelToUpdate.description,
55 support: videoChannelToUpdate.support
56 })
57 },
58
59 err => this.error = err.message
60 )
61 })
62 }
63
64 ngOnDestroy () {
65 if (this.paramsSub) this.paramsSub.unsubscribe()
66 }
67
68 formValidated () {
69 this.error = undefined
70
71 const body = this.form.value
72 const videoChannelUpdate: VideoChannelUpdate = {
73 displayName: body['display-name'],
360329cc
C
74 description: body.description || null,
75 support: body.support || null
08c1efbe
C
76 }
77
78 this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.uuid, videoChannelUpdate).subscribe(
79 () => {
95166f9a 80 this.authService.refreshUserInformation()
b1d40cff
C
81 this.notificationsService.success(
82 this.i18n('Success'),
25acef90 83 this.i18n('Video channel {{videoChannelName}} updated.', { videoChannelName: videoChannelUpdate.displayName })
b1d40cff 84 )
08c1efbe
C
85 this.router.navigate([ '/my-account', 'video-channels' ])
86 },
87
88 err => this.error = err.message
89 )
90 }
91
92 isCreation () {
93 return false
94 }
95
96 getFormButtonTitle () {
b1d40cff 97 return this.i18n('Update')
08c1efbe
C
98 }
99}