Client: simplify simple menu/admin menu displaying logic

This commit is contained in:
Chocobozzz 2016-08-21 11:27:24 +02:00
parent 9aa46b0c7b
commit beacf6993c
6 changed files with 11 additions and 29 deletions

View File

@ -15,7 +15,7 @@
<div class="panel-block">
<div id="panel-quit-administration" class="panel-button">
<span class="hidden-xs glyphicon glyphicon-cog"></span>
<a [routerLink]="['/videos/list']" (click)="quitAdmin()">Quit admin.</a>
<a [routerLink]="['/videos/list']">Quit admin.</a>
</div>
</div>
</menu>

View File

@ -1,4 +1,4 @@
import { Component, Output, EventEmitter } from '@angular/core';
import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';
@Component({
@ -6,10 +6,4 @@ import { ROUTER_DIRECTIVES } from '@angular/router';
template: require('./menu-admin.component.html'),
directives: [ ROUTER_DIRECTIVES ]
})
export class MenuAdminComponent {
@Output() quittedAdmin = new EventEmitter<boolean>();
quitAdmin() {
this.quittedAdmin.emit(true);
}
}
export class MenuAdminComponent { }

View File

@ -14,14 +14,11 @@
<div class="row">
<my-menu *ngIf="isInAdmin === false" (enteredInAdmin)="onEnteredInAdmin()"></my-menu>
<my-menu-admin *ngIf="isInAdmin === true" (quittedAdmin)="onQuittedAdmin()"></my-menu-admin>
<my-menu *ngIf="isInAdmin() === false"></my-menu>
<my-menu-admin *ngIf="isInAdmin() === true"></my-menu-admin>
<div class="col-md-9 col-sm-8 col-xs-8 router-outlet-container">
<router-outlet></router-outlet>
</div>
</div>
<footer>
PeerTube, CopyLeft 2015-2016

View File

@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';
import { Router, ROUTER_DIRECTIVES } from '@angular/router';
import { MenuAdminComponent } from './admin';
import { MenuComponent } from './menu.component';
@ -15,13 +15,9 @@ import { VideoService } from './videos';
})
export class AppComponent {
isInAdmin = false;
constructor(private router: Router) {}
onEnteredInAdmin() {
this.isInAdmin = true;
}
onQuittedAdmin() {
this.isInAdmin = false;
isInAdmin() {
return this.router.url.indexOf('/admin/') !== -1;
}
}

View File

@ -33,7 +33,7 @@
<div class="panel-block" *ngIf="isUserAdmin()">
<div id="panel-get-videos" class="panel-button">
<span class="hidden-xs glyphicon glyphicon-cog"></span>
<a [routerLink]="['/admin']" (click)="enterInAdmin()">Administration</a>
<a [routerLink]="['/admin']">Administration</a>
</div>
</div>
</menu>

View File

@ -1,4 +1,4 @@
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { Router, ROUTER_DIRECTIVES } from '@angular/router';
import { AuthService, AuthStatus } from './shared';
@ -9,7 +9,6 @@ import { AuthService, AuthStatus } from './shared';
directives: [ ROUTER_DIRECTIVES ]
})
export class MenuComponent implements OnInit {
@Output() enteredInAdmin = new EventEmitter<boolean>();
isLoggedIn: boolean;
constructor (
@ -35,10 +34,6 @@ export class MenuComponent implements OnInit {
);
}
enterInAdmin() {
this.enteredInAdmin.emit(true);
}
isUserAdmin() {
return this.authService.isAdmin();
}