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/Subject'
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,
35 this.userInformationLoaded.subscribe(() => {
36 this.form.patchValue({
37 nsfwPolicy: this.user.nsfwPolicy,
38 autoPlayVideo: this.user.autoPlayVideo === true ? 'true' : 'false'
44 const nsfwPolicy = this.form.value['nsfwPolicy']
45 const autoPlayVideo = this.form.value['autoPlayVideo']
46 const details: UserUpdateMe = {
51 this.userService.updateMyProfile(details).subscribe(
53 this.notificationsService.success(this.i18n('Success'), this.i18n('Information updated.'))
55 this.authService.refreshUserInformation()
58 err => this.notificationsService.error(this.i18n('Error'), err.message)