]>
Commit | Line | Data |
---|---|---|
c30745f3 | 1 | import { Component, Input, OnInit } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier } from '@app/core' |
c30745f3 C |
3 | import { UserUpdateMe } from '../../../../../../shared' |
4 | import { AuthService } from '../../../core' | |
5 | import { FormReactive, User, UserService } from '../../../shared' | |
b1d40cff | 6 | import { I18n } from '@ngx-translate/i18n-polyfill' |
d18d6478 | 7 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
4d089429 | 8 | import { Subject } from 'rxjs' |
af5e743b C |
9 | |
10 | @Component({ | |
ed56ad11 C |
11 | selector: 'my-account-video-settings', |
12 | templateUrl: './my-account-video-settings.component.html', | |
13 | styleUrls: [ './my-account-video-settings.component.scss' ] | |
af5e743b | 14 | }) |
ed56ad11 | 15 | export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit { |
df98563e | 16 | @Input() user: User = null |
d18d6478 | 17 | @Input() userInformationLoaded: Subject<any> |
af5e743b | 18 | |
df98563e | 19 | constructor ( |
d18d6478 | 20 | protected formValidatorService: FormValidatorService, |
af5e743b | 21 | private authService: AuthService, |
f8b2c1b4 | 22 | private notifier: Notifier, |
b1d40cff C |
23 | private userService: UserService, |
24 | private i18n: I18n | |
af5e743b | 25 | ) { |
df98563e | 26 | super() |
af5e743b C |
27 | } |
28 | ||
d18d6478 C |
29 | ngOnInit () { |
30 | this.buildForm({ | |
31 | nsfwPolicy: null, | |
ed638e53 | 32 | webTorrentEnabled: null, |
d18d6478 | 33 | autoPlayVideo: null |
df98563e | 34 | }) |
af5e743b | 35 | |
d18d6478 C |
36 | this.userInformationLoaded.subscribe(() => { |
37 | this.form.patchValue({ | |
38 | nsfwPolicy: this.user.nsfwPolicy, | |
ed638e53 | 39 | webTorrentEnabled: this.user.webTorrentEnabled, |
d879e48b | 40 | autoPlayVideo: this.user.autoPlayVideo === true |
d18d6478 C |
41 | }) |
42 | }) | |
af5e743b C |
43 | } |
44 | ||
df98563e | 45 | updateDetails () { |
0883b324 | 46 | const nsfwPolicy = this.form.value['nsfwPolicy'] |
ed638e53 | 47 | const webTorrentEnabled = this.form.value['webTorrentEnabled'] |
7efe153b | 48 | const autoPlayVideo = this.form.value['autoPlayVideo'] |
8094a898 | 49 | const details: UserUpdateMe = { |
0883b324 | 50 | nsfwPolicy, |
ed638e53 | 51 | webTorrentEnabled, |
7efe153b | 52 | autoPlayVideo |
df98563e | 53 | } |
af5e743b | 54 | |
ed56ad11 | 55 | this.userService.updateMyProfile(details).subscribe( |
af5e743b | 56 | () => { |
f8b2c1b4 | 57 | this.notifier.success(this.i18n('Information updated.')) |
af5e743b | 58 | |
d592e0a9 | 59 | this.authService.refreshUserInformation() |
af5e743b C |
60 | }, |
61 | ||
f8b2c1b4 | 62 | err => this.notifier.error(err.message) |
df98563e | 63 | ) |
af5e743b C |
64 | } |
65 | } |