diff options
Diffstat (limited to 'client/src/app/+my-account')
7 files changed, 84 insertions, 34 deletions
diff --git a/client/src/app/+my-account/my-account-history/my-account-history.component.ts b/client/src/app/+my-account/my-account-history/my-account-history.component.ts index 13607119e..5f0ccee50 100644 --- a/client/src/app/+my-account/my-account-history/my-account-history.component.ts +++ b/client/src/app/+my-account/my-account-history/my-account-history.component.ts | |||
@@ -11,6 +11,7 @@ import { ScreenService } from '@app/shared/misc/screen.service' | |||
11 | import { UserHistoryService } from '@app/shared/users/user-history.service' | 11 | import { UserHistoryService } from '@app/shared/users/user-history.service' |
12 | import { UserService } from '@app/shared' | 12 | import { UserService } from '@app/shared' |
13 | import { Notifier, ServerService } from '@app/core' | 13 | import { Notifier, ServerService } from '@app/core' |
14 | import { LocalStorageService } from '@app/shared/misc/storage.service' | ||
14 | 15 | ||
15 | @Component({ | 16 | @Component({ |
16 | selector: 'my-account-history', | 17 | selector: 'my-account-history', |
@@ -35,6 +36,7 @@ export class MyAccountHistoryComponent extends AbstractVideoList implements OnIn | |||
35 | protected userService: UserService, | 36 | protected userService: UserService, |
36 | protected notifier: Notifier, | 37 | protected notifier: Notifier, |
37 | protected screenService: ScreenService, | 38 | protected screenService: ScreenService, |
39 | protected storageService: LocalStorageService, | ||
38 | private confirmService: ConfirmService, | 40 | private confirmService: ConfirmService, |
39 | private videoService: VideoService, | 41 | private videoService: VideoService, |
40 | private userHistoryService: UserHistoryService | 42 | private userHistoryService: UserHistoryService |
diff --git a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.html b/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.html index f034c6bb3..6f48d8f7d 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.html +++ b/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.html | |||
@@ -12,5 +12,5 @@ | |||
12 | </div> | 12 | </div> |
13 | </div> | 13 | </div> |
14 | 14 | ||
15 | <input type="submit" i18n-value value="Save" [disabled]="!form.valid"> | 15 | <input *ngIf="!reactiveUpdate" type="submit" class="mt-0" i18n-value value="Save" [disabled]="!form.valid"> |
16 | </form> | 16 | </form> |
diff --git a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts b/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts index 441f89f10..b6c17c0e3 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts +++ b/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts | |||
@@ -1,21 +1,26 @@ | |||
1 | import { Component, Input, OnInit } from '@angular/core' | 1 | import { Component, Input, OnInit, OnDestroy } from '@angular/core' |
2 | import { Notifier, ServerService } from '@app/core' | 2 | import { Notifier, ServerService } from '@app/core' |
3 | import { ServerConfig, UserUpdateMe } from '../../../../../../shared' | 3 | import { ServerConfig, UserUpdateMe } from '../../../../../../shared' |
4 | import { AuthService } from '../../../core' | 4 | import { AuthService } from '../../../core' |
5 | import { FormReactive, User, UserService } from '../../../shared' | 5 | import { FormReactive } from '../../../shared/forms/form-reactive' |
6 | import { User, UserService } from '../../../shared/users' | ||
6 | import { I18n } from '@ngx-translate/i18n-polyfill' | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
7 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | 8 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
8 | import { Subject } from 'rxjs' | 9 | import { Subject, Subscription } from 'rxjs' |
9 | 10 | ||
10 | @Component({ | 11 | @Component({ |
11 | selector: 'my-account-interface-settings', | 12 | selector: 'my-account-interface-settings', |
12 | templateUrl: './my-account-interface-settings.component.html', | 13 | templateUrl: './my-account-interface-settings.component.html', |
13 | styleUrls: [ './my-account-interface-settings.component.scss' ] | 14 | styleUrls: [ './my-account-interface-settings.component.scss' ] |
14 | }) | 15 | }) |
15 | export class MyAccountInterfaceSettingsComponent extends FormReactive implements OnInit { | 16 | export class MyAccountInterfaceSettingsComponent extends FormReactive implements OnInit, OnDestroy { |
16 | @Input() user: User = null | 17 | @Input() user: User = null |
18 | @Input() reactiveUpdate = false | ||
19 | @Input() notifyOnUpdate = true | ||
17 | @Input() userInformationLoaded: Subject<any> | 20 | @Input() userInformationLoaded: Subject<any> |
18 | 21 | ||
22 | formValuesWatcher: Subscription | ||
23 | |||
19 | private serverConfig: ServerConfig | 24 | private serverConfig: ServerConfig |
20 | 25 | ||
21 | constructor ( | 26 | constructor ( |
@@ -48,9 +53,17 @@ export class MyAccountInterfaceSettingsComponent extends FormReactive implements | |||
48 | this.form.patchValue({ | 53 | this.form.patchValue({ |
49 | theme: this.user.theme | 54 | theme: this.user.theme |
50 | }) | 55 | }) |
56 | |||
57 | if (this.reactiveUpdate) { | ||
58 | this.formValuesWatcher = this.form.valueChanges.subscribe(val => this.updateInterfaceSettings()) | ||
59 | } | ||
51 | }) | 60 | }) |
52 | } | 61 | } |
53 | 62 | ||
63 | ngOnDestroy () { | ||
64 | this.formValuesWatcher?.unsubscribe() | ||
65 | } | ||
66 | |||
54 | updateInterfaceSettings () { | 67 | updateInterfaceSettings () { |
55 | const theme = this.form.value['theme'] | 68 | const theme = this.form.value['theme'] |
56 | 69 | ||
@@ -58,14 +71,19 @@ export class MyAccountInterfaceSettingsComponent extends FormReactive implements | |||
58 | theme | 71 | theme |
59 | } | 72 | } |
60 | 73 | ||
61 | this.userService.updateMyProfile(details).subscribe( | 74 | if (this.authService.isLoggedIn()) { |
62 | () => { | 75 | this.userService.updateMyProfile(details).subscribe( |
63 | this.authService.refreshUserInformation() | 76 | () => { |
77 | this.authService.refreshUserInformation() | ||
64 | 78 | ||
65 | this.notifier.success(this.i18n('Interface settings updated.')) | 79 | if (this.notifyOnUpdate) this.notifier.success(this.i18n('Interface settings updated.')) |
66 | }, | 80 | }, |
67 | 81 | ||
68 | err => this.notifier.error(err.message) | 82 | err => this.notifier.error(err.message) |
69 | ) | 83 | ) |
84 | } else { | ||
85 | this.userService.updateMyAnonymousProfile(details) | ||
86 | if (this.notifyOnUpdate) this.notifier.success(this.i18n('Interface settings updated.')) | ||
87 | } | ||
70 | } | 88 | } |
71 | } | 89 | } |
diff --git a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html index 51a672734..f17829127 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html +++ b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html | |||
@@ -35,6 +35,8 @@ | |||
35 | </div> | 35 | </div> |
36 | </div> | 36 | </div> |
37 | 37 | ||
38 | <ng-content select="inner-title"></ng-content> | ||
39 | |||
38 | <div class="form-group"> | 40 | <div class="form-group"> |
39 | <my-peertube-checkbox | 41 | <my-peertube-checkbox |
40 | inputName="webTorrentEnabled" formControlName="webTorrentEnabled" | 42 | inputName="webTorrentEnabled" formControlName="webTorrentEnabled" |
@@ -56,5 +58,5 @@ | |||
56 | ></my-peertube-checkbox> | 58 | ></my-peertube-checkbox> |
57 | </div> | 59 | </div> |
58 | 60 | ||
59 | <input type="submit" i18n-value value="Save" [disabled]="!form.valid"> | 61 | <input *ngIf="!reactiveUpdate" type="submit" i18n-value value="Save" [disabled]="!form.valid"> |
60 | </form> | 62 | </form> |
diff --git a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts index a66159b3f..0aaa54cd7 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts +++ b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts | |||
@@ -1,24 +1,31 @@ | |||
1 | import { Component, Input, OnInit } from '@angular/core' | 1 | import { Component, Input, OnInit, OnDestroy } from '@angular/core' |
2 | import { Notifier, ServerService } from '@app/core' | 2 | import { Notifier, ServerService } from '@app/core' |
3 | import { UserUpdateMe } from '../../../../../../shared' | 3 | import { UserUpdateMe } from '../../../../../../shared/models/users' |
4 | import { User, UserService } from '@app/shared/users' | ||
4 | import { AuthService } from '../../../core' | 5 | import { AuthService } from '../../../core' |
5 | import { FormReactive, User, UserService } from '../../../shared' | 6 | import { FormReactive } from '@app/shared/forms/form-reactive' |
6 | import { I18n } from '@ngx-translate/i18n-polyfill' | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
7 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | 8 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
8 | import { forkJoin, Subject } from 'rxjs' | 9 | import { forkJoin, Subject, Subscription } from 'rxjs' |
9 | import { SelectItem } from 'primeng/api' | 10 | import { SelectItem } from 'primeng/api' |
10 | import { first } from 'rxjs/operators' | 11 | import { first } from 'rxjs/operators' |
12 | import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' | ||
13 | import { pick } from 'lodash-es' | ||
11 | 14 | ||
12 | @Component({ | 15 | @Component({ |
13 | selector: 'my-account-video-settings', | 16 | selector: 'my-account-video-settings', |
14 | templateUrl: './my-account-video-settings.component.html', | 17 | templateUrl: './my-account-video-settings.component.html', |
15 | styleUrls: [ './my-account-video-settings.component.scss' ] | 18 | styleUrls: [ './my-account-video-settings.component.scss' ] |
16 | }) | 19 | }) |
17 | export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit { | 20 | export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit, OnDestroy { |
18 | @Input() user: User = null | 21 | @Input() user: User = null |
22 | @Input() reactiveUpdate = false | ||
23 | @Input() notifyOnUpdate = true | ||
19 | @Input() userInformationLoaded: Subject<any> | 24 | @Input() userInformationLoaded: Subject<any> |
20 | 25 | ||
21 | languageItems: SelectItem[] = [] | 26 | languageItems: SelectItem[] = [] |
27 | defaultNSFWPolicy: NSFWPolicyType | ||
28 | formValuesWatcher: Subscription | ||
22 | 29 | ||
23 | constructor ( | 30 | constructor ( |
24 | protected formValidatorService: FormValidatorService, | 31 | protected formValidatorService: FormValidatorService, |
@@ -32,6 +39,8 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI | |||
32 | } | 39 | } |
33 | 40 | ||
34 | ngOnInit () { | 41 | ngOnInit () { |
42 | let oldForm: any | ||
43 | |||
35 | this.buildForm({ | 44 | this.buildForm({ |
36 | nsfwPolicy: null, | 45 | nsfwPolicy: null, |
37 | webTorrentEnabled: null, | 46 | webTorrentEnabled: null, |
@@ -42,8 +51,9 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI | |||
42 | 51 | ||
43 | forkJoin([ | 52 | forkJoin([ |
44 | this.serverService.getVideoLanguages(), | 53 | this.serverService.getVideoLanguages(), |
54 | this.serverService.getConfig(), | ||
45 | this.userInformationLoaded.pipe(first()) | 55 | this.userInformationLoaded.pipe(first()) |
46 | ]).subscribe(([ languages ]) => { | 56 | ]).subscribe(([ languages, config ]) => { |
47 | this.languageItems = [ { label: this.i18n('Unknown language'), value: '_unknown' } ] | 57 | this.languageItems = [ { label: this.i18n('Unknown language'), value: '_unknown' } ] |
48 | this.languageItems = this.languageItems | 58 | this.languageItems = this.languageItems |
49 | .concat(languages.map(l => ({ label: l.label, value: l.id }))) | 59 | .concat(languages.map(l => ({ label: l.label, value: l.id }))) |
@@ -52,17 +62,32 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI | |||
52 | ? this.user.videoLanguages | 62 | ? this.user.videoLanguages |
53 | : this.languageItems.map(l => l.value) | 63 | : this.languageItems.map(l => l.value) |
54 | 64 | ||
65 | this.defaultNSFWPolicy = config.instance.defaultNSFWPolicy | ||
66 | |||
55 | this.form.patchValue({ | 67 | this.form.patchValue({ |
56 | nsfwPolicy: this.user.nsfwPolicy, | 68 | nsfwPolicy: this.user.nsfwPolicy || this.defaultNSFWPolicy, |
57 | webTorrentEnabled: this.user.webTorrentEnabled, | 69 | webTorrentEnabled: this.user.webTorrentEnabled, |
58 | autoPlayVideo: this.user.autoPlayVideo === true, | 70 | autoPlayVideo: this.user.autoPlayVideo === true, |
59 | autoPlayNextVideo: this.user.autoPlayNextVideo, | 71 | autoPlayNextVideo: this.user.autoPlayNextVideo, |
60 | videoLanguages | 72 | videoLanguages |
61 | }) | 73 | }) |
74 | |||
75 | if (this.reactiveUpdate) { | ||
76 | oldForm = { ...this.form.value } | ||
77 | this.formValuesWatcher = this.form.valueChanges.subscribe((formValue: any) => { | ||
78 | const updatedKey = Object.keys(formValue).find(k => formValue[k] !== oldForm[k]) | ||
79 | oldForm = { ...this.form.value } | ||
80 | this.updateDetails([updatedKey]) | ||
81 | }) | ||
82 | } | ||
62 | }) | 83 | }) |
63 | } | 84 | } |
64 | 85 | ||
65 | updateDetails () { | 86 | ngOnDestroy () { |
87 | this.formValuesWatcher?.unsubscribe() | ||
88 | } | ||
89 | |||
90 | updateDetails (onlyKeys?: string[]) { | ||
66 | const nsfwPolicy = this.form.value[ 'nsfwPolicy' ] | 91 | const nsfwPolicy = this.form.value[ 'nsfwPolicy' ] |
67 | const webTorrentEnabled = this.form.value['webTorrentEnabled'] | 92 | const webTorrentEnabled = this.form.value['webTorrentEnabled'] |
68 | const autoPlayVideo = this.form.value['autoPlayVideo'] | 93 | const autoPlayVideo = this.form.value['autoPlayVideo'] |
@@ -81,7 +106,7 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI | |||
81 | } | 106 | } |
82 | } | 107 | } |
83 | 108 | ||
84 | const details: UserUpdateMe = { | 109 | let details: UserUpdateMe = { |
85 | nsfwPolicy, | 110 | nsfwPolicy, |
86 | webTorrentEnabled, | 111 | webTorrentEnabled, |
87 | autoPlayVideo, | 112 | autoPlayVideo, |
@@ -89,15 +114,22 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI | |||
89 | videoLanguages | 114 | videoLanguages |
90 | } | 115 | } |
91 | 116 | ||
92 | this.userService.updateMyProfile(details).subscribe( | 117 | if (onlyKeys) details = pick(details, onlyKeys) |
93 | () => { | ||
94 | this.notifier.success(this.i18n('Video settings updated.')) | ||
95 | 118 | ||
96 | this.authService.refreshUserInformation() | 119 | if (this.authService.isLoggedIn()) { |
97 | }, | 120 | this.userService.updateMyProfile(details).subscribe( |
121 | () => { | ||
122 | this.authService.refreshUserInformation() | ||
98 | 123 | ||
99 | err => this.notifier.error(err.message) | 124 | if (this.notifyOnUpdate) this.notifier.success(this.i18n('Video settings updated.')) |
100 | ) | 125 | }, |
126 | |||
127 | err => this.notifier.error(err.message) | ||
128 | ) | ||
129 | } else { | ||
130 | this.userService.updateMyAnonymousProfile(details) | ||
131 | if (this.notifyOnUpdate) this.notifier.success(this.i18n('Display/Video settings updated.')) | ||
132 | } | ||
101 | } | 133 | } |
102 | 134 | ||
103 | getDefaultVideoLanguageLabel () { | 135 | getDefaultVideoLanguageLabel () { |
diff --git a/client/src/app/+my-account/my-account.component.html b/client/src/app/+my-account/my-account.component.html index 3999252be..d885eb243 100644 --- a/client/src/app/+my-account/my-account.component.html +++ b/client/src/app/+my-account/my-account.component.html | |||
@@ -1,7 +1,7 @@ | |||
1 | <div class="row"> | 1 | <div class="row"> |
2 | <my-top-menu-dropdown [menuEntries]="menuEntries"></my-top-menu-dropdown> | 2 | <my-top-menu-dropdown [menuEntries]="menuEntries"></my-top-menu-dropdown> |
3 | 3 | ||
4 | <div class="margin-content"> | 4 | <div class="margin-content pb-5"> |
5 | <router-outlet></router-outlet> | 5 | <router-outlet></router-outlet> |
6 | </div> | 6 | </div> |
7 | </div> | 7 | </div> |
diff --git a/client/src/app/+my-account/my-account.module.ts b/client/src/app/+my-account/my-account.module.ts index 6cf1499d3..db8ffac16 100644 --- a/client/src/app/+my-account/my-account.module.ts +++ b/client/src/app/+my-account/my-account.module.ts | |||
@@ -5,7 +5,6 @@ import { InputSwitchModule } from 'primeng/inputswitch' | |||
5 | import { SharedModule } from '../shared' | 5 | import { SharedModule } from '../shared' |
6 | import { MyAccountRoutingModule } from './my-account-routing.module' | 6 | import { MyAccountRoutingModule } from './my-account-routing.module' |
7 | import { MyAccountChangePasswordComponent } from './my-account-settings/my-account-change-password/my-account-change-password.component' | 7 | import { MyAccountChangePasswordComponent } from './my-account-settings/my-account-change-password/my-account-change-password.component' |
8 | import { MyAccountVideoSettingsComponent } from './my-account-settings/my-account-video-settings/my-account-video-settings.component' | ||
9 | import { MyAccountSettingsComponent } from './my-account-settings/my-account-settings.component' | 8 | import { MyAccountSettingsComponent } from './my-account-settings/my-account-settings.component' |
10 | import { MyAccountComponent } from './my-account.component' | 9 | import { MyAccountComponent } from './my-account.component' |
11 | import { MyAccountVideosComponent } from './my-account-videos/my-account-videos.component' | 10 | import { MyAccountVideosComponent } from './my-account-videos/my-account-videos.component' |
@@ -37,7 +36,6 @@ import { | |||
37 | } from '@app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component' | 36 | } from '@app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component' |
38 | import { DragDropModule } from '@angular/cdk/drag-drop' | 37 | import { DragDropModule } from '@angular/cdk/drag-drop' |
39 | import { MyAccountChangeEmailComponent } from '@app/+my-account/my-account-settings/my-account-change-email' | 38 | import { MyAccountChangeEmailComponent } from '@app/+my-account/my-account-settings/my-account-change-email' |
40 | import { MyAccountInterfaceSettingsComponent } from '@app/+my-account/my-account-settings/my-account-interface' | ||
41 | 39 | ||
42 | @NgModule({ | 40 | @NgModule({ |
43 | imports: [ | 41 | imports: [ |
@@ -54,10 +52,8 @@ import { MyAccountInterfaceSettingsComponent } from '@app/+my-account/my-account | |||
54 | MyAccountComponent, | 52 | MyAccountComponent, |
55 | MyAccountSettingsComponent, | 53 | MyAccountSettingsComponent, |
56 | MyAccountChangePasswordComponent, | 54 | MyAccountChangePasswordComponent, |
57 | MyAccountVideoSettingsComponent, | ||
58 | MyAccountProfileComponent, | 55 | MyAccountProfileComponent, |
59 | MyAccountChangeEmailComponent, | 56 | MyAccountChangeEmailComponent, |
60 | MyAccountInterfaceSettingsComponent, | ||
61 | 57 | ||
62 | MyAccountVideosComponent, | 58 | MyAccountVideosComponent, |
63 | 59 | ||