aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/admin/friends
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-08-12 18:22:58 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-08-12 18:22:58 +0200
commite2f555cab7563cd74fa790cea5fc65f2e31b0dc0 (patch)
tree73b68f28c3d8b4521612e5c6de120d2d2614dd70 /client/src/app/admin/friends
parentc323efb9cdc6a605242d112ac0c9db9f67eabaad (diff)
downloadPeerTube-e2f555cab7563cd74fa790cea5fc65f2e31b0dc0.tar.gz
PeerTube-e2f555cab7563cd74fa790cea5fc65f2e31b0dc0.tar.zst
PeerTube-e2f555cab7563cd74fa790cea5fc65f2e31b0dc0.zip
Client: add friends page
Diffstat (limited to 'client/src/app/admin/friends')
-rw-r--r--client/src/app/admin/friends/friend-list/friend-list.component.html21
-rw-r--r--client/src/app/admin/friends/friend-list/friend-list.component.scss3
-rw-r--r--client/src/app/admin/friends/friend-list/friend-list.component.ts46
-rw-r--r--client/src/app/admin/friends/friend-list/index.ts1
-rw-r--r--client/src/app/admin/friends/friend.service.ts29
-rw-r--r--client/src/app/admin/friends/friends.component.ts13
-rw-r--r--client/src/app/admin/friends/friends.routes.ts22
-rw-r--r--client/src/app/admin/friends/index.ts4
-rw-r--r--client/src/app/admin/friends/shared/friend.model.ts3
-rw-r--r--client/src/app/admin/friends/shared/friend.service.ts39
-rw-r--r--client/src/app/admin/friends/shared/index.ts2
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 @@
1table {
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 @@
1import { Component, OnInit } from '@angular/core';
2
3import { 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})
10export 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 @@
1import { Injectable } from '@angular/core';
2import { Response } from '@angular/http';
3import { Observable } from 'rxjs/Observable';
4
5import { AuthHttp, AuthService } from '../../shared';
6
7@Injectable()
8export 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 @@
1import { Component } from '@angular/core';
2import { ROUTER_DIRECTIVES } from '@angular/router';
3
4import { FriendService } from './shared';
5
6@Component({
7 template: '<router-outlet></router-outlet>',
8 directives: [ ROUTER_DIRECTIVES ],
9 providers: [ FriendService ]
10})
11
12export 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 @@
1import { RouterConfig } from '@angular/router';
2
3import { FriendsComponent } from './friends.component';
4import { FriendListComponent } from './friend-list';
5
6export 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 @@
1export * from './friend.service'; 1export * from './shared';
2export * from './friend-list';
3export * 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 @@
1export 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 @@
1import { Injectable } from '@angular/core';
2import { Response } from '@angular/http';
3import { Observable } from 'rxjs/Observable';
4
5import { Friend } from './friend.model';
6import { AuthHttp, AuthService } from '../../../shared';
7
8@Injectable()
9export 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 @@
1export * from './friend.model';
2export * from './friend.service';