]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/account/account-settings/account-details/account-details.component.ts
Add ability to choose what policy we have for NSFW videos
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account-settings / account-details / account-details.component.ts
CommitLineData
c30745f3 1import { Component, Input, OnInit } from '@angular/core'
df98563e 2import { FormBuilder, FormGroup } from '@angular/forms'
df98563e 3import { NotificationsService } from 'angular2-notifications'
c30745f3
C
4import { UserUpdateMe } from '../../../../../../shared'
5import { AuthService } from '../../../core'
6import { FormReactive, User, UserService } from '../../../shared'
af5e743b
C
7
8@Component({
9 selector: 'my-account-details',
c30745f3
C
10 templateUrl: './account-details.component.html',
11 styleUrls: [ './account-details.component.scss' ]
af5e743b
C
12})
13
14export class AccountDetailsComponent extends FormReactive implements OnInit {
df98563e 15 @Input() user: User = null
af5e743b 16
df98563e
C
17 form: FormGroup
18 formErrors = {}
19 validationMessages = {}
af5e743b 20
df98563e 21 constructor (
af5e743b
C
22 private authService: AuthService,
23 private formBuilder: FormBuilder,
af5e743b
C
24 private notificationsService: NotificationsService,
25 private userService: UserService
26 ) {
df98563e 27 super()
af5e743b
C
28 }
29
df98563e 30 buildForm () {
af5e743b 31 this.form = this.formBuilder.group({
0883b324 32 nsfwPolicy: [ this.user.nsfwPolicy ],
7efe153b 33 autoPlayVideo: [ this.user.autoPlayVideo ]
df98563e 34 })
af5e743b 35
df98563e 36 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
af5e743b
C
37 }
38
df98563e
C
39 ngOnInit () {
40 this.buildForm()
af5e743b
C
41 }
42
df98563e 43 updateDetails () {
0883b324 44 const nsfwPolicy = this.form.value['nsfwPolicy']
7efe153b 45 const autoPlayVideo = this.form.value['autoPlayVideo']
8094a898 46 const details: UserUpdateMe = {
0883b324 47 nsfwPolicy,
7efe153b 48 autoPlayVideo
df98563e 49 }
af5e743b 50
8094a898 51 this.userService.updateMyDetails(details).subscribe(
af5e743b 52 () => {
8094a898 53 this.notificationsService.success('Success', 'Information updated.')
af5e743b 54
d592e0a9 55 this.authService.refreshUserInformation()
af5e743b
C
56 },
57
fd206f0b 58 err => this.notificationsService.error('Error', err.message)
df98563e 59 )
af5e743b
C
60 }
61}