From d5f5a670fcf6258d0facf9a2fd3aabd550fbc78f Mon Sep 17 00:00:00 2001 From: Green-Star Date: Wed, 2 Aug 2017 21:50:42 +0200 Subject: Remove one pod (#76) * Client: Fix typo * Client: Add removeFriend feature * Server: Add removeFriend feature * Server: Update method name * Fix rebase onto develop issues * Server: Fix error message * Server: Remove useless methods in removeFriend method * Server: Finish remove on pod feature after rebase * Server: Type pod parameter * Fix Travis build * Add friend-basic test for the remove one pod feature * Add check-params tests for the remove one pod feature * Fix typos * Add friend-advanced test for the remove one pod feature * Client: Trailing new line * Move to promises * Add undefined id test * Use find method instead of a for loop to find the friend to remove * Remove setTimeout method * Server: Remove requestScheduler operations * Server: Fix logging messages * Server: Remove sign request parameter --- .../friends/friend-list/friend-list.component.html | 2 +- .../friends/friend-list/friend-list.component.ts | 30 +++++++++++++++++++--- .../app/+admin/friends/shared/friend.service.ts | 9 ++++++- 3 files changed, 36 insertions(+), 5 deletions(-) (limited to 'client') 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 index 45695f7c8..7b9fff304 100644 --- a/client/src/app/+admin/friends/friend-list/friend-list.component.html +++ b/client/src/app/+admin/friends/friend-list/friend-list.component.html @@ -2,7 +2,7 @@

Friends list

- + Quit friends 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 index 9f0256d7f..822a112cc 100644 --- a/client/src/app/+admin/friends/friend-list/friend-list.component.ts +++ b/client/src/app/+admin/friends/friend-list/friend-list.component.ts @@ -6,6 +6,7 @@ import { ServerDataSource } from 'ng2-smart-table' import { ConfirmService } from '../../../core' import { Utils } from '../../../shared' import { FriendService } from '../shared' +import { Pod } from '../../../../../../shared' @Component({ selector: 'my-friend-list', @@ -15,6 +16,7 @@ import { FriendService } from '../shared' export class FriendListComponent { friendsSource = null tableSettings = { + mode: 'external', attr: { class: 'table-hover' }, @@ -23,7 +25,10 @@ export class FriendListComponent { position: 'right', add: false, edit: false, - delete: false + delete: true + }, + delete: { + deleteButtonContent: Utils.getRowDeleteButton() }, columns: { id: { @@ -71,8 +76,7 @@ export class FriendListComponent { this.friendService.quitFriends().subscribe( status => { - this.notificationsService.success('Sucess', 'Friends left!') - + this.notificationsService.success('Success', 'Friends left!') this.friendsSource.refresh() }, @@ -81,4 +85,24 @@ export class FriendListComponent { } ) } + + removeFriend ({ data }) { + const confirmMessage = 'Do you really want to remove this friend ? All its videos will be deleted.' + const friend: Pod = data + + this.confirmService.confirm(confirmMessage, 'Remove').subscribe( + res => { + if (res === false) return + + this.friendService.removeFriend(friend).subscribe( + status => { + this.notificationsService.success('Success', 'Friend removed') + this.friendsSource.refresh() + }, + + err => this.notificationsService.error('Error', err.text) + ) + } + ) + } } diff --git a/client/src/app/+admin/friends/shared/friend.service.ts b/client/src/app/+admin/friends/shared/friend.service.ts index 79de4470e..8bc0239ab 100644 --- a/client/src/app/+admin/friends/shared/friend.service.ts +++ b/client/src/app/+admin/friends/shared/friend.service.ts @@ -6,6 +6,7 @@ import 'rxjs/add/operator/map' import { ServerDataSource } from 'ng2-smart-table' import { AuthHttp, RestExtractor, RestDataSource, ResultList } from '../../../shared' +import { Pod } from '../../../../../../shared' @Injectable() export class FriendService { @@ -20,7 +21,7 @@ export class FriendService { return new RestDataSource(this.authHttp, FriendService.BASE_FRIEND_URL) } - makeFriends (notEmptyHosts) { + makeFriends (notEmptyHosts: String[]) { const body = { hosts: notEmptyHosts } @@ -35,4 +36,10 @@ export class FriendService { .map(res => res.status) .catch((res) => this.restExtractor.handleError(res)) } + + removeFriend (friend: Pod) { + return this.authHttp.delete(FriendService.BASE_FRIEND_URL + friend.id) + .map(this.restExtractor.extractDataBool) + .catch((res) => this.restExtractor.handleError(res)) + } } -- cgit v1.2.3