PeerTube/client/src/app/app.component.ts

111 lines
2.3 KiB
TypeScript
Raw Normal View History

2016-05-13 07:18:37 -05:00
import { Component } from '@angular/core';
import { HTTP_PROVIDERS } from '@angular/http';
2016-06-10 10:43:40 -05:00
import { Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Routes } from '@angular/router';
2016-03-14 07:50:19 -05:00
import { FriendService } from './friends';
import { LoginComponent } from './login';
import {
AuthService,
AuthStatus,
Search,
SearchComponent
} from './shared';
import {
VideoAddComponent,
VideoListComponent,
VideoWatchComponent,
VideoService
} from './videos';
2016-06-10 10:43:40 -05:00
import { SearchService } from './shared'; // Temporary
2016-03-14 07:50:19 -05:00
2016-06-10 10:43:40 -05:00
@Routes([
2016-03-22 09:51:54 -05:00
{
path: '/users/login',
component: LoginComponent
2016-03-22 09:51:54 -05:00
},
2016-03-14 07:50:19 -05:00
{
path: '/videos/list',
2016-06-10 10:43:40 -05:00
component: VideoListComponent
2016-03-14 07:50:19 -05:00
},
{
path: '/videos/watch/:id',
component: VideoWatchComponent
2016-03-14 07:50:19 -05:00
},
{
path: '/videos/add',
component: VideoAddComponent
2016-06-10 15:08:39 -05:00
},
{
path: '/',
component: VideoListComponent
2016-03-14 07:50:19 -05:00
}
])
@Component({
selector: 'my-app',
template: require('./app.component.html'),
styles: [ require('./app.component.scss') ],
directives: [ ROUTER_DIRECTIVES, SearchComponent ],
2016-06-10 10:43:40 -05:00
providers: [ AuthService, FriendService, HTTP_PROVIDERS, ROUTER_PROVIDERS, VideoService, SearchService ]
2016-03-14 07:50:19 -05:00
})
export class AppComponent {
2016-05-27 10:25:52 -05:00
choices = [];
2016-05-27 10:49:18 -05:00
isLoggedIn: boolean;
2016-05-24 16:00:58 -05:00
2016-05-27 10:49:18 -05:00
constructor(
private authService: AuthService,
private friendService: FriendService,
private router: Router
2016-03-22 09:51:54 -05:00
) {
2016-05-27 10:25:52 -05:00
this.isLoggedIn = this.authService.isLoggedIn();
2016-03-22 09:51:54 -05:00
2016-05-27 10:25:52 -05:00
this.authService.loginChangedSource.subscribe(
2016-03-22 09:51:54 -05:00
status => {
if (status === AuthStatus.LoggedIn) {
this.isLoggedIn = true;
}
}
);
}
2016-03-14 16:16:43 -05:00
onSearch(search: Search) {
if (search.value !== '') {
2016-05-24 16:00:58 -05:00
const params = {
2016-05-27 10:49:18 -05:00
field: search.field,
search: search.value
2016-05-24 16:00:58 -05:00
};
2016-06-10 10:43:40 -05:00
this.router.navigate(['/videos/list', params]);
2016-03-14 16:16:43 -05:00
} else {
2016-06-10 10:43:40 -05:00
this.router.navigate(['/videos/list']);
2016-03-14 16:16:43 -05:00
}
}
2016-03-14 07:50:19 -05:00
2016-06-10 10:43:40 -05:00
// FIXME
2016-03-22 09:51:54 -05:00
logout() {
// this._authService.logout();
}
2016-03-14 07:50:19 -05:00
makeFriends() {
2016-05-27 10:25:52 -05:00
this.friendService.makeFriends().subscribe(
2016-03-14 07:50:19 -05:00
status => {
if (status === 409) {
alert('Already made friends!');
2016-03-14 16:16:43 -05:00
} else {
2016-03-14 07:50:19 -05:00
alert('Made friends!');
}
},
error => alert(error)
2016-04-08 13:58:07 -05:00
);
2016-03-14 07:50:19 -05:00
}
quitFriends() {
2016-05-27 10:25:52 -05:00
this.friendService.quitFriends().subscribe(
2016-03-14 07:50:19 -05:00
status => {
2016-05-27 10:49:18 -05:00
alert('Quit friends!');
2016-03-14 07:50:19 -05:00
},
error => alert(error)
2016-04-08 13:58:07 -05:00
);
2016-03-14 07:50:19 -05:00
}
}