]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Client: add friends page
authorChocobozzz <florian.bigard@gmail.com>
Fri, 12 Aug 2016 16:22:58 +0000 (18:22 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Fri, 12 Aug 2016 16:22:58 +0000 (18:22 +0200)
15 files changed:
client/src/app/admin/admin.routes.ts
client/src/app/admin/friends/friend-list/friend-list.component.html [new file with mode: 0644]
client/src/app/admin/friends/friend-list/friend-list.component.scss [new file with mode: 0644]
client/src/app/admin/friends/friend-list/friend-list.component.ts [new file with mode: 0644]
client/src/app/admin/friends/friend-list/index.ts [new file with mode: 0644]
client/src/app/admin/friends/friend.service.ts [deleted file]
client/src/app/admin/friends/friends.component.ts [new file with mode: 0644]
client/src/app/admin/friends/friends.routes.ts [new file with mode: 0644]
client/src/app/admin/friends/index.ts
client/src/app/admin/friends/shared/friend.model.ts [new file with mode: 0644]
client/src/app/admin/friends/shared/friend.service.ts [new file with mode: 0644]
client/src/app/admin/friends/shared/index.ts [new file with mode: 0644]
client/src/app/admin/menu-admin.component.html
client/src/app/admin/menu-admin.component.ts
client/tsconfig.json

index d375a86af2e920a2a553fb153033da5b62b69cb8..f57deef62dfca4e881bddc530c4dc303733678b8 100644 (file)
@@ -1,6 +1,7 @@
 import { RouterConfig } from '@angular/router';
 
 import { AdminComponent } from './admin.component';
+import { FriendsRoutes } from './friends';
 import { UsersRoutes } from './users';
 
 export const AdminRoutes: RouterConfig = [
@@ -8,6 +9,7 @@ export const AdminRoutes: RouterConfig = [
     path: 'admin',
     component: AdminComponent,
     children: [
+      ...FriendsRoutes,
       ...UsersRoutes
     ]
   }
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 (file)
index 0000000..860bd2c
--- /dev/null
@@ -0,0 +1,21 @@
+<table class="table table-hover">
+  <thead>
+    <tr>
+      <th>Url</th>
+    </tr>
+  </thead>
+
+  <tbody>
+    <tr *ngFor="let friend of friends">
+      <td>{{ friend.url }}</td>
+    </tr>
+  </tbody>
+</table>
+
+<a class="add-user btn btn-danger pull-left" (click)="quitFriends()">
+  Quit friends
+</a>
+
+<a class="add-user btn btn-success pull-right" (click)="makeFriends()">
+  Make friends
+</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 (file)
index 0000000..cb597e1
--- /dev/null
@@ -0,0 +1,3 @@
+table {
+  margin-bottom: 40px;
+}
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 (file)
index 0000000..bf66d3f
--- /dev/null
@@ -0,0 +1,46 @@
+import { Component, OnInit } from '@angular/core';
+
+import { Friend, FriendService } from '../shared';
+
+@Component({
+  selector: 'my-friend-list',
+  template: require('./friend-list.component.html'),
+  styles: [ require('./friend-list.component.scss') ]
+})
+export class FriendListComponent implements OnInit {
+  friends: Friend[];
+
+  constructor(private friendService: FriendService) {  }
+
+  ngOnInit() {
+    this.friendService.getFriends().subscribe(
+      friends => this.friends = friends,
+
+      err => alert(err)
+    );
+  }
+
+  makeFriends() {
+    this.friendService.makeFriends().subscribe(
+      status => {
+        if (status === 409) {
+          alert('Already made friends!');
+        } else {
+          alert('Made friends!');
+        }
+      },
+      error => alert(error)
+    );
+  }
+
+  quitFriends() {
+    if (!confirm('Are you sure?')) return;
+
+    this.friendService.quitFriends().subscribe(
+      status => {
+        alert('Quit friends!');
+      },
+      error => alert(error)
+    );
+  }
+}
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 (file)
index 0000000..354c978
--- /dev/null
@@ -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 (file)
index d4ab5e6..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-import { Injectable } from '@angular/core';
-import { Response } from '@angular/http';
-import { Observable } from 'rxjs/Observable';
-
-import { AuthHttp, AuthService } from '../../shared';
-
-@Injectable()
-export class FriendService {
-  private static BASE_FRIEND_URL: string = '/api/v1/pods/';
-
-  constructor (private authHttp: AuthHttp, private authService: AuthService) {}
-
-  makeFriends() {
-    return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'makefriends')
-                    .map(res => res.status)
-                    .catch(this.handleError);
-  }
-
-  quitFriends() {
-    return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends')
-                    .map(res => res.status)
-                    .catch(this.handleError);
-  }
-
-  private handleError (error: Response): Observable<number> {
-    console.error(error);
-    return Observable.throw(error.json().error || 'Server error');
-  }
-}
diff --git a/client/src/app/admin/friends/friends.component.ts b/client/src/app/admin/friends/friends.component.ts
new file mode 100644 (file)
index 0000000..e66280f
--- /dev/null
@@ -0,0 +1,13 @@
+import { Component } from '@angular/core';
+import { ROUTER_DIRECTIVES } from '@angular/router';
+
+import { FriendService } from './shared';
+
+@Component({
+    template: '<router-outlet></router-outlet>',
+    directives: [ ROUTER_DIRECTIVES ],
+    providers: [ FriendService ]
+})
+
+export class FriendsComponent {
+}
diff --git a/client/src/app/admin/friends/friends.routes.ts b/client/src/app/admin/friends/friends.routes.ts
new file mode 100644 (file)
index 0000000..1e36463
--- /dev/null
@@ -0,0 +1,22 @@
+import { RouterConfig } from '@angular/router';
+
+import { FriendsComponent } from './friends.component';
+import { FriendListComponent } from './friend-list';
+
+export const FriendsRoutes: RouterConfig = [
+  {
+      path: 'friends',
+      component: FriendsComponent,
+      children: [
+        {
+          path: '',
+          redirectTo: 'list',
+          pathMatch: 'full'
+        },
+        {
+          path: 'list',
+          component: FriendListComponent
+        }
+      ]
+    }
+];
index 0adc256c43280b29ac261098e1d7d31a77f82dcb..01aeedeee756fcc5092579be50fd193001736b26 100644 (file)
@@ -1 +1,3 @@
-export * from './friend.service';
+export * from './shared';
+export * from './friend-list';
+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 (file)
index 0000000..847eb9c
--- /dev/null
@@ -0,0 +1,3 @@
+export interface Friend {
+  url: string;
+}
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 (file)
index 0000000..da4d646
--- /dev/null
@@ -0,0 +1,39 @@
+import { Injectable } from '@angular/core';
+import { Response } from '@angular/http';
+import { Observable } from 'rxjs/Observable';
+
+import { Friend } from './friend.model';
+import { AuthHttp, AuthService } from '../../../shared';
+
+@Injectable()
+export class FriendService {
+  private static BASE_FRIEND_URL: string = '/api/v1/pods/';
+
+  constructor (
+    private authHttp: AuthHttp,
+    private authService: AuthService
+  ) {}
+
+  getFriends(): Observable<Friend[]> {
+    return this.authHttp.get(FriendService.BASE_FRIEND_URL)
+                        .map(res => <Friend[]>res.json())
+                        .catch(this.handleError);
+  }
+
+  makeFriends() {
+    return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'makefriends')
+                        .map(res => res.status)
+                        .catch(this.handleError);
+  }
+
+  quitFriends() {
+    return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends')
+                        .map(res => res.status)
+                        .catch(this.handleError);
+  }
+
+  private handleError (error: Response) {
+    console.error(error);
+    return Observable.throw(error.json().error || 'Server error');
+  }
+}
diff --git a/client/src/app/admin/friends/shared/index.ts b/client/src/app/admin/friends/shared/index.ts
new file mode 100644 (file)
index 0000000..0d67163
--- /dev/null
@@ -0,0 +1,2 @@
+export * from './friend.model';
+export * from './friend.service';
index 15a3c764e17de3b3ed058f8b4858d6a5d64802b3..092ab6081d36cb921c6dc39fa533859c1003af4f 100644 (file)
@@ -6,14 +6,9 @@
       <a [routerLink]="['/admin/users/list']">List users</a>
     </div>
 
