]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { Subscription } from 'rxjs' |
c199c427 | 2 | import { Component, OnDestroy, OnInit } from '@angular/core' |
08c1efbe | 3 | import { ActivatedRoute, Router } from '@angular/router' |
f8b2c1b4 | 4 | import { AuthService, Notifier, ServerService } from '@app/core' |
67ed6552 C |
5 | import { FormValidatorService, VideoChannelValidatorsService } from '@app/shared/shared-forms' |
6 | import { VideoChannel, VideoChannelService } from '@app/shared/shared-main' | |
b1d40cff | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
67ed6552 C |
8 | import { ServerConfig, VideoChannelUpdate } from '@shared/models' |
9 | import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit' | |
08c1efbe C |
10 | |
11 | @Component({ | |
12 | selector: 'my-account-video-channel-update', | |
13 | templateUrl: './my-account-video-channel-edit.component.html', | |
14 | styleUrls: [ './my-account-video-channel-edit.component.scss' ] | |
15 | }) | |
16 | export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelEdit implements OnInit, OnDestroy { | |
17 | error: string | |
e1807a94 | 18 | videoChannelToUpdate: VideoChannel |
c199c427 | 19 | |
08c1efbe | 20 | private paramsSub: Subscription |
1e66b987 | 21 | private oldSupportField: string |
ba430d75 | 22 | private serverConfig: ServerConfig |
08c1efbe C |
23 | |
24 | constructor ( | |
d18d6478 | 25 | protected formValidatorService: FormValidatorService, |
95166f9a | 26 | private authService: AuthService, |
e309822b | 27 | private videoChannelValidatorsService: VideoChannelValidatorsService, |
f8b2c1b4 | 28 | private notifier: Notifier, |
08c1efbe C |
29 | private router: Router, |
30 | private route: ActivatedRoute, | |
b1d40cff | 31 | private videoChannelService: VideoChannelService, |
52d9f792 C |
32 | private i18n: I18n, |
33 | private serverService: ServerService | |
08c1efbe C |
34 | ) { |
35 | super() | |
36 | } | |
37 | ||
08c1efbe | 38 | ngOnInit () { |
ba430d75 C |
39 | this.serverConfig = this.serverService.getTmpConfig() |
40 | this.serverService.getConfig() | |
41 | .subscribe(config => this.serverConfig = config) | |
42 | ||
d18d6478 | 43 | this.buildForm({ |
e309822b C |
44 | 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME, |
45 | description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION, | |
1e66b987 C |
46 | support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT, |
47 | bulkVideosSupportUpdate: null | |
d18d6478 | 48 | }) |
08c1efbe C |
49 | |
50 | this.paramsSub = this.route.params.subscribe(routeParams => { | |
51 | const videoChannelId = routeParams['videoChannelId'] | |
52 | ||
53 | this.videoChannelService.getVideoChannel(videoChannelId).subscribe( | |
54 | videoChannelToUpdate => { | |
55 | this.videoChannelToUpdate = videoChannelToUpdate | |
56 | ||
1e66b987 C |
57 | this.oldSupportField = videoChannelToUpdate.support |
58 | ||
08c1efbe C |
59 | this.form.patchValue({ |
60 | 'display-name': videoChannelToUpdate.displayName, | |
61 | description: videoChannelToUpdate.description, | |
62 | support: videoChannelToUpdate.support | |
63 | }) | |
64 | }, | |
65 | ||
66 | err => this.error = err.message | |
67 | ) | |
68 | }) | |
69 | } | |
70 | ||
71 | ngOnDestroy () { | |
72 | if (this.paramsSub) this.paramsSub.unsubscribe() | |
73 | } | |
74 | ||
75 | formValidated () { | |
76 | this.error = undefined | |
77 | ||
78 | const body = this.form.value | |
79 | const videoChannelUpdate: VideoChannelUpdate = { | |
80 | displayName: body['display-name'], | |
360329cc | 81 | description: body.description || null, |
1e66b987 C |
82 | support: body.support || null, |
83 | bulkVideosSupportUpdate: body.bulkVideosSupportUpdate || false | |
08c1efbe C |
84 | } |
85 | ||
22a16e36 | 86 | this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.name, videoChannelUpdate).subscribe( |
08c1efbe | 87 | () => { |
95166f9a | 88 | this.authService.refreshUserInformation() |
f8b2c1b4 C |
89 | |
90 | this.notifier.success( | |
25acef90 | 91 | this.i18n('Video channel {{videoChannelName}} updated.', { videoChannelName: videoChannelUpdate.displayName }) |
b1d40cff | 92 | ) |
f8b2c1b4 | 93 | |
08c1efbe C |
94 | this.router.navigate([ '/my-account', 'video-channels' ]) |
95 | }, | |
96 | ||
97 | err => this.error = err.message | |
98 | ) | |
99 | } | |
100 | ||
52d9f792 | 101 | onAvatarChange (formData: FormData) { |
22a16e36 | 102 | this.videoChannelService.changeVideoChannelAvatar(this.videoChannelToUpdate.name, formData) |
52d9f792 C |
103 | .subscribe( |
104 | data => { | |
f8b2c1b4 | 105 | this.notifier.success(this.i18n('Avatar changed.')) |
52d9f792 C |
106 | |
107 | this.videoChannelToUpdate.updateAvatar(data.avatar) | |
108 | }, | |
109 | ||
f8b2c1b4 | 110 | err => this.notifier.error(err.message) |
52d9f792 C |
111 | ) |
112 | } | |
113 | ||
114 | get maxAvatarSize () { | |
ba430d75 | 115 | return this.serverConfig.avatar.file.size.max |
52d9f792 C |
116 | } |
117 | ||
118 | get avatarExtensions () { | |
ba430d75 | 119 | return this.serverConfig.avatar.file.extensions.join(',') |
52d9f792 C |
120 | } |
121 | ||
08c1efbe C |
122 | isCreation () { |
123 | return false | |
124 | } | |
125 | ||
126 | getFormButtonTitle () { | |
b1d40cff | 127 | return this.i18n('Update') |
08c1efbe | 128 | } |
1e66b987 C |
129 | |
130 | isBulkUpdateVideosDisplayed () { | |
131 | if (this.oldSupportField === undefined) return false | |
132 | ||
133 | return this.oldSupportField !== this.form.value['support'] | |
134 | } | |
08c1efbe | 135 | } |