PeerTube/client/angular/app/app.component.ts

98 lines
2.5 KiB
TypeScript
Raw Normal View History

2016-03-14 13:50:19 +01:00
import { Component, ElementRef } from 'angular2/core';
2016-03-14 22:16:43 +01:00
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Router } from 'angular2/router';
import { HTTP_PROVIDERS } from 'angular2/http';
2016-03-14 13:50:19 +01:00
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 { FriendsService } from '../friends/services/friends.service';
2016-03-22 15:51:54 +01:00
import { UserLoginComponent } from '../users/components/login/login.component';
import { AuthService } from '../users/services/auth.service';
import { AuthStatus } from '../users/models/authStatus';
2016-03-14 13:50:19 +01:00
@RouteConfig([
2016-03-22 15:51:54 +01:00
{
path: '/users/login',
name: 'UserLogin',
component: UserLoginComponent
},
2016-03-14 13:50:19 +01:00
{
path: '/videos/list',
name: 'VideosList',
component: VideosListComponent,
useAsDefault: true
},
{
path: '/videos/watch/:id',
name: 'VideosWatch',
component: VideosWatchComponent
},
{
path: '/videos/add',
name: 'VideosAdd',
component: VideosAddComponent
}
])
@Component({
selector: 'my-app',
templateUrl: 'app/angular/app/app.component.html',
styleUrls: [ 'app/angular/app/app.component.css' ],
directives: [ ROUTER_DIRECTIVES ],
2016-04-29 16:51:40 +02:00
providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS, VideosService, FriendsService, AuthService ]
2016-03-14 13:50:19 +01:00
})
export class AppComponent {
2016-03-22 15:51:54 +01:00
isLoggedIn: boolean;
constructor(private _friendsService: FriendsService,
private _authService: AuthService,
private _router: Router
) {
this.isLoggedIn = this._authService.isLoggedIn();
2016-03-22 15:51:54 +01:00
this._authService.loginChanged$.subscribe(
status => {
if (status === AuthStatus.LoggedIn) {
this.isLoggedIn = true;
}
}
);
}
2016-03-14 22:16:43 +01:00
doSearch(search: string) {
if (search !== '') {
this._router.navigate(['VideosList', { search: search }]);
} else {
this._router.navigate(['VideosList']);
}
}
2016-03-14 13:50:19 +01:00
2016-03-22 15:51:54 +01:00
logout() {
// this._authService.logout();
}
2016-03-14 13:50:19 +01:00
makeFriends() {
this._friendsService.makeFriends().subscribe(
status => {
if (status === 409) {
alert('Already made friends!');
2016-03-14 22:16:43 +01:00
} else {
2016-03-14 13:50:19 +01:00
alert('Made friends!');
}
},
error => alert(error)
2016-04-08 20:58:07 +02:00
);
2016-03-14 13:50:19 +01:00
}
quitFriends() {
this._friendsService.quitFriends().subscribe(
status => {
alert('Quit friends!');
},
error => alert(error)
2016-04-08 20:58:07 +02:00
);
2016-03-14 13:50:19 +01:00
}
}