X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fapp.component.ts;h=84435b5dbddcfddc2ab03228bc3b3adcb859c7b9;hb=09700934b90e2ac7b1b9ed1694d9d4d52735e2e1;hp=b7a3d7c58c583e164ff1e62720b25750743a87d8;hpb=0f3a78e7eafa000864f5d9348565d33aedc707e1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index b7a3d7c58..84435b5db 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -1,73 +1,114 @@ -import { Component } from '@angular/core'; -import { ActivatedRoute, Router, ROUTER_DIRECTIVES } from '@angular/router'; - -import { FriendService } from './friends'; -import { - AuthService, - AuthStatus, - SearchComponent, - SearchService -} from './shared'; -import { VideoService } from './videos'; +import { Component, OnInit } from '@angular/core' +import { DomSanitizer, SafeHtml } from '@angular/platform-browser' +import { GuardsCheckStart, Router } from '@angular/router' +import { AuthService, RedirectService, ServerService } from '@app/core' +import { isInSmallView } from '@app/shared/misc/utils' @Component({ - selector: 'my-app', - template: require('./app.component.html'), - styles: [ require('./app.component.scss') ], - directives: [ ROUTER_DIRECTIVES, SearchComponent ], - providers: [ FriendService, VideoService, SearchService ] + selector: 'my-app', + templateUrl: './app.component.html', + styleUrls: [ './app.component.scss' ] }) +export class AppComponent implements OnInit { + notificationOptions = { + timeOut: 5000, + lastOnBottom: true, + clickToClose: true, + maxLength: 0, + maxStack: 7, + showProgressBar: false, + pauseOnHover: false, + preventDuplicates: false, + preventLastDuplicates: 'visible', + rtl: false + } + + isMenuDisplayed = true -export class AppComponent { - choices = []; - isLoggedIn: boolean; + customCSS: SafeHtml - constructor( + constructor ( + private router: Router, private authService: AuthService, - private friendService: FriendService, - private route: ActivatedRoute, - private router: Router - ) { - this.isLoggedIn = this.authService.isLoggedIn(); - - this.authService.loginChangedSource.subscribe( - status => { - if (status === AuthStatus.LoggedIn) { - this.isLoggedIn = true; - console.log('Logged in.'); - } else if (status === AuthStatus.LoggedOut) { - this.isLoggedIn = false; - console.log('Logged out.'); - } else { - console.error('Unknown auth status: ' + status); - } - } - ); + private serverService: ServerService, + private domSanitizer: DomSanitizer, + private redirectService: RedirectService + ) {} + + get serverVersion () { + return this.serverService.getConfig().serverVersion } - logout() { - this.authService.logout(); + get instanceName () { + return this.serverService.getConfig().instance.name } - makeFriends() { - this.friendService.makeFriends().subscribe( - status => { - if (status === 409) { - alert('Already made friends!'); - } else { - alert('Made friends!'); + ngOnInit () { + document.getElementById('incompatible-browser').className += ' browser-ok' + + const pathname = window.location.pathname + if (!pathname || pathname === '/') { + this.redirectService.redirectToHomepage() + } + + this.authService.loadClientCredentials() + + if (this.authService.isLoggedIn()) { + // The service will automatically redirect to the login page if the token is not valid anymore + this.authService.refreshUserInformation() + } + + // Load custom data from server + this.serverService.loadConfig() + this.serverService.loadVideoCategories() + this.serverService.loadVideoLanguages() + this.serverService.loadVideoLicences() + this.serverService.loadVideoPrivacies() + + // Do not display menu on small screens + if (isInSmallView()) { + this.isMenuDisplayed = false + } + + this.router.events.subscribe( + e => { + // User clicked on a link in the menu, change the page + if (e instanceof GuardsCheckStart && isInSmallView()) { + this.isMenuDisplayed = false + } + } + ) + + this.serverService.configLoaded + .subscribe(() => { + const config = this.serverService.getConfig() + + // We test customCSS in case or the admin removed the css + if (this.customCSS || config.instance.customizations.css) { + const styleTag = '' + this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag) } - }, - error => alert(error) - ); + + if (config.instance.customizations.javascript) { + try { + // tslint:disable:no-eval + eval(config.instance.customizations.javascript) + } catch (err) { + console.error('Cannot eval custom JavaScript.', err) + } + } + }) } - quitFriends() { - this.friendService.quitFriends().subscribe( - status => { - alert('Quit friends!'); - }, - error => alert(error) - ); + toggleMenu () { + window.scrollTo(0, 0) + this.isMenuDisplayed = !this.isMenuDisplayed + } + + getMainColClasses () { + // Take all width is the menu is not displayed + if (this.isMenuDisplayed === false) return [ 'expanded' ] + + return [] } }