aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src
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
parentc323efb9cdc6a605242d112ac0c9db9f67eabaad (diff)
downloadPeerTube-e2f555cab7563cd74fa790cea5fc65f2e31b0dc0.tar.gz
PeerTube-e2f555cab7563cd74fa790cea5fc65f2e31b0dc0.tar.zst
PeerTube-e2f555cab7563cd74fa790cea5fc65f2e31b0dc0.zip
Client: add friends page
Diffstat (limited to 'client/src')
-rw-r--r--client/src/app/admin/admin.routes.ts2
-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
-rw-r--r--client/src/app/admin/menu-admin.component.html9
-rw-r--r--client/src/app/admin/menu-admin.component.ts29
14 files changed, 158 insertions, 65 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 @@
1import { RouterConfig } from '@angular/router'; 1import { RouterConfig } from '@angular/router';
2 2
3import { AdminComponent } from './admin.component'; 3import { AdminComponent } from './admin.component';
4import { FriendsRoutes } from './friends';
4import { UsersRoutes } from './users'; 5import { UsersRoutes } from './users';
5 6
6export const AdminRoutes: RouterConfig = [ 7export 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 @@
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';
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 @@
1import { Component, Output, EventEmitter } from '@angular/core'; 1import { Component, Output, EventEmitter } from '@angular/core';
2import { ROUTER_DIRECTIVES } from '@angular/router'; 2import { ROUTER_DIRECTIVES } from '@angular/router';
3 3
4import { 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})
12export class MenuAdminComponent { 9export 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}