diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/src/app/admin/admin.routes.ts | 2 | ||||
-rw-r--r-- | client/src/app/admin/friends/friend-list/friend-list.component.html | 21 | ||||
-rw-r--r-- | client/src/app/admin/friends/friend-list/friend-list.component.scss | 3 | ||||
-rw-r--r-- | client/src/app/admin/friends/friend-list/friend-list.component.ts | 46 | ||||
-rw-r--r-- | client/src/app/admin/friends/friend-list/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/admin/friends/friend.service.ts | 29 | ||||
-rw-r--r-- | client/src/app/admin/friends/friends.component.ts | 13 | ||||
-rw-r--r-- | client/src/app/admin/friends/friends.routes.ts | 22 | ||||
-rw-r--r-- | client/src/app/admin/friends/index.ts | 4 | ||||
-rw-r--r-- | client/src/app/admin/friends/shared/friend.model.ts | 3 | ||||
-rw-r--r-- | client/src/app/admin/friends/shared/friend.service.ts | 39 | ||||
-rw-r--r-- | client/src/app/admin/friends/shared/index.ts | 2 | ||||
-rw-r--r-- | client/src/app/admin/menu-admin.component.html | 9 | ||||
-rw-r--r-- | client/src/app/admin/menu-admin.component.ts | 29 | ||||
-rw-r--r-- | client/tsconfig.json | 8 |
15 files changed, 165 insertions, 66 deletions
diff --git a/client/src/app/admin/admin.routes.ts b/client/src/app/admin/admin.routes.ts index d375a86af..f57deef62 100644 --- a/client/src/app/admin/admin.routes.ts +++ b/client/src/app/admin/admin.routes.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { RouterConfig } from '@angular/router'; | 1 | import { RouterConfig } from '@angular/router'; |
2 | 2 | ||
3 | import { AdminComponent } from './admin.component'; | 3 | import { AdminComponent } from './admin.component'; |
4 | import { FriendsRoutes } from './friends'; | ||
4 | import { UsersRoutes } from './users'; | 5 | import { UsersRoutes } from './users'; |
5 | 6 | ||
6 | export const AdminRoutes: RouterConfig = [ | 7 | export const AdminRoutes: RouterConfig = [ |
@@ -8,6 +9,7 @@ export const AdminRoutes: RouterConfig = [ | |||
8 | path: 'admin', | 9 | path: 'admin', |
9 | component: AdminComponent, | 10 | component: AdminComponent, |
10 | children: [ | 11 | children: [ |
12 | ...FriendsRoutes, | ||
11 | ...UsersRoutes | 13 | ...UsersRoutes |
12 | ] | 14 | ] |
13 | } | 15 | } |
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'; | ||
diff --git a/client/src/app/admin/menu-admin.component.html b/client/src/app/admin/menu-admin.component.html index 15a3c764e..092ab6081 100644 --- a/client/src/app/admin/menu-admin.component.html +++ b/client/src/app/admin/menu-admin.component.html | |||
@@ -6,14 +6,9 @@ | |||
6 | <a [routerLink]="['/admin/users/list']">List users</a> | 6 | <a [routerLink]="['/admin/users/list']">List users</a> |
7 | </div> | 7 | </div> |
8 | 8 | ||
9 | <div id="panel-make-friends" class="panel-button"> | 9 | <div id="panel-friends" class="panel-button"> |
10 | <span class="hidden-xs glyphicon glyphicon-cloud"></span> | 10 | <span class="hidden-xs glyphicon glyphicon-cloud"></span> |
11 | <a (click)='makeFriends()'>Make friends</a> | 11 | <a [routerLink]="['/admin/friends/list']">Friends</a> |
12 | </div> | ||
13 | |||
14 | <div id="panel-quit-friends" class="panel-button"> | ||
15 | <span class="hidden-xs glyphicon glyphicon-plane"></span> | ||
16 | <a (click)='quitFriends()'>Quit friends</a> | ||
17 | </div> | 12 | </div> |
18 | </div> | 13 | </div> |
19 | 14 | ||
diff --git a/client/src/app/admin/menu-admin.component.ts b/client/src/app/admin/menu-admin.component.ts index eb27c1e58..b23f7409e 100644 --- a/client/src/app/admin/menu-admin.component.ts +++ b/client/src/app/admin/menu-admin.component.ts | |||
@@ -1,42 +1,15 @@ | |||
1 | import { Component, Output, EventEmitter } from '@angular/core'; | 1 | import { Component, Output, EventEmitter } from '@angular/core'; |
2 | import { ROUTER_DIRECTIVES } from '@angular/router'; | 2 | import { ROUTER_DIRECTIVES } from '@angular/router'; |
3 | 3 | ||
4 | import { FriendService } from './friends'; | ||
5 | |||
6 | @Component({ | 4 | @Component({ |
7 | selector: 'my-menu-admin', | 5 | selector: 'my-menu-admin', |
8 | template: require('./menu-admin.component.html'), | 6 | template: require('./menu-admin.component.html'), |
9 | directives: [ ROUTER_DIRECTIVES ], | 7 | directives: [ ROUTER_DIRECTIVES ] |
10 | providers: [ FriendService ] | ||
11 | }) | 8 | }) |
12 | export class MenuAdminComponent { | 9 | export class MenuAdminComponent { |
13 | @Output() quittedAdmin = new EventEmitter<boolean>(); | 10 | @Output() quittedAdmin = new EventEmitter<boolean>(); |
14 | 11 | ||
15 | constructor(private friendService: FriendService) {} | ||
16 | |||
17 | makeFriends() { | ||
18 | this.friendService.makeFriends().subscribe( | ||
19 | status => { | ||
20 | if (status === 409) { | ||
21 | alert('Already made friends!'); | ||
22 | } else { | ||
23 | alert('Made friends!'); | ||
24 | } | ||
25 | }, | ||
26 | error => alert(error) | ||
27 | ); | ||
28 | } | ||
29 | |||
30 | quitAdmin() { | 12 | quitAdmin() { |
31 | this.quittedAdmin.emit(true); | 13 | this.quittedAdmin.emit(true); |
32 | } | 14 | } |
33 | |||
34 | quitFriends() { | ||
35 | this.friendService.quitFriends().subscribe( | ||
36 | status => { | ||
37 | alert('Quit friends!'); | ||
38 | }, | ||
39 | error => alert(error) | ||
40 | ); | ||
41 | } | ||
42 | } | 15 | } |
diff --git a/client/tsconfig.json b/client/tsconfig.json index 157529133..7de2a1a75 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json | |||
@@ -33,8 +33,14 @@ | |||
33 | "src/app/account/index.ts", | 33 | "src/app/account/index.ts", |
34 | "src/app/admin/admin.component.ts", | 34 | "src/app/admin/admin.component.ts", |
35 | "src/app/admin/admin.routes.ts", | 35 | "src/app/admin/admin.routes.ts", |
36 | "src/app/admin/friends/friend.service.ts", | 36 | "src/app/admin/friends/friend-list/friend-list.component.ts", |
37 | "src/app/admin/friends/friend-list/index.ts", | ||
38 | "src/app/admin/friends/friends.routes.ts", | ||
37 | "src/app/admin/friends/index.ts", | 39 | "src/app/admin/friends/index.ts", |
40 | "src/app/admin/friends/shared/friend.model.ts", | ||
41 | "src/app/admin/friends/shared/friend.service.ts", | ||
42 | "src/app/admin/friends/shared/index.ts", | ||
43 | "src/app/admin/friends/users.component.ts", | ||
38 | "src/app/admin/index.ts", | 44 | "src/app/admin/index.ts", |
39 | "src/app/admin/menu-admin.component.ts", | 45 | "src/app/admin/menu-admin.component.ts", |
40 | "src/app/admin/users/index.ts", | 46 | "src/app/admin/users/index.ts", |