]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/angular/app/app.component.ts
Lint the client
[github/Chocobozzz/PeerTube.git] / client / angular / app / app.component.ts
index 3d41183f2c4029e71f687293a9d55bbe4b55b656..3a6df844aa94f639c0019549e2042e26676fb07a 100644 (file)
@@ -1,14 +1,24 @@
-import { Component, ElementRef } from 'angular2/core';
-import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router';
-import {HTTP_PROVIDERS} from 'angular2/http';
+import { Component } from '@angular/core';
+import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Router } from '@angular/router-deprecated';
+import { HTTP_PROVIDERS } from '@angular/http';
 
 import { VideosAddComponent } from '../videos/components/add/videos-add.component';
 import { VideosListComponent } from '../videos/components/list/videos-list.component';
 import { VideosWatchComponent } from '../videos/components/watch/videos-watch.component';
-import { VideosService } from '../videos/services/videos.service';
+import { VideosService } from '../videos/videos.service';
 import { FriendsService } from '../friends/services/friends.service';
+import { UserLoginComponent } from '../users/components/login/login.component';
+import { AuthService } from '../users/services/auth.service';
+import { AuthStatus } from '../users/models/authStatus';
+import { SearchComponent } from './search.component';
+import { Search } from './search';
 
 @RouteConfig([
+  {
+    path: '/users/login',
+    name: 'UserLogin',
+    component: UserLoginComponent
+  },
   {
     path: '/videos/list',
     name: 'VideosList',
@@ -31,25 +41,53 @@ import { FriendsService } from '../friends/services/friends.service';
     selector: 'my-app',
     templateUrl: 'app/angular/app/app.component.html',
     styleUrls: [ 'app/angular/app/app.component.css' ],
-    directives: [ ROUTER_DIRECTIVES ],
-    providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS, ElementRef, VideosService, FriendsService ]
+    directives: [ ROUTER_DIRECTIVES, SearchComponent ],
+    providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS, VideosService, FriendsService, AuthService ]
 })
 
 export class AppComponent {
-  constructor(private _friendsService: FriendsService) {}
+  isLoggedIn: boolean;
+  search_field: string = name;
+  choices = [  ];
+
+  constructor(private _friendsService: FriendsService,
+              private _authService: AuthService,
+              private _router: Router
+  ) {
+    this.isLoggedIn = this._authService.isLoggedIn();
+
+    this._authService.loginChanged$.subscribe(
+      status => {
+        if (status === AuthStatus.LoggedIn) {
+          this.isLoggedIn = true;
+        }
+      }
+    );
+  }
+
+  onSearch(search: Search) {
+    if (search.value !== '') {
+      this._router.navigate(['VideosList', { search: search.value, field: search.field }]);
+    } else {
+      this._router.navigate(['VideosList']);
+    }
+  }
+
+  logout() {
+    // this._authService.logout();
+  }
 
   makeFriends() {
     this._friendsService.makeFriends().subscribe(
       status => {
         if (status === 409) {
           alert('Already made friends!');
-        }
-        else {
+        } else {
           alert('Made friends!');
         }
       },
       error => alert(error)
-    )
+    );
   }
 
   quitFriends() {
@@ -58,6 +96,6 @@ export class AppComponent {
           alert('Quit friends!');
       },
       error => alert(error)
-    )
+    );
   }
 }