aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/app/app.component.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-27 16:23:10 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-27 16:23:10 +0200
commit41a2aee38cf812510010da09de9bae53590ec119 (patch)
tree79d55d6ae0ef6f66ccb88890cf1ef1946dc65fb4 /client/app/app.component.ts
parent157cb9c9713e08ff70078660a32dd77ecb87eabc (diff)
downloadPeerTube-41a2aee38cf812510010da09de9bae53590ec119.tar.gz
PeerTube-41a2aee38cf812510010da09de9bae53590ec119.tar.zst
PeerTube-41a2aee38cf812510010da09de9bae53590ec119.zip
Follow the angular styleguide for the directories structure
Diffstat (limited to 'client/app/app.component.ts')
-rw-r--r--client/app/app.component.ts109
1 files changed, 109 insertions, 0 deletions
diff --git a/client/app/app.component.ts b/client/app/app.component.ts
new file mode 100644
index 000000000..c94ff79a7
--- /dev/null
+++ b/client/app/app.component.ts
@@ -0,0 +1,109 @@
1import { Component } from '@angular/core';
2import { HTTP_PROVIDERS } from '@angular/http';
3import { RouteConfig, Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated';
4
5import { FriendService } from './friends/index';
6import { Search, SearchComponent } from './shared/index';
7import {
8 UserLoginComponent,
9 AuthService,
10 AuthStatus
11} from './users/index';
12import {
13 VideoAddComponent,
14 VideoListComponent,
15 VideoWatchComponent,
16 VideoService
17} from './videos/index';
18
19@RouteConfig([
20 {
21 path: '/users/login',
22 name: 'UserLogin',
23 component: UserLoginComponent
24 },
25 {
26 path: '/videos/list',
27 name: 'VideosList',
28 component: VideoListComponent,
29 useAsDefault: true
30 },
31 {
32 path: '/videos/watch/:id',
33 name: 'VideosWatch',
34 component: VideoWatchComponent
35 },
36 {
37 path: '/videos/add',
38 name: 'VideosAdd',
39 component: VideoAddComponent
40 }
41])
42
43@Component({
44 selector: 'my-app',
45 templateUrl: 'client/app/app.component.html',
46 styleUrls: [ 'client/app/app.component.css' ],
47 directives: [ ROUTER_DIRECTIVES, SearchComponent ],
48 providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS, VideoService, FriendService, AuthService ]
49})
50
51export class AppComponent {
52 isLoggedIn: boolean;
53 search_field: string = name;
54 choices = [ ];
55
56 constructor(private _friendService: FriendService,
57 private _authService: AuthService,
58 private _router: Router
59
60 ) {
61 this.isLoggedIn = this._authService.isLoggedIn();
62
63 this._authService.loginChanged$.subscribe(
64 status => {
65 if (status === AuthStatus.LoggedIn) {
66 this.isLoggedIn = true;
67 }
68 }
69 );
70 }
71
72 onSearch(search: Search) {
73 if (search.value !== '') {
74 const params = {
75 search: search.value,
76 field: search.field
77 };
78 this._router.navigate(['VideosList', params]);
79 } else {
80 this._router.navigate(['VideosList']);
81 }
82 }
83
84 logout() {
85 // this._authService.logout();
86 }
87
88 makeFriends() {
89 this._friendService.makeFriends().subscribe(
90 status => {
91 if (status === 409) {
92 alert('Already made friends!');
93 } else {
94 alert('Made friends!');
95 }
96 },
97 error => alert(error)
98 );
99 }
100
101 quitFriends() {
102 this._friendService.quitFriends().subscribe(
103 status => {
104 alert('Quit friends!');
105 },
106 error => alert(error)
107 );
108 }
109}