-    <div id="panel-make-friends" class="panel-button">
+    <div id="panel-friends" class="panel-button">
       <span class="hidden-xs glyphicon glyphicon-cloud"></span>
-      <a (click)='makeFriends()'>Make friends</a>
-    </div>
-
-    <div id="panel-quit-friends" class="panel-button">
-      <span class="hidden-xs glyphicon glyphicon-plane"></span>
-      <a (click)='quitFriends()'>Quit friends</a>
+      <a [routerLink]="['/admin/friends/list']">Friends</a>
     </div>
   </div>
 
index eb27c1e58ca421afc0a7994bdd8560723f4f15df..b23f7409e8016cc0871ece2274202a7ce0bd8ad6 100644 (file)
@@ -1,42 +1,15 @@
 import { Component, Output, EventEmitter } from '@angular/core';
 import { ROUTER_DIRECTIVES } from '@angular/router';
 
-import { FriendService } from './friends';
-
 @Component({
   selector: 'my-menu-admin',
   template: require('./menu-admin.component.html'),
-  directives: [ ROUTER_DIRECTIVES ],
-  providers: [ FriendService ]
+  directives: [ ROUTER_DIRECTIVES ]
 })
 export class MenuAdminComponent {
   @Output() quittedAdmin = new EventEmitter<boolean>();
 
-  constructor(private friendService: FriendService) {}
-
-  makeFriends() {
-    this.friendService.makeFriends().subscribe(
-      status => {
-        if (status === 409) {
-          alert('Already made friends!');
-        } else {
-          alert('Made friends!');
-        }
-      },
-      error => alert(error)
-    );
-  }
-
   quitAdmin() {
     this.quittedAdmin.emit(true);
   }
-
-  quitFriends() {
-    this.friendService.quitFriends().subscribe(
-      status => {
-        alert('Quit friends!');
-      },
-      error => alert(error)
-    );
-  }
 }
index 15752913335a4e00c357ccd4a44c7f2b505ee194..7de2a1a752fe9d8d365a60c753f77cf4e055bf21 100644 (file)
     "src/app/account/index.ts",
     "src/app/admin/admin.component.ts",
     "src/app/admin/admin.routes.ts",
-    "src/app/admin/friends/friend.service.ts",
+    "src/app/admin/friends/friend-list/friend-list.component.ts",
+    "src/app/admin/friends/friend-list/index.ts",
+    "src/app/admin/friends/friends.routes.ts",
     "src/app/admin/friends/index.ts",
+    "src/app/admin/friends/shared/friend.model.ts",
+    "src/app/admin/friends/shared/friend.service.ts",
+    "src/app/admin/friends/shared/index.ts",
+    "src/app/admin/friends/users.component.ts",
     "src/app/admin/index.ts",
     "src/app/admin/menu-admin.component.ts",
     "src/app/admin/users/index.ts",