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