Client: add friends page
This commit is contained in:
parent
c323efb9cd
commit
e2f555cab7
|
@ -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
|
||||
]
|
||||
}
|
||||
|
|
|
@ -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>
|
|
@ -0,0 +1,3 @@
|
|||
table {
|
||||
margin-bottom: 40px;
|
||||
}
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
export * from './friend-list.component';
|
|
@ -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');
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
}
|
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
|
@ -1 +1,3 @@
|
|||
export * from './friend.service';
|
||||
export * from './shared';
|
||||
export * from './friend-list';
|
||||
export * from './friends.routes';
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
export interface Friend {
|
||||
url: string;
|
||||
}
|
|
@ -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');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
export * from './friend.model';
|
||||
export * from './friend.service';
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,14 @@
|
|||
"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",
|
||||
|
|
Loading…
Reference in New Issue