aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-user-settings
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/shared-user-settings')
-rw-r--r--client/src/app/shared/shared-user-settings/index.ts4
-rw-r--r--client/src/app/shared/shared-user-settings/shared-user-settings.module.ts26
-rw-r--r--client/src/app/shared/shared-user-settings/user-interface-settings.component.html17
-rw-r--r--client/src/app/shared/shared-user-settings/user-interface-settings.component.scss21
-rw-r--r--client/src/app/shared/shared-user-settings/user-interface-settings.component.ts86
-rw-r--r--client/src/app/shared/shared-user-settings/user-video-settings.component.html75
-rw-r--r--client/src/app/shared/shared-user-settings/user-video-settings.component.scss24
-rw-r--r--client/src/app/shared/shared-user-settings/user-video-settings.component.ts139
8 files changed, 392 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-user-settings/index.ts b/client/src/app/shared/shared-user-settings/index.ts
new file mode 100644
index 000000000..dcc08bdce
--- /dev/null
+++ b/client/src/app/shared/shared-user-settings/index.ts
@@ -0,0 +1,4 @@
1export * from './user-interface-settings.component'
2export * from './user-video-settings.component'
3
4export * from './shared-user-settings.module'
diff --git a/client/src/app/shared/shared-user-settings/shared-user-settings.module.ts b/client/src/app/shared/shared-user-settings/shared-user-settings.module.ts
new file mode 100644
index 000000000..395f2e3d0
--- /dev/null
+++ b/client/src/app/shared/shared-user-settings/shared-user-settings.module.ts
@@ -0,0 +1,26 @@
1
2import { NgModule } from '@angular/core'
3import { SharedFormModule } from '../shared-forms'
4import { SharedMainModule } from '../shared-main/shared-main.module'
5import { UserInterfaceSettingsComponent } from './user-interface-settings.component'
6import { UserVideoSettingsComponent } from './user-video-settings.component'
7
8@NgModule({
9 imports: [
10 SharedMainModule,
11 SharedFormModule
12 ],
13
14 declarations: [
15 UserInterfaceSettingsComponent,
16 UserVideoSettingsComponent
17 ],
18
19 exports: [
20 UserInterfaceSettingsComponent,
21 UserVideoSettingsComponent
22 ],
23
24 providers: [ ]
25})
26export class SharedUserInterfaceSettingsModule { }
diff --git a/client/src/app/shared/shared-user-settings/user-interface-settings.component.html b/client/src/app/shared/shared-user-settings/user-interface-settings.component.html
new file mode 100644
index 000000000..0d0ddc0f2
--- /dev/null
+++ b/client/src/app/shared/shared-user-settings/user-interface-settings.component.html
@@ -0,0 +1,17 @@
1<form role="form" (ngSubmit)="updateInterfaceSettings()" [formGroup]="form">
2
3 <div class="form-group">
4 <label i18n for="theme">Theme</label>
5
6 <div class="peertube-select-container">
7 <select formControlName="theme" id="theme" class="form-control">
8 <option i18n value="instance-default">instance default</option>
9 <option i18n value="default">peertube default</option>
10
11 <option *ngFor="let theme of availableThemes" [value]="theme">{{ theme }}</option>
12 </select>
13 </div>
14 </div>
15
16 <input *ngIf="!reactiveUpdate" type="submit" class="mt-0" i18n-value value="Save" [disabled]="!form.valid">
17</form>
diff --git a/client/src/app/shared/shared-user-settings/user-interface-settings.component.scss b/client/src/app/shared/shared-user-settings/user-interface-settings.component.scss
new file mode 100644
index 000000000..7818dfc02
--- /dev/null
+++ b/client/src/app/shared/shared-user-settings/user-interface-settings.component.scss
@@ -0,0 +1,21 @@
1@import '_variables';
2@import '_mixins';
3
4label {
5 font-weight: $font-regular;
6 font-size: 100%;
7}
8
9input[type=submit] {
10 @include peertube-button;
11 @include orange-button;
12
13 display: block;
14 margin-top: 15px;
15}
16
17.peertube-select-container {
18 @include peertube-select-container(340px);
19
20 margin-bottom: 30px;
21}
diff --git a/client/src/app/shared/shared-user-settings/user-interface-settings.component.ts b/client/src/app/shared/shared-user-settings/user-interface-settings.component.ts
new file mode 100644
index 000000000..875ffa3f1
--- /dev/null
+++ b/client/src/app/shared/shared-user-settings/user-interface-settings.component.ts
@@ -0,0 +1,86 @@
1import { Subject, Subscription } from 'rxjs'
2import { Component, Input, OnDestroy, OnInit } from '@angular/core'
3import { AuthService, Notifier, ServerService, UserService } from '@app/core'
4import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
5import { I18n } from '@ngx-translate/i18n-polyfill'
6import { ServerConfig, User, UserUpdateMe } from '@shared/models'
7
8@Component({
9 selector: 'my-user-interface-settings',
10 templateUrl: './user-interface-settings.component.html',
11 styleUrls: [ './user-interface-settings.component.scss' ]
12})
13export class UserInterfaceSettingsComponent extends FormReactive implements OnInit, OnDestroy {
14 @Input() user: User = null
15 @Input() reactiveUpdate = false
16 @Input() notifyOnUpdate = true
17 @Input() userInformationLoaded: Subject<any>
18
19 formValuesWatcher: Subscription
20
21 private serverConfig: ServerConfig
22
23 constructor (
24 protected formValidatorService: FormValidatorService,
25 private authService: AuthService,
26 private notifier: Notifier,
27 private userService: UserService,
28 private serverService: ServerService,
29 private i18n: I18n
30 ) {
31 super()
32 }
33
34 get availableThemes () {
35 return this.serverConfig.theme.registered
36 .map(t => t.name)
37 }
38
39 ngOnInit () {
40 this.serverConfig = this.serverService.getTmpConfig()
41 this.serverService.getConfig()
42 .subscribe(config => this.serverConfig = config)
43
44 this.buildForm({
45 theme: null
46 })
47
48 this.userInformationLoaded
49 .subscribe(() => {
50 this.form.patchValue({
51 theme: this.user.theme
52 })
53
54 if (this.reactiveUpdate) {
55 this.formValuesWatcher = this.form.valueChanges.subscribe(val => this.updateInterfaceSettings())
56 }
57 })
58 }
59
60 ngOnDestroy () {
61 this.formValuesWatcher?.unsubscribe()
62 }
63
64 updateInterfaceSettings () {
65 const theme = this.form.value['theme']
66
67 const details: UserUpdateMe = {
68 theme
69 }
70
71 if (this.authService.isLoggedIn()) {
72 this.userService.updateMyProfile(details).subscribe(
73 () => {
74 this.authService.refreshUserInformation()
75
76 if (this.notifyOnUpdate) this.notifier.success(this.i18n('Interface settings updated.'))
77 },
78
79 err => this.notifier.error(err.message)
80 )
81 } else {
82 this.userService.updateMyAnonymousProfile(details)
83 if (this.notifyOnUpdate) this.notifier.success(this.i18n('Interface settings updated.'))
84 }
85 }
86}
diff --git a/client/src/app/shared/shared-user-settings/user-video-settings.component.html b/client/src/app/shared/shared-user-settings/user-video-settings.component.html
new file mode 100644
index 000000000..0dda33af2
--- /dev/null
+++ b/client/src/app/shared/shared-user-settings/user-video-settings.component.html
@@ -0,0 +1,75 @@
1<form role="form" (ngSubmit)="updateDetails()" [formGroup]="form">
2 <div class="form-group form-group-select">
3 <label i18n for="nsfwPolicy">Default policy on videos containing sensitive content</label>
4 <my-help>
5 <ng-template ptTemplate="customHtml">
6 <ng-container i18n>
7 With <strong>Do not list</strong> or <strong>Blur thumbnails</strong>, a confirmation will be requested to watch the video.
8 </ng-container>
9 </ng-template>
10 </my-help>
11
12 <div class="peertube-select-container">
13 <select id="nsfwPolicy" formControlName="nsfwPolicy" class="form-control">
14 <option i18n value="undefined" disabled>Policy for sensitive videos</option>
15 <option i18n value="do_not_list">Do not list</option>
16 <option i18n value="blur">Blur thumbnails</option>
17 <option i18n value="display">Display</option>
18 </select>
19 </div>
20 </div>
21
22 <div class="form-group form-group-select">
23 <label i18n for="videoLanguages">Only display videos in the following languages/subtitles</label>
24 <my-help>
25 <ng-template ptTemplate="customHtml">
26 <ng-container i18n>In Recently added, Trending, Local, Most liked and Search pages</ng-container>
27 </ng-template>
28 </my-help>
29
30 <div>
31 <p-multiSelect
32 inputId="videoLanguages" [options]="languageItems" formControlName="videoLanguages" [showToggleAll]="true"
33 [defaultLabel]="getDefaultVideoLanguageLabel()" [selectedItemsLabel]="getSelectedVideoLanguageLabel()"
34 emptyFilterMessage="No results found" i18n-emptyFilterMessage
35 ></p-multiSelect>
36 </div>
37 </div>
38
39 <ng-content select="inner-title"></ng-content>
40
41 <div class="form-group">
42 <my-peertube-checkbox
43 inputName="webTorrentEnabled" formControlName="webTorrentEnabled" [recommended]="true"
44 i18n-labelText labelText="Help share videos being played"
45 >
46 <ng-container ngProjectAs="description">
47 <span i18n>The <a routerLink="/about/peertube" fragment="privacy">sharing system</a> implies that some technical information about your system (such as a public IP address) can be sent to other peers, but greatly helps to reduce server load.</span>
48 </ng-container>
49 </my-peertube-checkbox>
50 </div>
51
52 <div class="form-group">
53 <my-peertube-checkbox
54 inputName="autoPlayVideo" formControlName="autoPlayVideo"
55 i18n-labelText labelText="Automatically play videos"
56 >
57 <ng-container ngProjectAs="description">
58 <span i18n>When on a video page, directly start playing the video.</span>
59 </ng-container>
60 </my-peertube-checkbox>
61 </div>
62
63 <div class="form-group">
64 <my-peertube-checkbox
65 inputName="autoPlayNextVideo" formControlName="autoPlayNextVideo"
66 i18n-labelText labelText="Automatically start playing the next video"
67 >
68 <ng-container ngProjectAs="description">
69 <span i18n>When a video ends, follow up with the next suggested video.</span>
70 </ng-container>
71 </my-peertube-checkbox>
72 </div>
73
74 <input *ngIf="!reactiveUpdate" type="submit" i18n-value value="Save" [disabled]="!form.valid">
75</form>
diff --git a/client/src/app/shared/shared-user-settings/user-video-settings.component.scss b/client/src/app/shared/shared-user-settings/user-video-settings.component.scss
new file mode 100644
index 000000000..430250b87
--- /dev/null
+++ b/client/src/app/shared/shared-user-settings/user-video-settings.component.scss
@@ -0,0 +1,24 @@
1@import '_variables';
2@import '_mixins';
3
4label {
5 font-weight: $font-regular;
6 font-size: 100%;
7}
8
9input[type=submit] {
10 @include peertube-button;
11 @include orange-button;
12
13 margin-top: 15px;
14}
15
16.peertube-select-container {
17 @include peertube-select-container(340px);
18
19 margin-bottom: 30px;
20}
21
22.form-group-select {
23 margin-bottom: 30px;
24}
diff --git a/client/src/app/shared/shared-user-settings/user-video-settings.component.ts b/client/src/app/shared/shared-user-settings/user-video-settings.component.ts
new file mode 100644
index 000000000..4e4539936
--- /dev/null
+++ b/client/src/app/shared/shared-user-settings/user-video-settings.component.ts
@@ -0,0 +1,139 @@
1import { pick } from 'lodash-es'
2import { SelectItem } from 'primeng/api'
3import { forkJoin, Subject, Subscription } from 'rxjs'
4import { first } from 'rxjs/operators'
5import { Component, Input, OnDestroy, OnInit } from '@angular/core'
6import { AuthService, Notifier, ServerService, User, UserService } from '@app/core'
7import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
8import { I18n } from '@ngx-translate/i18n-polyfill'
9import { UserUpdateMe } from '@shared/models'
10import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type'
11
12@Component({
13 selector: 'my-user-video-settings',
14 templateUrl: './user-video-settings.component.html',
15 styleUrls: [ './user-video-settings.component.scss' ]
16})
17export class UserVideoSettingsComponent extends FormReactive implements OnInit, OnDestroy {
18 @Input() user: User = null
19 @Input() reactiveUpdate = false
20 @Input() notifyOnUpdate = true
21 @Input() userInformationLoaded: Subject<any>
22
23 languageItems: SelectItem[] = []
24 defaultNSFWPolicy: NSFWPolicyType
25 formValuesWatcher: Subscription
26
27 constructor (
28 protected formValidatorService: FormValidatorService,
29 private authService: AuthService,
30 private notifier: Notifier,
31 private userService: UserService,
32 private serverService: ServerService,
33 private i18n: I18n
34 ) {
35 super()
36 }
37
38 ngOnInit () {
39 let oldForm: any
40
41 this.buildForm({
42 nsfwPolicy: null,
43 webTorrentEnabled: null,
44 autoPlayVideo: null,
45 autoPlayNextVideo: null,
46 videoLanguages: null
47 })
48
49 forkJoin([
50 this.serverService.getVideoLanguages(),
51 this.serverService.getConfig(),
52 this.userInformationLoaded.pipe(first())
53 ]).subscribe(([ languages, config ]) => {
54 this.languageItems = [ { label: this.i18n('Unknown language'), value: '_unknown' } ]
55 this.languageItems = this.languageItems
56 .concat(languages.map(l => ({ label: l.label, value: l.id })))
57
58 const videoLanguages = this.user.videoLanguages
59 ? this.user.videoLanguages
60 : this.languageItems.map(l => l.value)
61
62 this.defaultNSFWPolicy = config.instance.defaultNSFWPolicy
63
64 this.form.patchValue({
65 nsfwPolicy: this.user.nsfwPolicy || this.defaultNSFWPolicy,
66 webTorrentEnabled: this.user.webTorrentEnabled,
67 autoPlayVideo: this.user.autoPlayVideo === true,
68 autoPlayNextVideo: this.user.autoPlayNextVideo,
69 videoLanguages
70 })
71
72 if (this.reactiveUpdate) {
73 oldForm = { ...this.form.value }
74 this.formValuesWatcher = this.form.valueChanges.subscribe((formValue: any) => {
75 const updatedKey = Object.keys(formValue).find(k => formValue[k] !== oldForm[k])
76 oldForm = { ...this.form.value }
77 this.updateDetails([updatedKey])
78 })
79 }
80 })
81 }
82
83 ngOnDestroy () {
84 this.formValuesWatcher?.unsubscribe()
85 }
86
87 updateDetails (onlyKeys?: string[]) {
88 const nsfwPolicy = this.form.value[ 'nsfwPolicy' ]
89 const webTorrentEnabled = this.form.value['webTorrentEnabled']
90 const autoPlayVideo = this.form.value['autoPlayVideo']
91 const autoPlayNextVideo = this.form.value['autoPlayNextVideo']
92
93 let videoLanguages: string[] = this.form.value['videoLanguages']
94 if (Array.isArray(videoLanguages)) {
95 if (videoLanguages.length === this.languageItems.length) {
96 videoLanguages = null // null means "All"
97 } else if (videoLanguages.length > 20) {
98 this.notifier.error('Too many languages are enabled. Please enable them all or stay below 20 enabled languages.')
99 return
100 } else if (videoLanguages.length === 0) {
101 this.notifier.error('You need to enabled at least 1 video language.')
102 return
103 }
104 }
105
106 let details: UserUpdateMe = {
107 nsfwPolicy,
108 webTorrentEnabled,
109 autoPlayVideo,
110 autoPlayNextVideo,
111 videoLanguages
112 }
113
114 if (onlyKeys) details = pick(details, onlyKeys)
115
116 if (this.authService.isLoggedIn()) {
117 this.userService.updateMyProfile(details).subscribe(
118 () => {
119 this.authService.refreshUserInformation()
120
121 if (this.notifyOnUpdate) this.notifier.success(this.i18n('Video settings updated.'))
122 },
123
124 err => this.notifier.error(err.message)
125 )
126 } else {
127 this.userService.updateMyAnonymousProfile(details)
128 if (this.notifyOnUpdate) this.notifier.success(this.i18n('Display/Video settings updated.'))
129 }
130 }
131
132 getDefaultVideoLanguageLabel () {
133 return this.i18n('No language')
134 }
135
136 getSelectedVideoLanguageLabel () {
137 return this.i18n('{{\'{0} languages selected')
138 }
139}