2016-05-13 12:18:37 +00:00
|
|
|
import { Component } from '@angular/core';
|
|
|
|
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Router } from '@angular/router-deprecated';
|
|
|
|
import { HTTP_PROVIDERS } from '@angular/http';
|
2016-03-14 12:50:19 +00: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';
|
2016-05-21 16:03:34 +00:00
|
|
|
import { VideosService } from '../videos/videos.service';
|
2016-03-14 12:50:19 +00:00
|
|
|
import { FriendsService } from '../friends/services/friends.service';
|
2016-03-22 14:51:54 +00:00
|
|
|
import { UserLoginComponent } from '../users/components/login/login.component';
|
|
|
|
import { AuthService } from '../users/services/auth.service';
|
|
|
|
import { AuthStatus } from '../users/models/authStatus';
|
2016-05-23 07:30:18 +00:00
|
|
|
import { SearchComponent } from './search.component';
|
|
|
|
import { Search } from './search';
|
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: 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' ],
|
2016-05-23 07:30:18 +00:00
|
|
|
directives: [ ROUTER_DIRECTIVES, SearchComponent ],
|
2016-04-29 14:51:40 +00:00
|
|
|
providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS, VideosService, FriendsService, AuthService ]
|
2016-03-14 12:50:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
export class AppComponent {
|
2016-03-22 14:51:54 +00:00
|
|
|
isLoggedIn: boolean;
|
2016-05-23 07:30:18 +00:00
|
|
|
search_field: string = name;
|
|
|
|
choices = [ ];
|
2016-03-22 14:51:54 +00:00
|
|
|
|
|
|
|
constructor(private _friendsService: FriendsService,
|
|
|
|
private _authService: AuthService,
|
|
|
|
private _router: Router
|
2016-05-24 21:00:58 +00:00
|
|
|
|
2016-03-22 14:51:54 +00:00
|
|
|
) {
|
2016-04-14 20:07:46 +00:00
|
|
|
this.isLoggedIn = this._authService.isLoggedIn();
|
2016-03-22 14:51:54 +00:00
|
|
|
|
|
|
|
this._authService.loginChanged$.subscribe(
|
|
|
|
status => {
|
|
|
|
if (status === AuthStatus.LoggedIn) {
|
|
|
|
this.isLoggedIn = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2016-03-14 21:16:43 +00:00
|
|
|
|
2016-05-23 07:30:18 +00:00
|
|
|
onSearch(search: Search) {
|
|
|
|
if (search.value !== '') {
|
2016-05-24 21:00:58 +00:00
|
|
|
const params = {
|
|
|
|
search: search.value,
|
|
|
|
field: search.field
|
|
|
|
};
|
|
|
|
this._router.navigate(['VideosList', params]);
|
2016-03-14 21:16:43 +00:00
|
|
|
} else {
|
|
|
|
this._router.navigate(['VideosList']);
|
|
|
|
}
|
|
|
|
}
|
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() {
|
|
|
|
this._friendsService.makeFriends().subscribe(
|
|
|
|
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() {
|
|
|
|
this._friendsService.quitFriends().subscribe(
|
|
|
|
status => {
|
|
|
|
alert('Quit friends!');
|
|
|
|
},
|
|
|
|
error => alert(error)
|
2016-04-08 18:58:07 +00:00
|
|
|
);
|
2016-03-14 12:50:19 +00:00
|
|
|
}
|
|
|
|
}
|