Add ability to disable P2P in HLS player too
[oweals/peertube.git] / client / src / app / +my-account / my-account-settings / my-account-interface / my-account-interface-settings.component.ts
1 import { Component, Input, OnInit } from '@angular/core'
2 import { Notifier, ServerService } from '@app/core'
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'
9
10 @Component({
11   selector: 'my-account-interface-settings',
12   templateUrl: './my-account-interface-settings.component.html',
13   styleUrls: [ './my-account-interface-settings.component.scss' ]
14 })
15 export class MyAccountInterfaceSettingsComponent extends FormReactive implements OnInit {
16   @Input() user: User = null
17   @Input() userInformationLoaded: Subject<any>
18
19   constructor (
20     protected formValidatorService: FormValidatorService,
21     private authService: AuthService,
22     private notifier: Notifier,
23     private userService: UserService,
24     private serverService: ServerService,
25     private i18n: I18n
26   ) {
27     super()
28   }
29
30   get availableThemes () {
31     return this.serverService.getConfig().theme.registered
32                .map(t => t.name)
33   }
34
35   ngOnInit () {
36     this.buildForm({
37       theme: null
38     })
39
40     this.userInformationLoaded
41       .subscribe(() => {
42         this.form.patchValue({
43           theme: this.user.theme
44         })
45       })
46   }
47
48   updateInterfaceSettings () {
49     const theme = this.form.value['theme']
50
51     const details: UserUpdateMe = {
52       theme
53     }
54
55     this.userService.updateMyProfile(details).subscribe(
56       () => {
57         this.authService.refreshUserInformation()
58
59         this.notifier.success(this.i18n('Interface settings updated.'))
60       },
61
62       err => this.notifier.error(err.message)
63     )
64   }
65 }