]>
Commit | Line | Data |
---|---|---|
7cd4d2ba C |
1 | import { Component, Input, OnInit } from '@angular/core' |
2 | import { Notifier, ServerService } from '@app/core' | |
ba430d75 | 3 | import { ServerConfig, UserUpdateMe } from '../../../../../../shared' |
7cd4d2ba C |
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 | ||
ba430d75 C |
19 | private serverConfig: ServerConfig |
20 | ||
7cd4d2ba C |
21 | constructor ( |
22 | protected formValidatorService: FormValidatorService, | |
23 | private authService: AuthService, | |
24 | private notifier: Notifier, | |
25 | private userService: UserService, | |
26 | private serverService: ServerService, | |
27 | private i18n: I18n | |
28 | ) { | |
29 | super() | |
30 | } | |
31 | ||
32 | get availableThemes () { | |
ba430d75 | 33 | return this.serverConfig.theme.registered |
ffb321be | 34 | .map(t => t.name) |
7cd4d2ba C |
35 | } |
36 | ||
37 | ngOnInit () { | |
ba430d75 C |
38 | this.serverConfig = this.serverService.getTmpConfig() |
39 | this.serverService.getConfig() | |
40 | .subscribe(config => this.serverConfig = config) | |
41 | ||
7cd4d2ba C |
42 | this.buildForm({ |
43 | theme: null | |
44 | }) | |
45 | ||
46 | this.userInformationLoaded | |
47 | .subscribe(() => { | |
48 | this.form.patchValue({ | |
49 | theme: this.user.theme | |
50 | }) | |
51 | }) | |
52 | } | |
53 | ||
54 | updateInterfaceSettings () { | |
55 | const theme = this.form.value['theme'] | |
56 | ||
57 | const details: UserUpdateMe = { | |
58 | theme | |
59 | } | |
60 | ||
61 | this.userService.updateMyProfile(details).subscribe( | |
62 | () => { | |
ffb321be | 63 | this.authService.refreshUserInformation() |
7cd4d2ba | 64 | |
ffb321be | 65 | this.notifier.success(this.i18n('Interface settings updated.')) |
7cd4d2ba C |
66 | }, |
67 | ||
68 | err => this.notifier.error(err.message) | |
69 | ) | |
70 | } | |
71 | } |