aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/menu/menu.component.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-02-28 13:52:21 +0100
committerGitHub <noreply@github.com>2020-02-28 13:52:21 +0100
commitd3217560a611b94f888ecf3de93b428a7521d4de (patch)
tree26fc984f351afb994dc13c94e138476ded50c76a /client/src/app/menu/menu.component.ts
parent64645512b08875c18ebdc009a550cdfa69def955 (diff)
downloadPeerTube-d3217560a611b94f888ecf3de93b428a7521d4de.tar.gz
PeerTube-d3217560a611b94f888ecf3de93b428a7521d4de.tar.zst
PeerTube-d3217560a611b94f888ecf3de93b428a7521d4de.zip
Add visitor settings, rework logged-in dropdown (#2514)
* Add visitor settings, rework logged-in dropdown * Make user dropdown P2P switch functional * Fix lint * Fix unnecessary notification when user logs out * Simplify visitor settings code and remove unnecessary icons * Catch parsing errors and reindent menu styles
Diffstat (limited to 'client/src/app/menu/menu.component.ts')
-rw-r--r--client/src/app/menu/menu.component.ts62
1 files changed, 55 insertions, 7 deletions
diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.ts
index 1d7651e78..5f3dfc52a 100644
--- a/client/src/app/menu/menu.component.ts
+++ b/client/src/app/menu/menu.component.ts
@@ -1,10 +1,13 @@
1import { Component, OnInit, ViewChild } from '@angular/core' 1import { Component, OnInit, ViewChild } from '@angular/core'
2import { UserRight } from '../../../../shared/models/users/user-right.enum' 2import { UserRight } from '../../../../shared/models/users/user-right.enum'
3import { AuthService, AuthStatus, RedirectService, ServerService, ThemeService } from '../core' 3import { AuthService, AuthStatus, RedirectService, ServerService } from '../core'
4import { User } from '../shared/users/user.model' 4import { User } from '@app/shared/users/user.model'
5import { UserService } from '@app/shared/users/user.service'
5import { LanguageChooserComponent } from '@app/menu/language-chooser.component' 6import { LanguageChooserComponent } from '@app/menu/language-chooser.component'
6import { HotkeysService } from 'angular2-hotkeys' 7import { HotkeysService } from 'angular2-hotkeys'
7import { ServerConfig } from '@shared/models' 8import { ServerConfig, VideoConstant } from '@shared/models'
9import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component'
10import { I18n } from '@ngx-translate/i18n-polyfill'
8 11
9@Component({ 12@Component({
10 selector: 'my-menu', 13 selector: 'my-menu',
@@ -13,11 +16,14 @@ import { ServerConfig } from '@shared/models'
13}) 16})
14export class MenuComponent implements OnInit { 17export class MenuComponent implements OnInit {
15 @ViewChild('languageChooserModal', { static: true }) languageChooserModal: LanguageChooserComponent 18 @ViewChild('languageChooserModal', { static: true }) languageChooserModal: LanguageChooserComponent
19 @ViewChild('quickSettingsModal', { static: true }) quickSettingsModal: QuickSettingsModalComponent
16 20
17 user: User 21 user: User
18 isLoggedIn: boolean 22 isLoggedIn: boolean
23
19 userHasAdminAccess = false 24 userHasAdminAccess = false
20 helpVisible = false 25 helpVisible = false
26 languages: VideoConstant<string>[] = []
21 27
22 private serverConfig: ServerConfig 28 private serverConfig: ServerConfig
23 private routesPerRight: { [ role in UserRight ]?: string } = { 29 private routesPerRight: { [ role in UserRight ]?: string } = {
@@ -31,9 +37,11 @@ export class MenuComponent implements OnInit {
31 37
32 constructor ( 38 constructor (
33 private authService: AuthService, 39 private authService: AuthService,
40 private userService: UserService,
34 private serverService: ServerService, 41 private serverService: ServerService,
35 private redirectService: RedirectService, 42 private redirectService: RedirectService,
36 private hotkeysService: HotkeysService 43 private hotkeysService: HotkeysService,
44 private i18n: I18n
37 ) {} 45 ) {}
38 46
39 ngOnInit () { 47 ngOnInit () {
@@ -63,9 +71,33 @@ export class MenuComponent implements OnInit {
63 } 71 }
64 ) 72 )
65 73
66 this.hotkeysService.cheatSheetToggle.subscribe(isOpen => { 74 this.hotkeysService.cheatSheetToggle.subscribe(isOpen => this.helpVisible = isOpen)
67 this.helpVisible = isOpen 75
68 }) 76 this.serverService.getVideoLanguages().subscribe(languages => this.languages = languages)
77 }
78
79 get language () {
80 return this.languageChooserModal.getCurrentLanguage()
81 }
82
83 get videoLanguages (): string[] {
84 if (!this.user) return
85 if (!this.user.videoLanguages) return [this.i18n('any language')]
86 return this.user.videoLanguages
87 .map(locale => this.langForLocale(locale))
88 .map(value => value === undefined ? '?' : value)
89 }
90
91 get nsfwPolicy () {
92 if (!this.user) return
93 switch (this.user.nsfwPolicy) {
94 case 'do_not_list':
95 return this.i18n('hide')
96 case 'blur':
97 return this.i18n('blur')
98 case 'display':
99 return this.i18n('display')
100 }
69 } 101 }
70 102
71 isRegistrationAllowed () { 103 isRegistrationAllowed () {
@@ -117,6 +149,22 @@ export class MenuComponent implements OnInit {
117 this.hotkeysService.cheatSheetToggle.next(!this.helpVisible) 149 this.hotkeysService.cheatSheetToggle.next(!this.helpVisible)
118 } 150 }
119 151
152 openQuickSettings () {
153 this.quickSettingsModal.show()
154 }
155
156 toggleUseP2P () {
157 if (!this.user) return
158 this.user.webTorrentEnabled = !this.user.webTorrentEnabled
159 this.userService.updateMyProfile({
160 webTorrentEnabled: this.user.webTorrentEnabled
161 }).subscribe(() => this.authService.refreshUserInformation())
162 }
163
164 langForLocale(localeId: string) {
165 return this.languages.find(lang => lang.id = localeId).label
166 }
167
120 private computeIsUserHasAdminAccess () { 168 private computeIsUserHasAdminAccess () {
121 const right = this.getFirstAdminRightAvailable() 169 const right = this.getFirstAdminRightAvailable()
122 170