import { RouterConfig } from '@angular/router';
import { AdminComponent } from './admin.component';
+import { FriendsRoutes } from './friends';
import { UsersRoutes } from './users';
export const AdminRoutes: RouterConfig = [
path: 'admin',
component: AdminComponent,
children: [
+ ...FriendsRoutes,
...UsersRoutes
]
}
--- /dev/null
+<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>
--- /dev/null
+table {
+ margin-bottom: 40px;
+}
--- /dev/null
+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)
+ );
+ }
+}
--- /dev/null
+export * from './friend-list.component';
+++ /dev/null
-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');
- }
-}
--- /dev/null
+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 {
+}
--- /dev/null
+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
+ }
+ ]
+ }
+];
-export * from './friend.service';
+export * from './shared';
+export * from './friend-list';
+export * from './friends.routes';
--- /dev/null
+export interface Friend {
+ url: string;
+}
--- /dev/null
+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');
+ }
+}
--- /dev/null
+export * from './friend.model';
+export * from './friend.service';
<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>
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)
- );
- }
}
"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",