diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-11 16:27:07 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-13 14:05:49 +0200 |
commit | c48e82b5e0478434de30626d14594a97f2402e7c (patch) | |
tree | a78e5272bd0fe4f5b41831e571e02d05f1515b82 /client/src/app/+admin/follows/shared | |
parent | a651038487faa838bda3ce04695b08bc65baff70 (diff) | |
download | PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.tar.gz PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.tar.zst PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.zip |
Basic video redundancy implementation
Diffstat (limited to 'client/src/app/+admin/follows/shared')
5 files changed, 82 insertions, 6 deletions
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' | |||
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { SortMeta } from 'primeng/primeng' | 4 | import { SortMeta } from 'primeng/primeng' |
5 | import { Observable } from 'rxjs' | 5 | import { Observable } from 'rxjs' |
6 | import { AccountFollow, ResultList } from '../../../../../../shared' | 6 | import { ActorFollow, ResultList } from '../../../../../../shared' |
7 | import { environment } from '../../../../environments/environment' | 7 | import { environment } from '../../../../environments/environment' |
8 | import { RestExtractor, RestPagination, RestService } from '../../../shared' | 8 | import { RestExtractor, RestPagination, RestService } from '../../../shared' |
9 | 9 | ||
@@ -18,22 +18,22 @@ export class FollowService { | |||
18 | ) { | 18 | ) { |
19 | } | 19 | } |
20 | 20 | ||
21 | getFollowing (pagination: RestPagination, sort: SortMeta): Observable<ResultList<AccountFollow>> { | 21 | getFollowing (pagination: RestPagination, sort: SortMeta): Observable<ResultList<ActorFollow>> { |
22 | let params = new HttpParams() | 22 | let params = new HttpParams() |
23 | params = this.restService.addRestGetParams(params, pagination, sort) | 23 | params = this.restService.addRestGetParams(params, pagination, sort) |
24 | 24 | ||
25 | return this.authHttp.get<ResultList<AccountFollow>>(FollowService.BASE_APPLICATION_URL + '/following', { params }) | 25 | return this.authHttp.get<ResultList<ActorFollow>>(FollowService.BASE_APPLICATION_URL + '/following', { params }) |
26 | .pipe( | 26 | .pipe( |
27 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | 27 | map(res => this.restExtractor.convertResultListDateToHuman(res)), |
28 | catchError(res => this.restExtractor.handleError(res)) | 28 | catchError(res => this.restExtractor.handleError(res)) |
29 | ) | 29 | ) |
30 | } | 30 | } |
31 | 31 | ||
32 | getFollowers (pagination: RestPagination, sort: SortMeta): Observable<ResultList<AccountFollow>> { | 32 | getFollowers (pagination: RestPagination, sort: SortMeta): Observable<ResultList<ActorFollow>> { |
33 | let params = new HttpParams() | 33 | let params = new HttpParams() |
34 | params = this.restService.addRestGetParams(params, pagination, sort) | 34 | params = this.restService.addRestGetParams(params, pagination, sort) |
35 | 35 | ||
36 | return this.authHttp.get<ResultList<AccountFollow>>(FollowService.BASE_APPLICATION_URL + '/followers', { params }) | 36 | return this.authHttp.get<ResultList<ActorFollow>>(FollowService.BASE_APPLICATION_URL + '/followers', { params }) |
37 | .pipe( | 37 | .pipe( |
38 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | 38 | map(res => this.restExtractor.convertResultListDateToHuman(res)), |
39 | catchError(res => this.restExtractor.handleError(res)) | 39 | catchError(res => this.restExtractor.handleError(res)) |
@@ -52,7 +52,7 @@ export class FollowService { | |||
52 | ) | 52 | ) |
53 | } | 53 | } |
54 | 54 | ||
55 | unfollow (follow: AccountFollow) { | 55 | unfollow (follow: ActorFollow) { |
56 | return this.authHttp.delete(FollowService.BASE_APPLICATION_URL + '/following/' + follow.following.host) | 56 | return this.authHttp.delete(FollowService.BASE_APPLICATION_URL + '/following/' + follow.following.host) |
57 | .pipe( | 57 | .pipe( |
58 | map(this.restExtractor.extractDataBool), | 58 | 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 @@ | |||
1 | <my-peertube-checkbox | ||
2 | [inputName]="host + '-redundancy-allowed'" [(ngModel)]="redundancyAllowed" (ngModelChange)="updateRedundancyState()" | ||
3 | ></my-peertube-checkbox> \ 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 @@ | |||
1 | @import '_variables'; | ||
2 | @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 @@ | |||
1 | import { Component, Input } from '@angular/core' | ||
2 | import { AuthService } from '@app/core' | ||
3 | import { RestExtractor } from '@app/shared/rest' | ||
4 | import { RedirectService } from '@app/core/routing/redirect.service' | ||
5 | import { NotificationsService } from 'angular2-notifications' | ||
6 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
7 | import { RedundancyService } from '@app/+admin/follows/shared/redundancy.service' | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-redundancy-checkbox', | ||
11 | templateUrl: './redundancy-checkbox.component.html', | ||
12 | styleUrls: [ './redundancy-checkbox.component.scss' ] | ||
13 | }) | ||
14 | export class RedundancyCheckboxComponent { | ||
15 | @Input() redundancyAllowed: boolean | ||
16 | @Input() host: string | ||
17 | |||
18 | constructor ( | ||
19 | private authService: AuthService, | ||
20 | private restExtractor: RestExtractor, | ||
21 | private redirectService: RedirectService, | ||
22 | private notificationsService: NotificationsService, | ||
23 | private redundancyService: RedundancyService, | ||
24 | private i18n: I18n | ||
25 | ) { } | ||
26 | |||
27 | updateRedundancyState () { | ||
28 | this.redundancyService.updateRedundancy(this.host, this.redundancyAllowed) | ||
29 | .subscribe( | ||
30 | () => { | ||
31 | const stateLabel = this.redundancyAllowed ? this.i18n('enabled') : this.i18n('disabled') | ||
32 | |||
33 | this.notificationsService.success( | ||
34 | this.i18n('Success'), | ||
35 | this.i18n('Redundancy for {{host}} is {{stateLabel}}', { host: this.host, stateLabel }) | ||
36 | ) | ||
37 | }, | ||
38 | |||
39 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
40 | ) | ||
41 | } | ||
42 | } | ||
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 @@ | |||
1 | import { catchError, map } from 'rxjs/operators' | ||
2 | import { HttpClient } from '@angular/common/http' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { RestExtractor, RestService } from '@app/shared' | ||
5 | import { environment } from '../../../../environments/environment' | ||
6 | |||
7 | @Injectable() | ||
8 | export class RedundancyService { | ||
9 | static BASE_USER_SUBSCRIPTIONS_URL = environment.apiUrl + '/api/v1/server/redundancy' | ||
10 | |||
11 | constructor ( | ||
12 | private authHttp: HttpClient, | ||
13 | private restExtractor: RestExtractor, | ||
14 | private restService: RestService | ||
15 | ) { } | ||
16 | |||
17 | updateRedundancy (host: string, redundancyAllowed: boolean) { | ||
18 | const url = RedundancyService.BASE_USER_SUBSCRIPTIONS_URL + '/' + host | ||
19 | |||
20 | const body = { redundancyAllowed } | ||
21 | |||
22 | return this.authHttp.put(url, body) | ||
23 | .pipe( | ||
24 | map(this.restExtractor.extractDataBool), | ||
25 | catchError(err => this.restExtractor.handleError(err)) | ||
26 | ) | ||
27 | } | ||
28 | |||
29 | } | ||