1
0
Fork 0
peertube/client/app/app.component.ts

109 lines
2.3 KiB
TypeScript
Raw Normal View History

2016-05-13 12:18:37 +00:00
import { Component } from '@angular/core';
import { HTTP_PROVIDERS } from '@angular/http';
import { RouteConfig, Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated';
2016-03-14 12:50:19 +00:00
import { FriendService } from './friends/index';
import { Search, SearchComponent } from './shared/index';
import {
UserLoginComponent,
AuthService,
AuthStatus
} from './users/index';
import {
VideoAddComponent,
VideoListComponent,
VideoWatchComponent,
VideoService
} from './videos/index';
2016-03-14 12:50:19 +00:00
@RouteConfig([
2016-03-22 14:51:54 +00:00
{
path: '/users/login',
name: 'UserLogin',
component: UserLoginComponent
},
2016-03-14 12:50:19 +00:00
{
path: '/videos/list',
name: 'VideosList',
component: VideoListComponent,
2016-03-14 12:50:19 +00:00
useAsDefault: true
},
{
path: '/videos/watch/:id',
name: 'VideosWatch',
component: VideoWatchComponent
2016-03-14 12:50:19 +00:00
},
{
path: '/videos/add',
name: 'VideosAdd',
component: VideoAddComponent
2016-03-14 12:50:19 +00:00
}
])
@Component({
selector: 'my-app',
templateUrl: 'client/app/app.component.html',
styleUrls: [ 'client/app/app.component.css' ],
directives: [ ROUTER_DIRECTIVES, SearchComponent ],
providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS, VideoService, FriendService, AuthService ]
2016-03-14 12:50:19 +00:00
})
export class AppComponent {
2016-05-27 15:25:52 +00:00
choices = [];
2016-05-27 15:49:18 +00:00
isLoggedIn: boolean;
2016-05-24 21:00:58 +00:00
2016-05-27 15:49:18 +00:00
constructor(
private authService: AuthService,
private friendService: FriendService,
private router: Router
2016-03-22 14:51:54 +00:00
) {
2016-05-27 15:25:52 +00:00
this.isLoggedIn = this.authService.isLoggedIn();
2016-03-22 14:51:54 +00:00
2016-05-27 15:25:52 +00:00
this.authService.loginChangedSource.subscribe(
2016-03-22 14:51:54 +00:00
status => {
if (status === AuthStatus.LoggedIn) {
this.isLoggedIn = true;
}
}
);
}
2016-03-14 21:16:43 +00:00
onSearch(search: Search) {
if (search.value !== '') {
2016-05-24 21:00:58 +00:00
const params = {
2016-05-27 15:49:18 +00:00
field: search.field,
search: search.value
2016-05-24 21:00:58 +00:00
};
2016-05-27 15:25:52 +00:00
this.router.navigate(['VideosList', params]);
2016-03-14 21:16:43 +00:00
} else {
2016-05-27 15:25:52 +00:00
this.router.navigate(['VideosList']);
2016-03-14 21:16:43 +00:00
}
}
2016-03-14 12:50:19 +00:00
2016-03-22 14:51:54 +00:00
logout() {
// this._authService.logout();
}
2016-03-14 12:50:19 +00:00
makeFriends() {
2016-05-27 15:25:52 +00:00
this.friendService.makeFriends().subscribe(
2016-03-14 12:50:19 +00:00
status => {
if (status === 409) {
alert('Already made friends!');
2016-03-14 21:16:43 +00:00
} else {
2016-03-14 12:50:19 +00:00
alert('Made friends!');
}
},
error => alert(error)
2016-04-08 18:58:07 +00:00
);
2016-03-14 12:50:19 +00:00
}
quitFriends() {
2016-05-27 15:25:52 +00:00
this.friendService.quitFriends().subscribe(
2016-03-14 12:50:19 +00:00
status => {
2016-05-27 15:49:18 +00:00
alert('Quit friends!');
2016-03-14 12:50:19 +00:00
},
error => alert(error)
2016-04-08 18:58:07 +00:00
);
2016-03-14 12:50:19 +00:00
}
}