From 3827c3b3488845f4235714e92eea439423df2909 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 26 Sep 2018 14:46:54 +0200 Subject: [PATCH] Fix quota translations --- .../edit-custom-config.component.ts | 51 ++++++++----------- .../+admin/config/shared/config.service.ts | 31 ++++++++++- .../followers-list.component.html | 5 +- .../following-list.component.html | 5 +- .../users/user-edit/user-create.component.ts | 4 ++ .../app/+admin/users/user-edit/user-edit.ts | 19 ++++--- .../users/user-edit/user-update.component.ts | 6 ++- server/tests/api/server/jobs.ts | 4 +- 8 files changed, 81 insertions(+), 44 deletions(-) diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts index 9b3bd86f1..4983b0425 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts @@ -14,37 +14,10 @@ import { BuildFormDefaultValues, FormValidatorService } from '@app/shared/forms/ styleUrls: [ './edit-custom-config.component.scss' ] }) export class EditCustomConfigComponent extends FormReactive implements OnInit { - static videoQuotaOptions = [ - { value: -1, label: 'Unlimited' }, - { value: 0, label: '0' }, - { value: 100 * 1024 * 1024, label: '100MB' }, - { value: 500 * 1024 * 1024, label: '500MB' }, - { value: 1024 * 1024 * 1024, label: '1GB' }, - { value: 5 * 1024 * 1024 * 1024, label: '5GB' }, - { value: 20 * 1024 * 1024 * 1024, label: '20GB' }, - { value: 50 * 1024 * 1024 * 1024, label: '50GB' } - ] - static videoQuotaDailyOptions = [ - { value: -1, label: 'Unlimited' }, - { value: 0, label: '0' }, - { value: 10 * 1024 * 1024, label: '10MB' }, - { value: 50 * 1024 * 1024, label: '50MB' }, - { value: 100 * 1024 * 1024, label: '100MB' }, - { value: 500 * 1024 * 1024, label: '500MB' }, - { value: 2 * 1024 * 1024 * 1024, label: '2GB' }, - { value: 5 * 1024 * 1024 * 1024, label: '5GB' } - ] - customConfig: CustomConfig - resolutions = [ '240p', '360p', '480p', '720p', '1080p' ] - transcodingThreadOptions = [ - { value: 0, label: 'Auto (via ffmpeg)' }, - { value: 1, label: '1' }, - { value: 2, label: '2' }, - { value: 4, label: '4' }, - { value: 8, label: '8' } - ] + resolutions: string[] = [] + transcodingThreadOptions: { label: string, value: number }[] = [] private oldCustomJavascript: string private oldCustomCSS: string @@ -60,14 +33,30 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { private i18n: I18n ) { super() + + this.resolutions = [ + this.i18n('240p'), + this.i18n('360p'), + this.i18n('480p'), + this.i18n('720p'), + this.i18n('1080p') + ] + + this.transcodingThreadOptions = [ + { value: 0, label: this.i18n('Auto (via ffmpeg)') }, + { value: 1, label: '1' }, + { value: 2, label: '2' }, + { value: 4, label: '4' }, + { value: 8, label: '8' } + ] } get videoQuotaOptions () { - return EditCustomConfigComponent.videoQuotaOptions + return this.configService.videoQuotaOptions } get videoQuotaDailyOptions () { - return EditCustomConfigComponent.videoQuotaDailyOptions + return this.configService.videoQuotaDailyOptions } getResolutionKey (resolution: string) { diff --git a/client/src/app/+admin/config/shared/config.service.ts b/client/src/app/+admin/config/shared/config.service.ts index 7c61fe9e7..28a3d67d6 100644 --- a/client/src/app/+admin/config/shared/config.service.ts +++ b/client/src/app/+admin/config/shared/config.service.ts @@ -4,15 +4,42 @@ import { Injectable } from '@angular/core' import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model' import { environment } from '../../../../environments/environment' import { RestExtractor } from '../../../shared' +import { I18n } from '@ngx-translate/i18n-polyfill' @Injectable() export class ConfigService { private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/config' + videoQuotaOptions: { value: number, label: string }[] = [] + videoQuotaDailyOptions: { value: number, label: string }[] = [] + constructor ( private authHttp: HttpClient, - private restExtractor: RestExtractor - ) {} + private restExtractor: RestExtractor, + private i18n: I18n + ) { + this.videoQuotaOptions = [ + { value: -1, label: this.i18n('Unlimited') }, + { value: 0, label: '0' }, + { value: 100 * 1024 * 1024, label: this.i18n('100MB') }, + { value: 500 * 1024 * 1024, label: this.i18n('500MB') }, + { value: 1024 * 1024 * 1024, label: this.i18n('1GB') }, + { value: 5 * 1024 * 1024 * 1024, label: this.i18n('5GB') }, + { value: 20 * 1024 * 1024 * 1024, label: this.i18n('20GB') }, + { value: 50 * 1024 * 1024 * 1024, label: this.i18n('50GB') } + ] + + this.videoQuotaDailyOptions = [ + { value: -1, label: this.i18n('Unlimited') }, + { value: 0, label: '0' }, + { value: 10 * 1024 * 1024, label: this.i18n('10MB') }, + { value: 50 * 1024 * 1024, label: this.i18n('50MB') }, + { value: 100 * 1024 * 1024, label: this.i18n('100MB') }, + { value: 500 * 1024 * 1024, label: this.i18n('500MB') }, + { value: 2 * 1024 * 1024 * 1024, label: this.i18n('2GB') }, + { value: 5 * 1024 * 1024 * 1024, label: this.i18n('5GB') } + ] + } getCustomConfig () { return this.authHttp.get(ConfigService.BASE_APPLICATION_URL + '/custom') 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 1a6ed616a..5645a60cc 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 @@ -19,7 +19,10 @@ {{ follow.score }} {{ follow.follower.name }} {{ follow.follower.host }} - {{ follow.state }} + + Accepted + Pending + {{ follow.createdAt }} 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 66ab64c50..8af624ac5 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 @@ -17,7 +17,10 @@ {{ follow.id }} {{ follow.following.host }} - {{ follow.state }} + + Accepted + Pending + {{ follow.createdAt }} ({ value: q.value.toString(), label: q.label })) - videoQuotaDailyOptions = EditCustomConfigComponent.videoQuotaDailyOptions - .map(q => ({ value: q.value.toString(), label: q.label })) - + videoQuotaOptions: { value: string, label: string }[] = [] + videoQuotaDailyOptions: { value: string, label: string }[] = [] roles = Object.keys(USER_ROLE_LABELS).map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] })) protected abstract serverService: ServerService + protected abstract configService: ConfigService abstract isCreation (): boolean abstract getFormButtonTitle (): string @@ -35,4 +33,13 @@ export abstract class UserEdit extends FormReactive { return multiplier * parseInt(this.form.value['videoQuota'], 10) } + + protected buildQuotaOptions () { + // These are used by a HTML select, so convert key into strings + this.videoQuotaOptions = this.configService + .videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label })) + + this.videoQuotaDailyOptions = this.configService + .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label })) + } } diff --git a/client/src/app/+admin/users/user-edit/user-update.component.ts b/client/src/app/+admin/users/user-edit/user-update.component.ts index 5821229b3..9eb91ac95 100644 --- a/client/src/app/+admin/users/user-edit/user-update.component.ts +++ b/client/src/app/+admin/users/user-edit/user-update.component.ts @@ -5,10 +5,11 @@ import { NotificationsService } from 'angular2-notifications' import { UserService } from '../shared' import { ServerService } from '../../../core' import { UserEdit } from './user-edit' -import { UserUpdate, User } from '../../../../../../shared' +import { User, UserUpdate } from '../../../../../../shared' import { I18n } from '@ngx-translate/i18n-polyfill' import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service' +import { ConfigService } from '@app/+admin/config/shared/config.service' @Component({ selector: 'my-user-update', @@ -25,6 +26,7 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy { constructor ( protected formValidatorService: FormValidatorService, protected serverService: ServerService, + protected configService: ConfigService, private userValidatorsService: UserValidatorsService, private route: ActivatedRoute, private router: Router, @@ -33,6 +35,8 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy { private i18n: I18n ) { super() + + this.buildQuotaOptions() } ngOnInit () { diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index f5a19c5ea..cd59d9a1b 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -41,9 +41,9 @@ describe('Test jobs', function () { }) it('Should list jobs with sort and pagination', async function () { - const res = await getJobsListPaginationAndSort(servers[1].url, servers[1].accessToken, 'completed', 1, 1, 'createdAt') + const res = await getJobsListPaginationAndSort(servers[1].url, servers[1].accessToken, 'completed', 1, 2, 'createdAt') expect(res.body.total).to.be.above(2) - expect(res.body.data).to.have.lengthOf(1) + expect(res.body.data).to.have.lengthOf(2) let job = res.body.data[0] // Skip repeat jobs