1 import { Component, Input, OnInit } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { UserUpdateMe } from '../../../../../../shared'
4 import { AuthService } from '../../../core'
5 import { FormReactive, User, UserService } from '../../../shared'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
7 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
8 import { Subject } from 'rxjs'
11 selector: 'my-account-video-settings',
12 templateUrl: './my-account-video-settings.component.html',
13 styleUrls: [ './my-account-video-settings.component.scss' ]
15 export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit {
16 @Input() user: User = null
17 @Input() userInformationLoaded: Subject<any>
20 protected formValidatorService: FormValidatorService,
21 private authService: AuthService,
22 private notificationsService: NotificationsService,
23 private userService: UserService,
32 webTorrentEnabled: null,
36 this.userInformationLoaded.subscribe(() => {
37 this.form.patchValue({
38 nsfwPolicy: this.user.nsfwPolicy,
39 webTorrentEnabled: this.user.webTorrentEnabled,
40 autoPlayVideo: this.user.autoPlayVideo === true
46 const nsfwPolicy = this.form.value['nsfwPolicy']
47 const webTorrentEnabled = this.form.value['webTorrentEnabled']
48 const autoPlayVideo = this.form.value['autoPlayVideo']
49 const details: UserUpdateMe = {
55 this.userService.updateMyProfile(details).subscribe(
57 this.notificationsService.success(this.i18n('Success'), this.i18n('Information updated.'))
59 this.authService.refreshUserInformation()
62 err => this.notificationsService.error(this.i18n('Error'), err.message)