diff options
author | Chocobozzz <me@florianbigard.com> | 2018-04-23 16:16:05 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-04-23 16:16:05 +0200 |
commit | 4bb6886d28cc5333bbe1523674bf5db141af456f (patch) | |
tree | 86276bfa11afdd4357ac45df2ead26a41f181069 /client/src/app/my-account/my-account-settings | |
parent | 3186046d17cc09a3426d5ea67835f4c936cb18a3 (diff) | |
download | PeerTube-4bb6886d28cc5333bbe1523674bf5db141af456f.tar.gz PeerTube-4bb6886d28cc5333bbe1523674bf5db141af456f.tar.zst PeerTube-4bb6886d28cc5333bbe1523674bf5db141af456f.zip |
Rename account module to my-account
Diffstat (limited to 'client/src/app/my-account/my-account-settings')
11 files changed, 362 insertions, 0 deletions
diff --git a/client/src/app/my-account/my-account-settings/my-account-change-password/index.ts b/client/src/app/my-account/my-account-settings/my-account-change-password/index.ts new file mode 100644 index 000000000..644047c5f --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-change-password/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './my-account-change-password.component' | |||
diff --git a/client/src/app/my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html b/client/src/app/my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html new file mode 100644 index 000000000..b0e3cada4 --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html | |||
@@ -0,0 +1,20 @@ | |||
1 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> | ||
2 | |||
3 | <form role="form" (ngSubmit)="changePassword()" [formGroup]="form"> | ||
4 | |||
5 | <label for="new-password">Change password</label> | ||
6 | <input | ||
7 | type="password" id="new-password" placeholder="New password" | ||
8 | formControlName="new-password" [ngClass]="{ 'input-error': formErrors['new-password'] }" | ||
9 | > | ||
10 | <div *ngIf="formErrors['new-password']" class="form-error"> | ||
11 | {{ formErrors['new-password'] }} | ||
12 | </div> | ||
13 | |||
14 | <input | ||
15 | type="password" id="new-confirmed-password" placeholder="Confirm new password" | ||
16 | formControlName="new-confirmed-password" | ||
17 | > | ||
18 | |||
19 | <input type="submit" value="Change password" [disabled]="!form.valid"> | ||
20 | </form> | ||
diff --git a/client/src/app/my-account/my-account-settings/my-account-change-password/my-account-change-password.component.scss b/client/src/app/my-account/my-account-settings/my-account-change-password/my-account-change-password.component.scss new file mode 100644 index 000000000..f8279ffd3 --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-change-password/my-account-change-password.component.scss | |||
@@ -0,0 +1,19 @@ | |||
1 | @import '_variables'; | ||
2 | @import '_mixins'; | ||
3 | |||
4 | input[type=password] { | ||
5 | @include peertube-input-text(340px); | ||
6 | display: block; | ||
7 | |||
8 | &#new-confirmed-password { | ||
9 | margin-top: 15px; | ||
10 | } | ||
11 | } | ||
12 | |||
13 | input[type=submit] { | ||
14 | @include peertube-button; | ||
15 | @include orange-button; | ||
16 | |||
17 | margin-top: 15px; | ||
18 | } | ||
19 | |||
diff --git a/client/src/app/my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts b/client/src/app/my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts new file mode 100644 index 000000000..80af668f9 --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts | |||
@@ -0,0 +1,62 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | ||
2 | import { FormBuilder, FormGroup } from '@angular/forms' | ||
3 | import { NotificationsService } from 'angular2-notifications' | ||
4 | import { FormReactive, USER_PASSWORD, UserService } from '../../../shared' | ||
5 | |||
6 | @Component({ | ||
7 | selector: 'my-account-change-password', | ||
8 | templateUrl: './my-account-change-password.component.html', | ||
9 | styleUrls: [ './my-account-change-password.component.scss' ] | ||
10 | }) | ||
11 | export class MyAccountChangePasswordComponent extends FormReactive implements OnInit { | ||
12 | error: string = null | ||
13 | |||
14 | form: FormGroup | ||
15 | formErrors = { | ||
16 | 'new-password': '', | ||
17 | 'new-confirmed-password': '' | ||
18 | } | ||
19 | validationMessages = { | ||
20 | 'new-password': USER_PASSWORD.MESSAGES, | ||
21 | 'new-confirmed-password': USER_PASSWORD.MESSAGES | ||
22 | } | ||
23 | |||
24 | constructor ( | ||
25 | private formBuilder: FormBuilder, | ||
26 | private notificationsService: NotificationsService, | ||
27 | private userService: UserService | ||
28 | ) { | ||
29 | super() | ||
30 | } | ||
31 | |||
32 | buildForm () { | ||
33 | this.form = this.formBuilder.group({ | ||
34 | 'new-password': [ '', USER_PASSWORD.VALIDATORS ], | ||
35 | 'new-confirmed-password': [ '', USER_PASSWORD.VALIDATORS ] | ||
36 | }) | ||
37 | |||
38 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
39 | } | ||
40 | |||
41 | ngOnInit () { | ||
42 | this.buildForm() | ||
43 | } | ||
44 | |||
45 | changePassword () { | ||
46 | const newPassword = this.form.value['new-password'] | ||
47 | const newConfirmedPassword = this.form.value['new-confirmed-password'] | ||
48 | |||
49 | this.error = null | ||
50 | |||
51 | if (newPassword !== newConfirmedPassword) { | ||
52 | this.error = 'The new password and the confirmed password do not correspond.' | ||
53 | return | ||
54 | } | ||
55 | |||
56 | this.userService.changePassword(newPassword).subscribe( | ||
57 | () => this.notificationsService.success('Success', 'Password updated.'), | ||
58 | |||
59 | err => this.error = err.message | ||
60 | ) | ||
61 | } | ||
62 | } | ||
diff --git a/client/src/app/my-account/my-account-settings/my-account-details/index.ts b/client/src/app/my-account/my-account-settings/my-account-details/index.ts new file mode 100644 index 000000000..b7f58e329 --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-details/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './my-account-details.component' | |||
diff --git a/client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.html b/client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.html new file mode 100644 index 000000000..0e8598e9e --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.html | |||
@@ -0,0 +1,25 @@ | |||
1 | <form role="form" (ngSubmit)="updateDetails()" [formGroup]="form"> | ||
2 | <div class="form-group"> | ||
3 | <label for="nsfwPolicy">Default policy on videos containing sensitive content</label> | ||
4 | <my-help helpType="custom" customHtml="With <strong>Do not list</strong> or <strong>Blur thumbnails</strong>, a confirmation will be requested to watch the video."></my-help> | ||
5 | |||
6 | <div class="peertube-select-container"> | ||
7 | <select id="nsfwPolicy" formControlName="nsfwPolicy"> | ||
8 | <option value="do_not_list">Do not list</option> | ||
9 | <option value="blur">Blur thumbnails</option> | ||
10 | <option value="display">Display</option> | ||
11 | </select> | ||
12 | </div> | ||
13 | </div> | ||
14 | |||
15 | <div class="form-group"> | ||
16 | <input | ||
17 | type="checkbox" id="autoPlayVideo" | ||
18 | formControlName="autoPlayVideo" | ||
19 | > | ||
20 | <label for="autoPlayVideo"></label> | ||
21 | <label for="autoPlayVideo">Automatically plays video</label> | ||
22 | </div> | ||
23 | |||
24 | <input type="submit" value="Save" [disabled]="!form.valid"> | ||
25 | </form> | ||
diff --git a/client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.scss b/client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.scss new file mode 100644 index 000000000..ed59e4689 --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.scss | |||
@@ -0,0 +1,20 @@ | |||
1 | @import '_variables'; | ||
2 | @import '_mixins'; | ||
3 | |||
4 | input[type=checkbox] { | ||
5 | @include peertube-checkbox(1px); | ||
6 | } | ||
7 | |||
8 | input[type=submit] { | ||
9 | @include peertube-button; | ||
10 | @include orange-button; | ||
11 | |||
12 | display: block; | ||
13 | margin-top: 15px; | ||
14 | } | ||
15 | |||
16 | .peertube-select-container { | ||
17 | @include peertube-select-container(340px); | ||
18 | |||
19 | margin-bottom: 30px; | ||
20 | } \ No newline at end of file | ||
diff --git a/client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.ts b/client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.ts new file mode 100644 index 000000000..4c1456541 --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.ts | |||
@@ -0,0 +1,60 @@ | |||
1 | import { Component, Input, OnInit } from '@angular/core' | ||
2 | import { FormBuilder, FormGroup } from '@angular/forms' | ||
3 | import { NotificationsService } from 'angular2-notifications' | ||
4 | import { UserUpdateMe } from '../../../../../../shared' | ||
5 | import { AuthService } from '../../../core' | ||
6 | import { FormReactive, User, UserService } from '../../../shared' | ||
7 | |||
8 | @Component({ | ||
9 | selector: 'my-account-details', | ||
10 | templateUrl: './my-account-details.component.html', | ||
11 | styleUrls: [ './my-account-details.component.scss' ] | ||
12 | }) | ||
13 | export class MyAccountDetailsComponent extends FormReactive implements OnInit { | ||
14 | @Input() user: User = null | ||
15 | |||
16 | form: FormGroup | ||
17 | formErrors = {} | ||
18 | validationMessages = {} | ||
19 | |||
20 | constructor ( | ||
21 | private authService: AuthService, | ||
22 | private formBuilder: FormBuilder, | ||
23 | private notificationsService: NotificationsService, | ||
24 | private userService: UserService | ||
25 | ) { | ||
26 | super() | ||
27 | } | ||
28 | |||
29 | buildForm () { | ||
30 | this.form = this.formBuilder.group({ | ||
31 | nsfwPolicy: [ this.user.nsfwPolicy ], | ||
32 | autoPlayVideo: [ this.user.autoPlayVideo ] | ||
33 | }) | ||
34 | |||
35 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
36 | } | ||
37 | |||
38 | ngOnInit () { | ||
39 | this.buildForm() | ||
40 | } | ||
41 | |||
42 | updateDetails () { | ||
43 | const nsfwPolicy = this.form.value['nsfwPolicy'] | ||
44 | const autoPlayVideo = this.form.value['autoPlayVideo'] | ||
45 | const details: UserUpdateMe = { | ||
46 | nsfwPolicy, | ||
47 | autoPlayVideo | ||
48 | } | ||
49 | |||
50 | this.userService.updateMyDetails(details).subscribe( | ||
51 | () => { | ||
52 | this.notificationsService.success('Success', 'Information updated.') | ||
53 | |||
54 | this.authService.refreshUserInformation() | ||
55 | }, | ||
56 | |||
57 | err => this.notificationsService.error('Error', err.message) | ||
58 | ) | ||
59 | } | ||
60 | } | ||
diff --git a/client/src/app/my-account/my-account-settings/my-account-settings.component.html b/client/src/app/my-account/my-account-settings/my-account-settings.component.html new file mode 100644 index 000000000..7ae27dc75 --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-settings.component.html | |||
@@ -0,0 +1,24 @@ | |||
1 | <div class="user"> | ||
2 | <img [src]="getAvatarUrl()" alt="Avatar" /> | ||
3 | |||
4 | <div class="user-info"> | ||
5 | <div class="user-info-username">{{ user.username }}</div> | ||
6 | <div class="user-info-followers">{{ user.account?.followersCount }} subscribers</div> | ||
7 | </div> | ||
8 | </div> | ||
9 | |||
10 | <div class="button-file"> | ||
11 | <span>Change your avatar</span> | ||
12 | <input #avatarfileInput type="file" name="avatarfile" id="avatarfile" [accept]="avatarExtensions" (change)="changeAvatar()" /> | ||
13 | </div> | ||
14 | <div class="file-max-size">(extensions: {{ avatarExtensions }}, max size: {{ maxAvatarSize | bytes }})</div> | ||
15 | |||
16 | <div class="user-quota"> | ||
17 | <span class="user-quota-label">Video quota:</span> {{ userVideoQuotaUsed | bytes: 0 }} / {{ userVideoQuota }} | ||
18 | </div> | ||
19 | |||
20 | <div class="account-title">Account settings</div> | ||
21 | <my-account-change-password></my-account-change-password> | ||
22 | |||
23 | <div class="account-title">Video settings</div> | ||
24 | <my-account-details [user]="user"></my-account-details> | ||
diff --git a/client/src/app/my-account/my-account-settings/my-account-settings.component.scss b/client/src/app/my-account/my-account-settings/my-account-settings.component.scss new file mode 100644 index 000000000..1cc00ca49 --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-settings.component.scss | |||
@@ -0,0 +1,56 @@ | |||
1 | @import '_variables'; | ||
2 | @import '_mixins'; | ||
3 | |||
4 | .user { | ||
5 | display: flex; | ||
6 | |||
7 | img { | ||
8 | @include avatar(50px); | ||
9 | |||
10 | margin-right: 15px; | ||
11 | } | ||
12 | |||
13 | .user-info { | ||
14 | .user-info-username { | ||
15 | font-size: 20px; | ||
16 | font-weight: $font-bold; | ||
17 | } | ||
18 | |||
19 | .user-info-followers { | ||
20 | font-size: 15px; | ||
21 | } | ||
22 | } | ||
23 | } | ||
24 | |||
25 | .button-file { | ||
26 | @include peertube-button-file(160px); | ||
27 | |||
28 | margin-top: 10px; | ||
29 | margin-bottom: 5px; | ||
30 | } | ||
31 | |||
32 | .file-max-size { | ||
33 | display: inline-block; | ||
34 | font-size: 13px; | ||
35 | |||
36 | position: relative; | ||
37 | top: -10px; | ||
38 | } | ||
39 | |||
40 | .user-quota { | ||
41 | font-size: 15px; | ||
42 | margin-top: 20px; | ||
43 | |||
44 | .user-quota-label { | ||
45 | font-weight: $font-semibold; | ||
46 | } | ||
47 | } | ||
48 | |||
49 | .account-title { | ||
50 | text-transform: uppercase; | ||
51 | color: $orange-color; | ||
52 | font-weight: $font-bold; | ||
53 | font-size: 13px; | ||
54 | margin-top: 55px; | ||
55 | margin-bottom: 30px; | ||
56 | } | ||
diff --git a/client/src/app/my-account/my-account-settings/my-account-settings.component.ts b/client/src/app/my-account/my-account-settings/my-account-settings.component.ts new file mode 100644 index 000000000..91420cc6f --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-settings.component.ts | |||
@@ -0,0 +1,74 @@ | |||
1 | import { Component, OnInit, ViewChild } from '@angular/core' | ||
2 | import { NotificationsService } from 'angular2-notifications' | ||
3 | import { BytesPipe } from 'ngx-pipes' | ||
4 | import { AuthService } from '../../core' | ||
5 | import { ServerService } from '../../core/server' | ||
6 | import { User } from '../../shared' | ||
7 | import { UserService } from '../../shared/users' | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-account-settings', | ||
11 | templateUrl: './my-account-settings.component.html', | ||
12 | styleUrls: [ './my-account-settings.component.scss' ] | ||
13 | }) | ||
14 | export class MyAccountSettingsComponent implements OnInit { | ||
15 | @ViewChild('avatarfileInput') avatarfileInput | ||
16 | |||
17 | user: User = null | ||
18 | userVideoQuota = '0' | ||
19 | userVideoQuotaUsed = 0 | ||
20 | |||
21 | constructor ( | ||
22 | private userService: UserService, | ||
23 | private authService: AuthService, | ||
24 | private serverService: ServerService, | ||
25 | private notificationsService: NotificationsService | ||
26 | ) {} | ||
27 | |||
28 | ngOnInit () { | ||
29 | this.user = this.authService.getUser() | ||
30 | |||
31 | this.authService.userInformationLoaded.subscribe( | ||
32 | () => { | ||
33 | if (this.user.videoQuota !== -1) { | ||
34 | this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString() | ||
35 | } else { | ||
36 | this.userVideoQuota = 'Unlimited' | ||
37 | } | ||
38 | } | ||
39 | ) | ||
40 | |||
41 | this.userService.getMyVideoQuotaUsed() | ||
42 | .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed) | ||
43 | } | ||
44 | |||
45 | getAvatarUrl () { | ||
46 | return this.user.getAvatarUrl() | ||
47 | } | ||
48 | |||
49 | changeAvatar () { | ||
50 | const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ] | ||
51 | |||
52 | const formData = new FormData() | ||
53 | formData.append('avatarfile', avatarfile) | ||
54 | |||
55 | this.userService.changeAvatar(formData) | ||
56 | .subscribe( | ||
57 | data => { | ||
58 | this.notificationsService.success('Success', 'Avatar changed.') | ||
59 | |||
60 | this.user.account.avatar = data.avatar | ||
61 | }, | ||
62 | |||
63 | err => this.notificationsService.error('Error', err.message) | ||
64 | ) | ||
65 | } | ||
66 | |||
67 | get maxAvatarSize () { | ||
68 | return this.serverService.getConfig().avatar.file.size.max | ||
69 | } | ||
70 | |||
71 | get avatarExtensions () { | ||
72 | return this.serverService.getConfig().avatar.file.extensions.join(',') | ||
73 | } | ||
74 | } | ||