diff options
Diffstat (limited to 'client/src/app/shared')
-rw-r--r-- | client/src/app/shared/shared-users/user-admin.service.ts | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/client/src/app/shared/shared-users/user-admin.service.ts b/client/src/app/shared/shared-users/user-admin.service.ts index 6224f0bd5..b18a36241 100644 --- a/client/src/app/shared/shared-users/user-admin.service.ts +++ b/client/src/app/shared/shared-users/user-admin.service.ts | |||
@@ -1,12 +1,12 @@ | |||
1 | import { SortMeta } from 'primeng/api' | 1 | import { SortMeta } from 'primeng/api' |
2 | import { from, Observable } from 'rxjs' | 2 | import { from, Observable } from 'rxjs' |
3 | import { catchError, concatMap, map, toArray } from 'rxjs/operators' | 3 | import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators' |
4 | import { HttpClient, HttpParams } from '@angular/common/http' | 4 | import { HttpClient, HttpParams } from '@angular/common/http' |
5 | import { Injectable } from '@angular/core' | 5 | import { Injectable } from '@angular/core' |
6 | import { RestExtractor, RestPagination, RestService, UserService } from '@app/core' | 6 | import { RestExtractor, RestPagination, RestService, ServerService, UserService } from '@app/core' |
7 | import { getBytes } from '@root-helpers/bytes' | 7 | import { getBytes } from '@root-helpers/bytes' |
8 | import { arrayify } from '@shared/core-utils' | 8 | import { arrayify, peertubeTranslate } from '@shared/core-utils' |
9 | import { ResultList, User as UserServerModel, UserCreate, UserRole, UserUpdate } from '@shared/models' | 9 | import { ResultList, User as UserServerModel, UserCreate, UserUpdate } from '@shared/models' |
10 | 10 | ||
11 | @Injectable() | 11 | @Injectable() |
12 | export class UserAdminService { | 12 | export class UserAdminService { |
@@ -14,7 +14,8 @@ export class UserAdminService { | |||
14 | constructor ( | 14 | constructor ( |
15 | private authHttp: HttpClient, | 15 | private authHttp: HttpClient, |
16 | private restExtractor: RestExtractor, | 16 | private restExtractor: RestExtractor, |
17 | private restService: RestService | 17 | private restService: RestService, |
18 | private serverService: ServerService | ||
18 | ) { } | 19 | ) { } |
19 | 20 | ||
20 | addUser (userCreate: UserCreate) { | 21 | addUser (userCreate: UserCreate) { |
@@ -58,10 +59,16 @@ export class UserAdminService { | |||
58 | } | 59 | } |
59 | 60 | ||
60 | return this.authHttp.get<ResultList<UserServerModel>>(UserService.BASE_USERS_URL, { params }) | 61 | return this.authHttp.get<ResultList<UserServerModel>>(UserService.BASE_USERS_URL, { params }) |
61 | .pipe( | 62 | .pipe( |
62 | map(res => this.restExtractor.applyToResultListData(res, this.formatUser.bind(this))), | 63 | switchMap(data => { |
63 | catchError(err => this.restExtractor.handleError(err)) | 64 | return this.serverService.getServerLocale() |
64 | ) | 65 | .pipe(map(translations => ({ data, translations }))) |
66 | }), | ||
67 | map(({ data, translations }) => { | ||
68 | return this.restExtractor.applyToResultListData(data, this.formatUser.bind(this), [translations]) | ||
69 | }), | ||
70 | catchError(err => this.restExtractor.handleError(err)) | ||
71 | ) | ||
65 | } | 72 | } |
66 | 73 | ||
67 | removeUsers (usersArg: UserServerModel | UserServerModel[]) { | 74 | removeUsers (usersArg: UserServerModel | UserServerModel[]) { |
@@ -98,7 +105,7 @@ export class UserAdminService { | |||
98 | ) | 105 | ) |
99 | } | 106 | } |
100 | 107 | ||
101 | private formatUser (user: UserServerModel) { | 108 | private formatUser (user: UserServerModel, translations: { [ id: string ]: string } = {}) { |
102 | let videoQuota | 109 | let videoQuota |
103 | if (user.videoQuota === -1) { | 110 | if (user.videoQuota === -1) { |
104 | videoQuota = '∞' | 111 | videoQuota = '∞' |
@@ -118,16 +125,10 @@ export class UserAdminService { | |||
118 | videoQuotaUsedDaily = getBytes(user.videoQuotaUsedDaily || 0, 0) + '' | 125 | videoQuotaUsedDaily = getBytes(user.videoQuotaUsedDaily || 0, 0) + '' |
119 | } | 126 | } |
120 | 127 | ||
121 | const roleLabels: { [ id in UserRole ]: string } = { | ||
122 | [UserRole.USER]: $localize`User`, | ||
123 | [UserRole.ADMINISTRATOR]: $localize`Administrator`, | ||
124 | [UserRole.MODERATOR]: $localize`Moderator` | ||
125 | } | ||
126 | |||
127 | return Object.assign(user, { | 128 | return Object.assign(user, { |
128 | role: { | 129 | role: { |
129 | id: user.role.id, | 130 | id: user.role.id, |
130 | label: roleLabels[user.role.id] | 131 | label: peertubeTranslate(user.role.label, translations) |
131 | }, | 132 | }, |
132 | videoQuota, | 133 | videoQuota, |
133 | videoQuotaUsed, | 134 | videoQuotaUsed, |