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