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