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