diff options
Diffstat (limited to 'client/src/app/admin/friends')
11 files changed, 153 insertions, 30 deletions
diff --git a/client/src/app/admin/friends/friend-list/friend-list.component.html b/client/src/app/admin/friends/friend-list/friend-list.component.html new file mode 100644 index 000000000..860bd2c07 --- /dev/null +++ b/client/src/app/admin/friends/friend-list/friend-list.component.html | |||
@@ -0,0 +1,21 @@ | |||
1 | <table class="table table-hover"> | ||
2 | <thead> | ||
3 | <tr> | ||
4 | <th>Url</th> | ||
5 | </tr> | ||
6 | </thead> | ||
7 | |||
8 | <tbody> | ||
9 | <tr *ngFor="let friend of friends"> | ||
10 | <td>{{ friend.url }}</td> | ||
11 | </tr> | ||
12 | </tbody> | ||
13 | </table> | ||
14 | |||
15 | <a class="add-user btn btn-danger pull-left" (click)="quitFriends()"> | ||
16 | Quit friends | ||
17 | </a> | ||
18 | |||
19 | <a class="add-user btn btn-success pull-right" (click)="makeFriends()"> | ||
20 | Make friends | ||
21 | </a> | ||
diff --git a/client/src/app/admin/friends/friend-list/friend-list.component.scss b/client/src/app/admin/friends/friend-list/friend-list.component.scss new file mode 100644 index 000000000..cb597e12b --- /dev/null +++ b/client/src/app/admin/friends/friend-list/friend-list.component.scss | |||
@@ -0,0 +1,3 @@ | |||
1 | table { | ||
2 | margin-bottom: 40px; | ||
3 | } | ||
diff --git a/client/src/app/admin/friends/friend-list/friend-list.component.ts b/client/src/app/admin/friends/friend-list/friend-list.component.ts new file mode 100644 index 000000000..bf66d3ff1 --- /dev/null +++ b/client/src/app/admin/friends/friend-list/friend-list.component.ts | |||
@@ -0,0 +1,46 @@ | |||
1 | import { Component, OnInit } from '@angular/core'; | ||
2 | |||
3 | import { Friend, FriendService } from '../shared'; | ||
4 | |||
5 | @Component({ | ||
6 | selector: 'my-friend-list', | ||
7 | template: require('./friend-list.component.html'), | ||
8 | styles: [ require('./friend-list.component.scss') ] | ||
9 | }) | ||
10 | export class FriendListComponent implements OnInit { | ||
11 | friends: Friend[]; | ||
12 | |||
13 | constructor(private friendService: FriendService) { } | ||
14 | |||
15 | ngOnInit() { | ||
16 | this.friendService.getFriends().subscribe( | ||
17 | friends => this.friends = friends, | ||
18 | |||
19 | err => alert(err) | ||
20 | ); | ||
21 | } | ||
22 | |||
23 | makeFriends() { | ||
24 | this.friendService.makeFriends().subscribe( | ||
25 | status => { | ||
26 | if (status === 409) { | ||
27 | alert('Already made friends!'); | ||
28 | } else { | ||
29 | alert('Made friends!'); | ||
30 | } | ||
31 | }, | ||
32 | error => alert(error) | ||
33 | ); | ||
34 | } | ||
35 | |||
36 | quitFriends() { | ||
37 | if (!confirm('Are you sure?')) return; | ||
38 | |||
39 | this.friendService.quitFriends().subscribe( | ||
40 | status => { | ||
41 | alert('Quit friends!'); | ||
42 | }, | ||
43 | error => alert(error) | ||
44 | ); | ||
45 | } | ||
46 | } | ||
diff --git a/client/src/app/admin/friends/friend-list/index.ts b/client/src/app/admin/friends/friend-list/index.ts new file mode 100644 index 000000000..354c978a4 --- /dev/null +++ b/client/src/app/admin/friends/friend-list/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './friend-list.component'; | |||
diff --git a/client/src/app/admin/friends/friend.service.ts b/client/src/app/admin/friends/friend.service.ts deleted file mode 100644 index d4ab5e60f..000000000 --- a/client/src/app/admin/friends/friend.service.ts +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | import { Injectable } from '@angular/core'; | ||
2 | import { Response } from '@angular/http'; | ||
3 | import { Observable } from 'rxjs/Observable'; | ||
4 | |||
5 | import { AuthHttp, AuthService } from '../../shared'; | ||
6 | |||
7 | @Injectable() | ||
8 | export class FriendService { | ||
9 | private static BASE_FRIEND_URL: string = '/api/v1/pods/'; | ||
10 | |||
11 | constructor (private authHttp: AuthHttp, private authService: AuthService) {} | ||
12 | |||
13 | makeFriends() { | ||
14 | return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'makefriends') | ||
15 | .map(res => res.status) | ||
16 | .catch(this.handleError); | ||
17 | } | ||
18 | |||
19 | quitFriends() { | ||
20 | return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends') | ||
21 | .map(res => res.status) | ||
22 | .catch(this.handleError); | ||
23 | } | ||
24 | |||
25 | private handleError (error: Response): Observable<number> { | ||
26 | console.error(error); | ||
27 | return Observable.throw(error.json().error || 'Server error'); | ||
28 | } | ||
29 | } | ||
diff --git a/client/src/app/admin/friends/friends.component.ts b/client/src/app/admin/friends/friends.component.ts new file mode 100644 index 000000000..e66280f01 --- /dev/null +++ b/client/src/app/admin/friends/friends.component.ts | |||
@@ -0,0 +1,13 @@ | |||
1 | import { Component } from '@angular/core'; | ||
2 | import { ROUTER_DIRECTIVES } from '@angular/router'; | ||
3 | |||
4 | import { FriendService } from './shared'; | ||
5 | |||
6 | @Component({ | ||
7 | template: '<router-outlet></router-outlet>', | ||
8 | directives: [ ROUTER_DIRECTIVES ], | ||
9 | providers: [ FriendService ] | ||
10 | }) | ||
11 | |||
12 | export class FriendsComponent { | ||
13 | } | ||
diff --git a/client/src/app/admin/friends/friends.routes.ts b/client/src/app/admin/friends/friends.routes.ts new file mode 100644 index 000000000..1e3646395 --- /dev/null +++ b/client/src/app/admin/friends/friends.routes.ts | |||
@@ -0,0 +1,22 @@ | |||
1 | import { RouterConfig } from '@angular/router'; | ||
2 | |||
3 | import { FriendsComponent } from './friends.component'; | ||
4 | import { FriendListComponent } from './friend-list'; | ||
5 | |||
6 | export const FriendsRoutes: RouterConfig = [ | ||
7 | { | ||
8 | path: 'friends', | ||
9 | component: FriendsComponent, | ||
10 | children: [ | ||
11 | { | ||
12 | path: '', | ||
13 | redirectTo: 'list', | ||
14 | pathMatch: 'full' | ||
15 | }, | ||
16 | { | ||
17 | path: 'list', | ||
18 | component: FriendListComponent | ||
19 | } | ||
20 | ] | ||
21 | } | ||
22 | ]; | ||
diff --git a/client/src/app/admin/friends/index.ts b/client/src/app/admin/friends/index.ts index 0adc256c4..01aeedeee 100644 --- a/client/src/app/admin/friends/index.ts +++ b/client/src/app/admin/friends/index.ts | |||
@@ -1 +1,3 @@ | |||
1 | export * from './friend.service'; | 1 | export * from './shared'; |
2 | export * from './friend-list'; | ||
3 | export * from './friends.routes'; | ||
diff --git a/client/src/app/admin/friends/shared/friend.model.ts b/client/src/app/admin/friends/shared/friend.model.ts new file mode 100644 index 000000000..847eb9c9c --- /dev/null +++ b/client/src/app/admin/friends/shared/friend.model.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export interface Friend { | ||
2 | url: string; | ||
3 | } | ||
diff --git a/client/src/app/admin/friends/shared/friend.service.ts b/client/src/app/admin/friends/shared/friend.service.ts new file mode 100644 index 000000000..da4d64611 --- /dev/null +++ b/client/src/app/admin/friends/shared/friend.service.ts | |||
@@ -0,0 +1,39 @@ | |||
1 | import { Injectable } from '@angular/core'; | ||
2 | import { Response } from '@angular/http'; | ||
3 | import { Observable } from 'rxjs/Observable'; | ||
4 | |||
5 | import { Friend } from './friend.model'; | ||
6 | import { AuthHttp, AuthService } from '../../../shared'; | ||
7 | |||
8 | @Injectable() | ||
9 | export class FriendService { | ||
10 | private static BASE_FRIEND_URL: string = '/api/v1/pods/'; | ||
11 | |||
12 | constructor ( | ||
13 | private authHttp: AuthHttp, | ||
14 | private authService: AuthService | ||
15 | ) {} | ||
16 | |||
17 | getFriends(): Observable<Friend[]> { | ||
18 | return this.authHttp.get(FriendService.BASE_FRIEND_URL) | ||
19 | .map(res => <Friend[]>res.json()) | ||
20 | .catch(this.handleError); | ||
21 | } | ||
22 | |||
23 | makeFriends() { | ||
24 | return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'makefriends') | ||
25 | .map(res => res.status) | ||
26 | .catch(this.handleError); | ||
27 | } | ||
28 | |||
29 | quitFriends() { | ||
30 | return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends') | ||
31 | .map(res => res.status) | ||
32 | .catch(this.handleError); | ||
33 | } | ||
34 | |||
35 | private handleError (error: Response) { | ||
36 | console.error(error); | ||
37 | return Observable.throw(error.json().error || 'Server error'); | ||
38 | } | ||
39 | } | ||
diff --git a/client/src/app/admin/friends/shared/index.ts b/client/src/app/admin/friends/shared/index.ts new file mode 100644 index 000000000..0d671637d --- /dev/null +++ b/client/src/app/admin/friends/shared/index.ts | |||
@@ -0,0 +1,2 @@ | |||
1 | export * from './friend.model'; | ||
2 | export * from './friend.service'; | ||