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 --- .../followers-list/followers-list.component.ts | 4 +-- .../following-list/following-list.component.html | 6 ++++ .../following-list/following-list.component.scss | 13 +++++++ .../following-list/following-list.component.ts | 9 ++--- .../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 +++++++++++++++ 9 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 client/src/app/+admin/follows/following-list/following-list.component.scss 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') diff --git a/client/src/app/+admin/follows/followers-list/followers-list.component.ts b/client/src/app/+admin/follows/followers-list/followers-list.component.ts index 96fb67588..ca993dcd3 100644 --- a/client/src/app/+admin/follows/followers-list/followers-list.component.ts +++ b/client/src/app/+admin/follows/followers-list/followers-list.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core' import { NotificationsService } from 'angular2-notifications' import { SortMeta } from 'primeng/primeng' -import { AccountFollow } from '../../../../../../shared/models/actors/follow.model' +import { ActorFollow } from '../../../../../../shared/models/actors/follow.model' import { RestPagination, RestTable } from '../../../shared' import { FollowService } from '../shared' import { I18n } from '@ngx-translate/i18n-polyfill' @@ -13,7 +13,7 @@ import { I18n } from '@ngx-translate/i18n-polyfill' styleUrls: [ './followers-list.component.scss' ] }) export class FollowersListComponent extends RestTable implements OnInit { - followers: AccountFollow[] = [] + followers: ActorFollow[] = [] totalRecords = 0 rowsPerPage = 10 sort: SortMeta = { field: 'createdAt', order: 1 } 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 e4a45e88c..66ab64c50 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 @@ -8,6 +8,7 @@ Host State Created + Redundancy allowed @@ -18,6 +19,11 @@ {{ follow.following.host }} {{ follow.state }} {{ follow.createdAt }} + + + diff --git a/client/src/app/+admin/follows/following-list/following-list.component.scss b/client/src/app/+admin/follows/following-list/following-list.component.scss new file mode 100644 index 000000000..bfcdcaa49 --- /dev/null +++ b/client/src/app/+admin/follows/following-list/following-list.component.scss @@ -0,0 +1,13 @@ +@import '_variables'; +@import '_mixins'; + +my-redundancy-checkbox /deep/ my-peertube-checkbox { + .form-group { + margin-bottom: 0; + align-items: center; + } + + label { + margin: 0; + } +} \ No newline at end of file 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 06e341e68..dd57884c6 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 @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core' import { NotificationsService } from 'angular2-notifications' import { SortMeta } from 'primeng/primeng' -import { AccountFollow } from '../../../../../../shared/models/actors/follow.model' +import { ActorFollow } from '../../../../../../shared/models/actors/follow.model' import { ConfirmService } from '../../../core/confirm/confirm.service' import { RestPagination, RestTable } from '../../../shared' import { FollowService } from '../shared' @@ -9,10 +9,11 @@ import { I18n } from '@ngx-translate/i18n-polyfill' @Component({ selector: 'my-followers-list', - templateUrl: './following-list.component.html' + templateUrl: './following-list.component.html', + styleUrls: [ './following-list.component.scss' ] }) export class FollowingListComponent extends RestTable implements OnInit { - following: AccountFollow[] = [] + following: ActorFollow[] = [] totalRecords = 0 rowsPerPage = 10 sort: SortMeta = { field: 'createdAt', order: 1 } @@ -31,7 +32,7 @@ export class FollowingListComponent extends RestTable implements OnInit { this.loadSort() } - async removeFollowing (follow: AccountFollow) { + async removeFollowing (follow: ActorFollow) { const res = await this.confirmService.confirm( this.i18n('Do you really want to unfollow {{host}}?', { host: follow.following.host }), this.i18n('Unfollow') 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