diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-09 09:26:41 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-09 09:32:26 +0200 |
commit | 62e62f118d5da57acd3494fece2e8ed357564ffe (patch) | |
tree | ff5b7c6ec5708d71a76a2eb5744d810015ae29a5 /client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts | |
parent | 1952a538baa330b13bd11631b3975f7ef1c37e70 (diff) | |
download | PeerTube-62e62f118d5da57acd3494fece2e8ed357564ffe.tar.gz PeerTube-62e62f118d5da57acd3494fece2e8ed357564ffe.tar.zst PeerTube-62e62f118d5da57acd3494fece2e8ed357564ffe.zip |
Load my-account module lazily
Diffstat (limited to 'client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts')
-rw-r--r-- | client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts b/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts new file mode 100644 index 000000000..2b7ba353c --- /dev/null +++ b/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts | |||
@@ -0,0 +1,65 @@ | |||
1 | import { Component, Input, OnInit } from '@angular/core' | ||
2 | import { FormBuilder, FormGroup } from '@angular/forms' | ||
3 | import { NotificationsService } from 'angular2-notifications' | ||
4 | import { FormReactive, USER_DESCRIPTION, USER_DISPLAY_NAME, UserService } from '../../../shared' | ||
5 | import { User } from '@app/shared' | ||
6 | |||
7 | @Component({ | ||
8 | selector: 'my-account-profile', | ||
9 | templateUrl: './my-account-profile.component.html', | ||
10 | styleUrls: [ './my-account-profile.component.scss' ] | ||
11 | }) | ||
12 | export class MyAccountProfileComponent extends FormReactive implements OnInit { | ||
13 | @Input() user: User = null | ||
14 | |||
15 | error: string = null | ||
16 | |||
17 | form: FormGroup | ||
18 | formErrors = { | ||
19 | 'display-name': '', | ||
20 | 'description': '' | ||
21 | } | ||
22 | validationMessages = { | ||
23 | 'display-name': USER_DISPLAY_NAME.MESSAGES, | ||
24 | 'description': USER_DESCRIPTION.MESSAGES | ||
25 | } | ||
26 | |||
27 | constructor ( | ||
28 | private formBuilder: FormBuilder, | ||
29 | private notificationsService: NotificationsService, | ||
30 | private userService: UserService | ||
31 | ) { | ||
32 | super() | ||
33 | } | ||
34 | |||
35 | buildForm () { | ||
36 | this.form = this.formBuilder.group({ | ||
37 | 'display-name': [ this.user.account.displayName, USER_DISPLAY_NAME.VALIDATORS ], | ||
38 | 'description': [ this.user.account.description, USER_DESCRIPTION.VALIDATORS ] | ||
39 | }) | ||
40 | |||
41 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
42 | } | ||
43 | |||
44 | ngOnInit () { | ||
45 | this.buildForm() | ||
46 | } | ||
47 | |||
48 | updateMyProfile () { | ||
49 | const displayName = this.form.value['display-name'] | ||
50 | const description = this.form.value['description'] | ||
51 | |||
52 | this.error = null | ||
53 | |||
54 | this.userService.updateMyProfile({ displayName, description }).subscribe( | ||
55 | () => { | ||
56 | this.user.account.displayName = displayName | ||
57 | this.user.account.description = description | ||
58 | |||
59 | this.notificationsService.success('Success', 'Profile updated.') | ||
60 | }, | ||
61 | |||
62 | err => this.error = err.message | ||
63 | ) | ||
64 | } | ||
65 | } | ||