]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/app.component.ts
Client: make an admin menu and a classic menu component
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
index 444b6b3b4a60af3adfa2a00fd83eb287e7560282..d9549ad5b674f283b04ae14c276b6a4b15b0207e 100644 (file)
@@ -1,79 +1,27 @@
 import { Component } from '@angular/core';
-import { ActivatedRoute, Router, ROUTER_DIRECTIVES } from '@angular/router';
+import { ROUTER_DIRECTIVES } from '@angular/router';
 
-import { FriendService } from './friends';
-import {
-  AuthService,
-  AuthStatus,
-  SearchComponent,
-  SearchService
-} from './shared';
+import { MenuAdminComponent } from './admin';
+import { MenuComponent } from './menu.component';
+import { SearchComponent, SearchService } from './shared';
 import { VideoService } from './videos';
 
 @Component({
     selector: 'my-app',
     template: require('./app.component.html'),
     styles: [ require('./app.component.scss') ],
-    directives: [ ROUTER_DIRECTIVES, SearchComponent ],
-    providers: [ FriendService, VideoService, SearchService ]
+    directives: [ MenuAdminComponent, MenuComponent, ROUTER_DIRECTIVES, SearchComponent ],
+    providers: [ VideoService, SearchService ]
 })
 
 export class AppComponent {
-  choices = [];
-  isLoggedIn: boolean;
+  isInAdmin = false;
 
-  constructor(
-    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);
-        }
-      }
-    );
-  }
-
-  isUserAdmin() {
-    return this.authService.isAdmin();
-  }
-
-  logout() {
-    this.authService.logout();
-    // Redirect to home page
-    this.router.navigate(['/videos/list']);
-  }
-
-  makeFriends() {
-    this.friendService.makeFriends().subscribe(
-      status => {
-        if (status === 409) {
-          alert('Already made friends!');
-        } else {
-          alert('Made friends!');
-        }
-      },
-      error => alert(error)
-    );
+  onEnteredInAdmin() {
+    this.isInAdmin = true;
   }
 
-  quitFriends() {
-    this.friendService.quitFriends().subscribe(
-      status => {
-        alert('Quit friends!');
-      },
-      error => alert(error)
-    );
+  onQuittedAdmin() {
+    this.isInAdmin = false;
   }
 }