]> 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
NoImplicitAny flag true (#1157)
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-video-channels / my-account-video-channel-update.component.ts
1 import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { NotificationsService } from 'angular2-notifications'
4 import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit'
5 import { VideoChannelUpdate } from '../../../../../shared/models/videos'
6 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
7 import { Subscription } from 'rxjs'
8 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
9 import { AuthService, ServerService } from '@app/core'
10 import { I18n } from '@ngx-translate/i18n-polyfill'
11 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
12 import { VideoChannelValidatorsService } from '@app/shared/forms/form-validators/video-channel-validators.service'
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 })
19 export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelEdit implements OnInit, OnDestroy {
20 @ViewChild('avatarfileInput') avatarfileInput: any
21
22 error: string
23
24 videoChannelToUpdate: VideoChannel
25 private paramsSub: Subscription
26
27 constructor (
28 protected formValidatorService: FormValidatorService,
29 private authService: AuthService,
30 private videoChannelValidatorsService: VideoChannelValidatorsService,
31 private notificationsService: NotificationsService,
32 private router: Router,
33 private route: ActivatedRoute,
34 private videoChannelService: VideoChannelService,
35 private i18n: I18n,
36 private serverService: ServerService
37 ) {
38 super()
39 }
40
41 ngOnInit () {
42 this.buildForm({
43 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
44 description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION,
45 support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT
46 })
47
48 this.paramsSub = this.route.params.subscribe(routeParams => {
49 const videoChannelId = routeParams['videoChannelId']
50
51 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
52 videoChannelToUpdate => {
53 this.videoChannelToUpdate = videoChannelToUpdate
54
55 this.form.patchValue({
56 'display-name': videoChannelToUpdate.displayName,
57 description: videoChannelToUpdate.description,
58 support: videoChannelToUpdate.support
59 })
60 },
61
62 err => this.error = err.message
63 )
64 })
65 }
66
67 ngOnDestroy () {
68 if (this.paramsSub) this.paramsSub.unsubscribe()
69 }
70
71 formValidated () {
72 this.error = undefined
73
74 const body = this.form.value
75 const videoChannelUpdate: VideoChannelUpdate = {
76 displayName: body['display-name'],
77 description: body.description || null,
78 support: body.support || null
79 }
80
81 this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.name, videoChannelUpdate).subscribe(
82 () => {
83 this.authService.refreshUserInformation()
84 this.notificationsService.success(
85 this.i18n('Success'),
86 this.i18n('Video channel {{videoChannelName}} updated.', { videoChannelName: videoChannelUpdate.displayName })
87 )
88 this.router.navigate([ '/my-account', 'video-channels' ])
89 },
90
91 err => this.error = err.message
92 )
93 }
94
95 onAvatarChange (formData: FormData) {
96 this.videoChannelService.changeVideoChannelAvatar(this.videoChannelToUpdate.name, formData)
97 .subscribe(
98 data => {
99 this.notificationsService.success(this.i18n('Success'), this.i18n('Avatar changed.'))
100
101 this.videoChannelToUpdate.updateAvatar(data.avatar)
102 },
103
104 err => this.notificationsService.error(this.i18n('Error'), err.message)
105 )
106 }
107
108 get maxAvatarSize () {
109 return this.serverService.getConfig().avatar.file.size.max
110 }
111
112 get avatarExtensions () {
113 return this.serverService.getConfig().avatar.file.extensions.join(',')
114 }
115
116 isCreation () {
117 return false
118 }
119
120 getFormButtonTitle () {
121 return this.i18n('Update')
122 }
123 }