X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fmenu%2Fmenu.component.ts;h=79bf29e9c72501edbe666a39bc702a972fad7cff;hb=5baee5fca418487e72ddcd6419d31bca8659b668;hp=1d7651e78f4f99b157b8cd0bf1abfd780de8045e;hpb=000eb0e40d74e914f6691305511c44e89cd8bf07;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.ts index 1d7651e78..79bf29e9c 100644 --- a/client/src/app/menu/menu.component.ts +++ b/client/src/app/menu/menu.component.ts @@ -1,10 +1,14 @@ import { Component, OnInit, ViewChild } from '@angular/core' import { UserRight } from '../../../../shared/models/users/user-right.enum' -import { AuthService, AuthStatus, RedirectService, ServerService, ThemeService } from '../core' -import { User } from '../shared/users/user.model' +import { AuthService, AuthStatus, RedirectService, ServerService } from '../core' +import { User } from '@app/shared/users/user.model' +import { UserService } from '@app/shared/users/user.service' import { LanguageChooserComponent } from '@app/menu/language-chooser.component' import { HotkeysService } from 'angular2-hotkeys' -import { ServerConfig } from '@shared/models' +import { ServerConfig, VideoConstant } from '@shared/models' +import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component' +import { I18n } from '@ngx-translate/i18n-polyfill' +import { ScreenService } from '@app/shared/misc/screen.service' @Component({ selector: 'my-menu', @@ -13,28 +17,48 @@ import { ServerConfig } from '@shared/models' }) export class MenuComponent implements OnInit { @ViewChild('languageChooserModal', { static: true }) languageChooserModal: LanguageChooserComponent + @ViewChild('quickSettingsModal', { static: true }) quickSettingsModal: QuickSettingsModalComponent user: User isLoggedIn: boolean + userHasAdminAccess = false helpVisible = false + videoLanguages: string[] = [] + + private languages: VideoConstant[] = [] private serverConfig: ServerConfig private routesPerRight: { [ role in UserRight ]?: string } = { [UserRight.MANAGE_USERS]: '/admin/users', [UserRight.MANAGE_SERVER_FOLLOW]: '/admin/friends', [UserRight.MANAGE_VIDEO_ABUSES]: '/admin/moderation/video-abuses', - [UserRight.MANAGE_VIDEO_BLACKLIST]: '/admin/moderation/video-blacklist', + [UserRight.MANAGE_VIDEO_BLOCKS]: '/admin/moderation/video-blocks', [UserRight.MANAGE_JOBS]: '/admin/jobs', [UserRight.MANAGE_CONFIGURATION]: '/admin/config' } constructor ( private authService: AuthService, + private userService: UserService, private serverService: ServerService, private redirectService: RedirectService, - private hotkeysService: HotkeysService - ) {} + private hotkeysService: HotkeysService, + private screenService: ScreenService, + private i18n: I18n + ) { } + + get isInMobileView () { + return this.screenService.isInMobileView() + } + + get placement () { + if (this.isInMobileView) { + return 'left-top auto' + } else { + return 'right-top auto' + } + } ngOnInit () { this.serverConfig = this.serverService.getTmpConfig() @@ -63,9 +87,35 @@ export class MenuComponent implements OnInit { } ) - this.hotkeysService.cheatSheetToggle.subscribe(isOpen => { - this.helpVisible = isOpen - }) + this.hotkeysService.cheatSheetToggle + .subscribe(isOpen => this.helpVisible = isOpen) + + this.serverService.getVideoLanguages() + .subscribe(languages => { + this.languages = languages + + this.authService.userInformationLoaded + .subscribe(() => this.buildUserLanguages()) + }) + } + + get language () { + return this.languageChooserModal.getCurrentLanguage() + } + + get nsfwPolicy () { + if (!this.user) return + + switch (this.user.nsfwPolicy) { + case 'do_not_list': + return this.i18n('hide') + + case 'blur': + return this.i18n('blur') + + case 'display': + return this.i18n('display') + } } isRegistrationAllowed () { @@ -81,7 +131,7 @@ export class MenuComponent implements OnInit { UserRight.MANAGE_USERS, UserRight.MANAGE_SERVER_FOLLOW, UserRight.MANAGE_VIDEO_ABUSES, - UserRight.MANAGE_VIDEO_BLACKLIST, + UserRight.MANAGE_VIDEO_BLOCKS, UserRight.MANAGE_JOBS, UserRight.MANAGE_CONFIGURATION ] @@ -117,6 +167,40 @@ export class MenuComponent implements OnInit { this.hotkeysService.cheatSheetToggle.next(!this.helpVisible) } + openQuickSettings () { + this.quickSettingsModal.show() + } + + toggleUseP2P () { + if (!this.user) return + this.user.webTorrentEnabled = !this.user.webTorrentEnabled + + this.userService.updateMyProfile({ webTorrentEnabled: this.user.webTorrentEnabled }) + .subscribe(() => this.authService.refreshUserInformation()) + } + + langForLocale (localeId: string) { + if (localeId === '_unknown') return this.i18n('Unknown') + + return this.languages.find(lang => lang.id === localeId).label + } + + private buildUserLanguages () { + if (!this.user) { + this.videoLanguages = [] + return + } + + if (!this.user.videoLanguages) { + this.videoLanguages = [ this.i18n('any language') ] + return + } + + this.videoLanguages = this.user.videoLanguages + .map(locale => this.langForLocale(locale)) + .map(value => value === undefined ? '?' : value) + } + private computeIsUserHasAdminAccess () { const right = this.getFirstAdminRightAvailable()