]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/account/account-details/account-details.component.ts
Use typescript standard and lint all files
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account-details / account-details.component.ts
1 import { Component, OnInit, Input } from '@angular/core'
2 import { FormBuilder, FormGroup } from '@angular/forms'
3 import { Router } from '@angular/router'
4
5 import { NotificationsService } from 'angular2-notifications'
6
7 import { AuthService } from '../../core'
8 import {
9 FormReactive,
10 User,
11 UserService,
12 USER_PASSWORD
13 } from '../../shared'
14
15 @Component({
16 selector: 'my-account-details',
17 templateUrl: './account-details.component.html'
18 })
19
20 export class AccountDetailsComponent extends FormReactive implements OnInit {
21 @Input() user: User = null
22
23 error: string = null
24
25 form: FormGroup
26 formErrors = {}
27 validationMessages = {}
28
29 constructor (
30 private authService: AuthService,
31 private formBuilder: FormBuilder,
32 private router: Router,
33 private notificationsService: NotificationsService,
34 private userService: UserService
35 ) {
36 super()
37 }
38
39 buildForm () {
40 this.form = this.formBuilder.group({
41 displayNSFW: [ this.user.displayNSFW ]
42 })
43
44 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
45 }
46
47 ngOnInit () {
48 this.buildForm()
49 }
50
51 updateDetails () {
52 const displayNSFW = this.form.value['displayNSFW']
53 const details = {
54 displayNSFW
55 }
56
57 this.error = null
58 this.userService.updateDetails(details).subscribe(
59 () => {
60 this.notificationsService.success('Success', 'Informations updated.')
61
62 this.authService.refreshUserInformations()
63 },
64
65 err => this.error = err
66 )
67 }
68 }