From c48e82b5e0478434de30626d14594a97f2402e7c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 Sep 2018 16:27:07 +0200 Subject: Basic video redundancy implementation --- .../app/+admin/follows/shared/follow.service.ts | 12 +++---- .../shared/redundancy-checkbox.component.html | 3 ++ .../shared/redundancy-checkbox.component.scss | 2 ++ .../shared/redundancy-checkbox.component.ts | 42 ++++++++++++++++++++++ .../+admin/follows/shared/redundancy.service.ts | 29 +++++++++++++++ 5 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 client/src/app/+admin/follows/shared/redundancy-checkbox.component.html create mode 100644 client/src/app/+admin/follows/shared/redundancy-checkbox.component.scss create mode 100644 client/src/app/+admin/follows/shared/redundancy-checkbox.component.ts create mode 100644 client/src/app/+admin/follows/shared/redundancy.service.ts (limited to 'client/src/app/+admin/follows/shared') diff --git a/client/src/app/+admin/follows/shared/follow.service.ts b/client/src/app/+admin/follows/shared/follow.service.ts index 87ea5fb0c..27169a9cd 100644 --- a/client/src/app/+admin/follows/shared/follow.service.ts +++ b/client/src/app/+admin/follows/shared/follow.service.ts @@ -3,7 +3,7 @@ import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { SortMeta } from 'primeng/primeng' import { Observable } from 'rxjs' -import { AccountFollow, ResultList } from '../../../../../../shared' +import { ActorFollow, ResultList } from '../../../../../../shared' import { environment } from '../../../../environments/environment' import { RestExtractor, RestPagination, RestService } from '../../../shared' @@ -18,22 +18,22 @@ export class FollowService { ) { } - getFollowing (pagination: RestPagination, sort: SortMeta): Observable> { + getFollowing (pagination: RestPagination, sort: SortMeta): Observable> { let params = new HttpParams() params = this.restService.addRestGetParams(params, pagination, sort) - return this.authHttp.get>(FollowService.BASE_APPLICATION_URL + '/following', { params }) + return this.authHttp.get>(FollowService.BASE_APPLICATION_URL + '/following', { params }) .pipe( map(res => this.restExtractor.convertResultListDateToHuman(res)), catchError(res => this.restExtractor.handleError(res)) ) } - getFollowers (pagination: RestPagination, sort: SortMeta): Observable> { + getFollowers (pagination: RestPagination, sort: SortMeta): Observable> { let params = new HttpParams() params = this.restService.addRestGetParams(params, pagination, sort) - return this.authHttp.get>(FollowService.BASE_APPLICATION_URL + '/followers', { params }) + return this.authHttp.get>(FollowService.BASE_APPLICATION_URL + '/followers', { params }) .pipe( map(res => this.restExtractor.convertResultListDateToHuman(res)), catchError(res => this.restExtractor.handleError(res)) @@ -52,7 +52,7 @@ export class FollowService { ) } - unfollow (follow: AccountFollow) { + unfollow (follow: ActorFollow) { return this.authHttp.delete(FollowService.BASE_APPLICATION_URL + '/following/' + follow.following.host) .pipe( map(this.restExtractor.extractDataBool), diff --git a/client/src/app/+admin/follows/shared/redundancy-checkbox.component.html b/client/src/app/+admin/follows/shared/redundancy-checkbox.component.html new file mode 100644 index 000000000..8a57d65f0 --- /dev/null +++ b/client/src/app/+admin/follows/shared/redundancy-checkbox.component.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/client/src/app/+admin/follows/shared/redundancy-checkbox.component.scss b/client/src/app/+admin/follows/shared/redundancy-checkbox.component.scss new file mode 100644 index 000000000..5e6774739 --- /dev/null +++ b/client/src/app/+admin/follows/shared/redundancy-checkbox.component.scss @@ -0,0 +1,2 @@ +@import '_variables'; +@import '_mixins'; diff --git a/client/src/app/+admin/follows/shared/redundancy-checkbox.component.ts b/client/src/app/+admin/follows/shared/redundancy-checkbox.component.ts new file mode 100644 index 000000000..ff4725e91 --- /dev/null +++ b/client/src/app/+admin/follows/shared/redundancy-checkbox.component.ts @@ -0,0 +1,42 @@ +import { Component, Input } from '@angular/core' +import { AuthService } from '@app/core' +import { RestExtractor } from '@app/shared/rest' +import { RedirectService } from '@app/core/routing/redirect.service' +import { NotificationsService } from 'angular2-notifications' +import { I18n } from '@ngx-translate/i18n-polyfill' +import { RedundancyService } from '@app/+admin/follows/shared/redundancy.service' + +@Component({ + selector: 'my-redundancy-checkbox', + templateUrl: './redundancy-checkbox.component.html', + styleUrls: [ './redundancy-checkbox.component.scss' ] +}) +export class RedundancyCheckboxComponent { + @Input() redundancyAllowed: boolean + @Input() host: string + + constructor ( + private authService: AuthService, + private restExtractor: RestExtractor, + private redirectService: RedirectService, + private notificationsService: NotificationsService, + private redundancyService: RedundancyService, + private i18n: I18n + ) { } + + updateRedundancyState () { + this.redundancyService.updateRedundancy(this.host, this.redundancyAllowed) + .subscribe( + () => { + const stateLabel = this.redundancyAllowed ? this.i18n('enabled') : this.i18n('disabled') + + this.notificationsService.success( + this.i18n('Success'), + this.i18n('Redundancy for {{host}} is {{stateLabel}}', { host: this.host, stateLabel }) + ) + }, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } +} diff --git a/client/src/app/+admin/follows/shared/redundancy.service.ts b/client/src/app/+admin/follows/shared/redundancy.service.ts new file mode 100644 index 000000000..96b29faab --- /dev/null +++ b/client/src/app/+admin/follows/shared/redundancy.service.ts @@ -0,0 +1,29 @@ +import { catchError, map } from 'rxjs/operators' +import { HttpClient } from '@angular/common/http' +import { Injectable } from '@angular/core' +import { RestExtractor, RestService } from '@app/shared' +import { environment } from '../../../../environments/environment' + +@Injectable() +export class RedundancyService { + static BASE_USER_SUBSCRIPTIONS_URL = environment.apiUrl + '/api/v1/server/redundancy' + + constructor ( + private authHttp: HttpClient, + private restExtractor: RestExtractor, + private restService: RestService + ) { } + + updateRedundancy (host: string, redundancyAllowed: boolean) { + const url = RedundancyService.BASE_USER_SUBSCRIPTIONS_URL + '/' + host + + const body = { redundancyAllowed } + + return this.authHttp.put(url, body) + .pipe( + map(this.restExtractor.extractDataBool), + catchError(err => this.restExtractor.handleError(err)) + ) + } + +} -- cgit v1.2.3