diff options
Diffstat (limited to 'client/src/app/menu')
-rw-r--r-- | client/src/app/menu/menu.component.html | 2 | ||||
-rw-r--r-- | client/src/app/menu/menu.component.ts | 67 |
2 files changed, 46 insertions, 23 deletions
diff --git a/client/src/app/menu/menu.component.html b/client/src/app/menu/menu.component.html index 8faa37ed6..71fb2c154 100644 --- a/client/src/app/menu/menu.component.html +++ b/client/src/app/menu/menu.component.html | |||
@@ -81,7 +81,7 @@ | |||
81 | <div *ngIf="isLoggedIn" class="panel-block"> | 81 | <div *ngIf="isLoggedIn" class="panel-block"> |
82 | <div i18n class="block-title">MY LIBRARY</div> | 82 | <div i18n class="block-title">MY LIBRARY</div> |
83 | 83 | ||
84 | <a routerLink="/my-account/videos" routerLinkActive="active"> | 84 | <a *ngIf="user.canSeeVideosLink" routerLink="/my-account/videos" routerLinkActive="active"> |
85 | <my-global-icon iconName="videos" aria-hidden="true"></my-global-icon> | 85 | <my-global-icon iconName="videos" aria-hidden="true"></my-global-icon> |
86 | <ng-container i18n>Videos</ng-container> | 86 | <ng-container i18n>Videos</ng-container> |
87 | </a> | 87 | </a> |
diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.ts index 0ea251f1c..2c55b9a84 100644 --- a/client/src/app/menu/menu.component.ts +++ b/client/src/app/menu/menu.component.ts | |||
@@ -1,21 +1,25 @@ | |||
1 | import { HotkeysService } from 'angular2-hotkeys' | 1 | import { HotkeysService } from 'angular2-hotkeys' |
2 | import * as debug from 'debug' | ||
3 | import { switchMap } from 'rxjs/operators' | ||
2 | import { Component, OnInit, ViewChild } from '@angular/core' | 4 | import { Component, OnInit, ViewChild } from '@angular/core' |
3 | import { AuthService, AuthStatus, RedirectService, ScreenService, ServerService, User, UserService } from '@app/core' | 5 | import { AuthService, AuthStatus, AuthUser, RedirectService, ScreenService, ServerService, UserService } from '@app/core' |
4 | import { LanguageChooserComponent } from '@app/menu/language-chooser.component' | 6 | import { LanguageChooserComponent } from '@app/menu/language-chooser.component' |
5 | import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component' | 7 | import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component' |
6 | import { I18n } from '@ngx-translate/i18n-polyfill' | 8 | import { I18n } from '@ngx-translate/i18n-polyfill' |
7 | import { ServerConfig, UserRight, VideoConstant } from '@shared/models' | 9 | import { ServerConfig, UserRight, VideoConstant } from '@shared/models' |
8 | 10 | ||
11 | const logger = debug('peertube:menu:MenuComponent') | ||
12 | |||
9 | @Component({ | 13 | @Component({ |
10 | selector: 'my-menu', | 14 | selector: 'my-menu', |
11 | templateUrl: './menu.component.html', | 15 | templateUrl: './menu.component.html', |
12 | styleUrls: [ './menu.component.scss' ] | 16 | styleUrls: ['./menu.component.scss'] |
13 | }) | 17 | }) |
14 | export class MenuComponent implements OnInit { | 18 | export class MenuComponent implements OnInit { |
15 | @ViewChild('languageChooserModal', { static: true }) languageChooserModal: LanguageChooserComponent | 19 | @ViewChild('languageChooserModal', { static: true }) languageChooserModal: LanguageChooserComponent |
16 | @ViewChild('quickSettingsModal', { static: true }) quickSettingsModal: QuickSettingsModalComponent | 20 | @ViewChild('quickSettingsModal', { static: true }) quickSettingsModal: QuickSettingsModalComponent |
17 | 21 | ||
18 | user: User | 22 | user: AuthUser |
19 | isLoggedIn: boolean | 23 | isLoggedIn: boolean |
20 | 24 | ||
21 | userHasAdminAccess = false | 25 | userHasAdminAccess = false |
@@ -25,7 +29,7 @@ export class MenuComponent implements OnInit { | |||
25 | 29 | ||
26 | private languages: VideoConstant<string>[] = [] | 30 | private languages: VideoConstant<string>[] = [] |
27 | private serverConfig: ServerConfig | 31 | private serverConfig: ServerConfig |
28 | private routesPerRight: { [ role in UserRight ]?: string } = { | 32 | private routesPerRight: { [role in UserRight]?: string } = { |
29 | [UserRight.MANAGE_USERS]: '/admin/users', | 33 | [UserRight.MANAGE_USERS]: '/admin/users', |
30 | [UserRight.MANAGE_SERVER_FOLLOW]: '/admin/friends', | 34 | [UserRight.MANAGE_SERVER_FOLLOW]: '/admin/friends', |
31 | [UserRight.MANAGE_ABUSES]: '/admin/moderation/abuses', | 35 | [UserRight.MANAGE_ABUSES]: '/admin/moderation/abuses', |
@@ -62,21 +66,30 @@ export class MenuComponent implements OnInit { | |||
62 | .subscribe(config => this.serverConfig = config) | 66 | .subscribe(config => this.serverConfig = config) |
63 | 67 | ||
64 | this.isLoggedIn = this.authService.isLoggedIn() | 68 | this.isLoggedIn = this.authService.isLoggedIn() |
65 | if (this.isLoggedIn === true) this.user = this.authService.getUser() | 69 | if (this.isLoggedIn === true) { |
66 | this.computeIsUserHasAdminAccess() | 70 | this.user = this.authService.getUser() |
71 | this.computeVideosLink() | ||
72 | } | ||
73 | |||
74 | this.computeAdminAccess() | ||
67 | 75 | ||
68 | this.authService.loginChangedSource.subscribe( | 76 | this.authService.loginChangedSource.subscribe( |
69 | status => { | 77 | status => { |
70 | if (status === AuthStatus.LoggedIn) { | 78 | if (status === AuthStatus.LoggedIn) { |
71 | this.isLoggedIn = true | 79 | this.isLoggedIn = true |
72 | this.user = this.authService.getUser() | 80 | this.user = this.authService.getUser() |
73 | this.computeIsUserHasAdminAccess() | 81 | |
74 | console.log('Logged in.') | 82 | this.computeAdminAccess() |
83 | this.computeVideosLink() | ||
84 | |||
85 | logger('Logged in.') | ||
75 | } else if (status === AuthStatus.LoggedOut) { | 86 | } else if (status === AuthStatus.LoggedOut) { |
76 | this.isLoggedIn = false | 87 | this.isLoggedIn = false |
77 | this.user = undefined | 88 | this.user = undefined |
78 | this.computeIsUserHasAdminAccess() | 89 | |
79 | console.log('Logged out.') | 90 | this.computeAdminAccess() |
91 | |||
92 | logger('Logged out.') | ||
80 | } else { | 93 | } else { |
81 | console.error('Unknown auth status: ' + status) | 94 | console.error('Unknown auth status: ' + status) |
82 | } | 95 | } |
@@ -84,15 +97,15 @@ export class MenuComponent implements OnInit { | |||
84 | ) | 97 | ) |
85 | 98 | ||
86 | this.hotkeysService.cheatSheetToggle | 99 | this.hotkeysService.cheatSheetToggle |
87 | .subscribe(isOpen => this.helpVisible = isOpen) | 100 | .subscribe(isOpen => this.helpVisible = isOpen) |
88 | 101 | ||
89 | this.serverService.getVideoLanguages() | 102 | this.serverService.getVideoLanguages() |
90 | .subscribe(languages => { | 103 | .subscribe(languages => { |
91 | this.languages = languages | 104 | this.languages = languages |
92 | 105 | ||
93 | this.authService.userInformationLoaded | 106 | this.authService.userInformationLoaded |
94 | .subscribe(() => this.buildUserLanguages()) | 107 | .subscribe(() => this.buildUserLanguages()) |
95 | }) | 108 | }) |
96 | } | 109 | } |
97 | 110 | ||
98 | get language () { | 111 | get language () { |
@@ -116,7 +129,7 @@ export class MenuComponent implements OnInit { | |||
116 | 129 | ||
117 | isRegistrationAllowed () { | 130 | isRegistrationAllowed () { |
118 | return this.serverConfig.signup.allowed && | 131 | return this.serverConfig.signup.allowed && |
119 | this.serverConfig.signup.allowedForCurrentIP | 132 | this.serverConfig.signup.allowedForCurrentIP |
120 | } | 133 | } |
121 | 134 | ||
122 | getFirstAdminRightAvailable () { | 135 | getFirstAdminRightAvailable () { |
@@ -172,7 +185,7 @@ export class MenuComponent implements OnInit { | |||
172 | this.user.webTorrentEnabled = !this.user.webTorrentEnabled | 185 | this.user.webTorrentEnabled = !this.user.webTorrentEnabled |
173 | 186 | ||
174 | this.userService.updateMyProfile({ webTorrentEnabled: this.user.webTorrentEnabled }) | 187 | this.userService.updateMyProfile({ webTorrentEnabled: this.user.webTorrentEnabled }) |
175 | .subscribe(() => this.authService.refreshUserInformation()) | 188 | .subscribe(() => this.authService.refreshUserInformation()) |
176 | } | 189 | } |
177 | 190 | ||
178 | langForLocale (localeId: string) { | 191 | langForLocale (localeId: string) { |
@@ -188,18 +201,28 @@ export class MenuComponent implements OnInit { | |||
188 | } | 201 | } |
189 | 202 | ||
190 | if (!this.user.videoLanguages) { | 203 | if (!this.user.videoLanguages) { |
191 | this.videoLanguages = [ this.i18n('any language') ] | 204 | this.videoLanguages = [this.i18n('any language')] |
192 | return | 205 | return |
193 | } | 206 | } |
194 | 207 | ||
195 | this.videoLanguages = this.user.videoLanguages | 208 | this.videoLanguages = this.user.videoLanguages |
196 | .map(locale => this.langForLocale(locale)) | 209 | .map(locale => this.langForLocale(locale)) |
197 | .map(value => value === undefined ? '?' : value) | 210 | .map(value => value === undefined ? '?' : value) |
198 | } | 211 | } |
199 | 212 | ||
200 | private computeIsUserHasAdminAccess () { | 213 | private computeAdminAccess () { |
201 | const right = this.getFirstAdminRightAvailable() | 214 | const right = this.getFirstAdminRightAvailable() |
202 | 215 | ||
203 | this.userHasAdminAccess = right !== undefined | 216 | this.userHasAdminAccess = right !== undefined |
204 | } | 217 | } |
218 | |||
219 | private computeVideosLink () { | ||
220 | this.authService.userInformationLoaded | ||
221 | .pipe( | ||
222 | switchMap(() => this.user.computeCanSeeVideosLink(this.userService.getMyVideoQuotaUsed())) | ||
223 | ).subscribe(res => { | ||
224 | if (res === true) logger('User can see videos link.') | ||
225 | else logger('User cannot see videos link.') | ||
226 | }) | ||
227 | } | ||
205 | } | 228 | } |