From 7e9334c34db23e5ad1e118151b24c720dd985984 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 20 Nov 2017 11:19:23 +0100 Subject: Add ability to unfollow a server --- .../followers-list/followers-list.component.html | 4 ++-- .../following-list/following-list.component.html | 9 +++++++-- .../following-list/following-list.component.ts | 19 +++++++++++++++++++ .../src/app/+admin/follows/shared/follow.service.ts | 8 +++++++- .../app/+admin/users/user-list/user-list.component.ts | 8 ++------ 5 files changed, 37 insertions(+), 11 deletions(-) (limited to 'client') diff --git a/client/src/app/+admin/follows/followers-list/followers-list.component.html b/client/src/app/+admin/follows/followers-list/followers-list.component.html index 24d75d2b3..549aacdf0 100644 --- a/client/src/app/+admin/follows/followers-list/followers-list.component.html +++ b/client/src/app/+admin/follows/followers-list/followers-list.component.html @@ -7,9 +7,9 @@ sortField="createdAt" (onLazyLoad)="loadLazy($event)" > - + - + diff --git a/client/src/app/+admin/follows/following-list/following-list.component.html b/client/src/app/+admin/follows/following-list/following-list.component.html index fbcebfaa7..dcc03f4a5 100644 --- a/client/src/app/+admin/follows/following-list/following-list.component.html +++ b/client/src/app/+admin/follows/following-list/following-list.component.html @@ -7,10 +7,15 @@ sortField="createdAt" (onLazyLoad)="loadLazy($event)" > - + - + + + + + + diff --git a/client/src/app/+admin/follows/following-list/following-list.component.ts b/client/src/app/+admin/follows/following-list/following-list.component.ts index a1dff1db3..411b8f640 100644 --- a/client/src/app/+admin/follows/following-list/following-list.component.ts +++ b/client/src/app/+admin/follows/following-list/following-list.component.ts @@ -2,6 +2,7 @@ import { Component } from '@angular/core' import { NotificationsService } from 'angular2-notifications' import { SortMeta } from 'primeng/primeng' import { AccountFollow } from '../../../../../../shared/models/accounts/follow.model' +import { ConfirmService } from '../../../core/confirm/confirm.service' import { RestPagination, RestTable } from '../../../shared' import { FollowService } from '../shared' @@ -18,11 +19,29 @@ export class FollowingListComponent extends RestTable { constructor ( private notificationsService: NotificationsService, + private confirmService: ConfirmService, private followService: FollowService ) { super() } + removeFollowing (follow: AccountFollow) { + this.confirmService.confirm(`Do you really want to unfollow ${follow.following.host}?`, 'Unfollow').subscribe( + res => { + if (res === false) return + + this.followService.unfollow(follow).subscribe( + () => { + this.notificationsService.success('Success', `You are not following ${follow.following.host} anymore.`) + this.loadData() + }, + + err => this.notificationsService.error('Error', err.message) + ) + } + ) + } + protected loadData () { this.followService.getFollowing(this.pagination, this.sort) .subscribe( diff --git a/client/src/app/+admin/follows/shared/follow.service.ts b/client/src/app/+admin/follows/shared/follow.service.ts index f66ed477d..0bfbe8eb6 100644 --- a/client/src/app/+admin/follows/shared/follow.service.ts +++ b/client/src/app/+admin/follows/shared/follow.service.ts @@ -37,7 +37,7 @@ export class FollowService { .catch(res => this.restExtractor.handleError(res)) } - follow (notEmptyHosts: String[]) { + follow (notEmptyHosts: string[]) { const body = { hosts: notEmptyHosts } @@ -46,4 +46,10 @@ export class FollowService { .map(this.restExtractor.extractDataBool) .catch(res => this.restExtractor.handleError(res)) } + + unfollow (follow: AccountFollow) { + return this.authHttp.delete(FollowService.BASE_APPLICATION_URL + '/following/' + follow.following.id) + .map(this.restExtractor.extractDataBool) + .catch(res => this.restExtractor.handleError(res)) + } } diff --git a/client/src/app/+admin/users/user-list/user-list.component.ts b/client/src/app/+admin/users/user-list/user-list.component.ts index 6debf89be..1e8e1af49 100644 --- a/client/src/app/+admin/users/user-list/user-list.component.ts +++ b/client/src/app/+admin/users/user-list/user-list.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core' +import { Component } from '@angular/core' import { SortMeta } from 'primeng/components/common/sortmeta' import { NotificationsService } from 'angular2-notifications' @@ -12,7 +12,7 @@ import { UserService } from '../shared' templateUrl: './user-list.component.html', styleUrls: [ './user-list.component.scss' ] }) -export class UserListComponent extends RestTable implements OnInit { +export class UserListComponent extends RestTable { users: User[] = [] totalRecords = 0 rowsPerPage = 10 @@ -27,10 +27,6 @@ export class UserListComponent extends RestTable implements OnInit { super() } - ngOnInit () { - this.loadData() - } - removeUser (user: User) { if (user.username === 'root') { this.notificationsService.error('Error', 'You cannot delete root.') -- cgit v1.2.3