Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 21e493d

Browse files
committed
Add ability to set a custom quota
1 parent ead64cd commit 21e493d

21 files changed

+141
-105
lines changed

client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -402,25 +402,29 @@ <h1 class="sr-only" i18n>Configuration</h1>
402402
<ng-container formGroupName="user">
403403
<div class="form-group">
404404
<label i18n for="userVideoQuota">Default video quota per user</label>
405-
<div class="peertube-select-container">
406-
<select id="userVideoQuota" formControlName="videoQuota" class="form-control">
407-
<option *ngFor="let videoQuotaOption of videoQuotaOptions" [value]="videoQuotaOption.value" [disabled]="videoQuotaOption.disabled">
408-
{{ videoQuotaOption.label }}
409-
</option>
410-
</select>
411-
</div>
405+
406+
<my-select-custom-value
407+
id="userVideoQuota"
408+
[items]="videoQuotaOptions"
409+
formControlName="videoQuota"
410+
i18n-inputSuffix inputSuffix="bytes" inputType="number"
411+
[clearable]="false"
412+
></my-select-custom-value>
413+
412414
<div *ngIf="formErrors.user.videoQuota" class="form-error">{{ formErrors.user.videoQuota }}</div>
413415
</div>
414416

415417
<div class="form-group">
416418
<label i18n for="userVideoQuotaDaily">Default daily upload limit per user</label>
417-
<div class="peertube-select-container">
418-
<select id="userVideoQuotaDaily" formControlName="videoQuotaDaily" class="form-control">
419-
<option *ngFor="let videoQuotaDailyOption of videoQuotaDailyOptions" [value]="videoQuotaDailyOption.value" [disabled]="videoQuotaDailyOption.disabled">
420-
{{ videoQuotaDailyOption.label }}
421-
</option>
422-
</select>
423-
</div>
419+
420+
<my-select-custom-value
421+
id="userVideoQuotaDaily"
422+
[items]="videoQuotaDailyOptions"
423+
formControlName="videoQuotaDaily"
424+
i18n-inputSuffix inputSuffix="bytes" inputType="number"
425+
[clearable]="false"
426+
></my-select-custom-value>
427+
424428
<div *ngIf="formErrors.user.videoQuotaDaily" class="form-error">{{ formErrors.user.videoQuotaDaily }}</div>
425429
</div>
426430
</ng-container>

client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import {
1919
TRANSCODING_THREADS_VALIDATOR
2020
} from '@app/shared/form-validators/custom-config-validators'
2121
import { USER_VIDEO_QUOTA_DAILY_VALIDATOR, USER_VIDEO_QUOTA_VALIDATOR } from '@app/shared/form-validators/user-validators'
22-
import { FormReactive, FormValidatorService, SelectOptionsItem } from '@app/shared/shared-forms'
22+
import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
2323
import { NgbNav } from '@ng-bootstrap/ng-bootstrap'
2424
import { CustomConfig, ServerConfig } from '@shared/models'
25+
import { SelectOptionsItem } from 'src/types/select-options-item.model'
2526

2627
@Component({
2728
selector: 'my-edit-custom-config',

client/src/app/+admin/config/shared/config.service.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,46 @@ import { HttpClient } from '@angular/common/http'
33
import { Injectable } from '@angular/core'
44
import { RestExtractor } from '@app/core'
55
import { CustomConfig } from '@shared/models'
6+
import { SelectOptionsItem } from '../../../../types/select-options-item.model'
67
import { environment } from '../../../../environments/environment'
78

89
@Injectable()
910
export class ConfigService {
1011
private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/config'
1112

12-
videoQuotaOptions: { value: number, label: string, disabled?: boolean }[] = []
13-
videoQuotaDailyOptions: { value: number, label: string, disabled?: boolean }[] = []
13+
videoQuotaOptions: SelectOptionsItem[] = []
14+
videoQuotaDailyOptions: SelectOptionsItem[] = []
1415

1516
constructor (
1617
private authHttp: HttpClient,
1718
private restExtractor: RestExtractor
1819
) {
1920
this.videoQuotaOptions = [
20-
{ value: undefined, label: 'Default quota', disabled: true },
21-
{ value: -1, label: $localize`Unlimited` },
22-
{ value: undefined, label: '─────', disabled: true },
23-
{ value: 0, label: $localize`None - no upload possible` },
24-
{ value: 100 * 1024 * 1024, label: $localize`100MB` },
25-
{ value: 500 * 1024 * 1024, label: $localize`500MB` },
26-
{ value: 1024 * 1024 * 1024, label: $localize`1GB` },
27-
{ value: 5 * 1024 * 1024 * 1024, label: $localize`5GB` },
28-
{ value: 20 * 1024 * 1024 * 1024, label: $localize`20GB` },
29-
{ value: 50 * 1024 * 1024 * 1024, label: $localize`50GB` }
21+
{ id: -1, label: $localize`Unlimited` },
22+
{ id: 0, label: $localize`None - no upload possible` },
23+
{ id: 100 * 1024 * 1024, label: $localize`100MB` },
24+
{ id: 500 * 1024 * 1024, label: $localize`500MB` },
25+
{ id: 1024 * 1024 * 1024, label: $localize`1GB` },
26+
{ id: 5 * 1024 * 1024 * 1024, label: $localize`5GB` },
27+
{ id: 20 * 1024 * 1024 * 1024, label: $localize`20GB` },
28+
{ id: 50 * 1024 * 1024 * 1024, label: $localize`50GB` },
29+
{ id: 100 * 1024 * 1024 * 1024, label: $localize`100GB` },
30+
{ id: 200 * 1024 * 1024 * 1024, label: $localize`200GB` },
31+
{ id: 500 * 1024 * 1024 * 1024, label: $localize`500GB` }
3032
]
3133

3234
this.videoQuotaDailyOptions = [
33-
{ value: undefined, label: 'Default daily upload limit', disabled: true },
34-
{ value: -1, label: $localize`Unlimited` },
35-
{ value: undefined, label: '─────', disabled: true },
36-
{ value: 0, label: $localize`None - no upload possible` },
37-
{ value: 10 * 1024 * 1024, label: $localize`10MB` },
38-
{ value: 50 * 1024 * 1024, label: $localize`50MB` },
39-
{ value: 100 * 1024 * 1024, label: $localize`100MB` },
40-
{ value: 500 * 1024 * 1024, label: $localize`500MB` },
41-
{ value: 2 * 1024 * 1024 * 1024, label: $localize`2GB` },
42-
{ value: 5 * 1024 * 1024 * 1024, label: $localize`5GB` }
35+
{ id: -1, label: $localize`Unlimited` },
36+
{ id: 0, label: $localize`None - no upload possible` },
37+
{ id: 10 * 1024 * 1024, label: $localize`10MB` },
38+
{ id: 50 * 1024 * 1024, label: $localize`50MB` },
39+
{ id: 100 * 1024 * 1024, label: $localize`100MB` },
40+
{ id: 500 * 1024 * 1024, label: $localize`500MB` },
41+
{ id: 2 * 1024 * 1024 * 1024, label: $localize`2GB` },
42+
{ id: 5 * 1024 * 1024 * 1024, label: $localize`5GB` },
43+
{ id: 10 * 1024 * 1024 * 1024, label: $localize`10GB` },
44+
{ id: 20 * 1024 * 1024 * 1024, label: $localize`20GB` },
45+
{ id: 50 * 1024 * 1024 * 1024, label: $localize`50GB` }
4346
]
4447
}
4548

client/src/app/+admin/users/user-edit/user-create.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export class UserCreateComponent extends UserEdit implements OnInit {
4545

4646
const defaultValues = {
4747
role: UserRole.USER.toString(),
48-
videoQuota: '-1',
49-
videoQuotaDaily: '-1'
48+
videoQuota: -1,
49+
videoQuotaDaily: -1
5050
}
5151

5252
this.buildForm({

client/src/app/+admin/users/user-edit/user-edit.component.html

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,28 +149,38 @@
149149

150150
<div class="form-group">
151151
<label i18n for="videoQuota">Video quota</label>
152-
<div class="peertube-select-container">
153-
<select id="videoQuota" formControlName="videoQuota" class="form-control">
154-
<option *ngFor="let videoQuotaOption of videoQuotaOptions" [value]="videoQuotaOption.value" [disabled]="videoQuotaOption.disabled">
155-
{{ videoQuotaOption.label }}
156-
</option>
157-
</select>
158-
</div>
152+
153+
<my-select-custom-value
154+
id="videoQuota"
155+
[items]="videoQuotaOptions"
156+
formControlName="videoQuota"
157+
i18n-inputSuffix inputSuffix="bytes" inputType="number"
158+
[clearable]="false"
159+
></my-select-custom-value>
159160

160161
<div i18n class="transcoding-information" *ngIf="isTranscodingInformationDisplayed()">
161162
Transcoding is enabled. The video quota only takes into account <strong>original</strong> video size. <br />
162163
At most, this user could upload ~ {{ computeQuotaWithTranscoding() | bytes: 0 }}.
163164
</div>
165+
166+
<div *ngIf="formErrors.videoQuota" class="form-error">
167+
{{ formErrors.videoQuota }}
168+
</div>
164169
</div>
165170

166171
<div class="form-group">
167172
<label i18n for="videoQuotaDaily">Daily video quota</label>
168-
<div class="peertube-select-container">
169-
<select id="videoQuotaDaily" formControlName="videoQuotaDaily" class="form-control">
170-
<option *ngFor="let videoQuotaDailyOption of videoQuotaDailyOptions" [value]="videoQuotaDailyOption.value" [disabled]="videoQuotaDailyOption.disabled">
171-
{{ videoQuotaDailyOption.label }}
172-
</option>
173-
</select>
173+
174+
<my-select-custom-value
175+
id="videoQuotaDaily"
176+
[items]="videoQuotaDailyOptions"
177+
formControlName="videoQuotaDaily"
178+
i18n-inputSuffix inputSuffix="bytes" inputType="number"
179+
[clearable]="false"
180+
></my-select-custom-value>
181+
182+
<div *ngIf="formErrors.videoQuotaDaily" class="form-error">
183+
{{ formErrors.videoQuotaDaily }}
174184
</div>
175185
</div>
176186

client/src/app/+admin/users/user-edit/user-edit.component.scss

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@import '_variables';
22
@import '_mixins';
33

4+
$form-base-input-width: 340px;
5+
46
label {
57
font-weight: $font-regular;
68
font-size: 100%;
@@ -15,18 +17,24 @@ label {
1517
}
1618

1719
input:not([type=submit]) {
18-
@include peertube-input-text(340px);
20+
@include peertube-input-text($form-base-input-width);
1921
display: block;
2022
}
2123

2224
my-input-toggle-hidden {
23-
@include responsive-width(340px);
25+
@include responsive-width($form-base-input-width);
2426

2527
display: block;
2628
}
2729

2830
.peertube-select-container {
29-
@include peertube-select-container(340px);
31+
@include peertube-select-container($form-base-input-width);
32+
}
33+
34+
my-select-custom-value {
35+
@include responsive-width($form-base-input-width);
36+
37+
display: block;
3038
}
3139

3240
input[type=submit], button {

client/src/app/+admin/users/user-edit/user-edit.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import { AuthService, ScreenService, ServerService, User } from '@app/core'
44
import { FormReactive } from '@app/shared/shared-forms'
55
import { USER_ROLE_LABELS } from '@shared/core-utils/users'
66
import { ServerConfig, UserAdminFlag, UserRole, VideoResolution } from '@shared/models'
7+
import { SelectOptionsItem } from '../../../../types/select-options-item.model'
78

89
@Directive()
910
// tslint:disable-next-line: directive-class-suffix
1011
export abstract class UserEdit extends FormReactive implements OnInit {
11-
videoQuotaOptions: { value: string, label: string, disabled?: boolean }[] = []
12-
videoQuotaDailyOptions: { value: string, label: string, disabled?: boolean }[] = []
12+
videoQuotaOptions: SelectOptionsItem[] = []
13+
videoQuotaDailyOptions: SelectOptionsItem[] = []
1314
username: string
1415
user: User
1516

@@ -97,19 +98,7 @@ export abstract class UserEdit extends FormReactive implements OnInit {
9798
}
9899

99100
protected buildQuotaOptions () {
100-
// These are used by a HTML select, so convert key into strings
101-
this.videoQuotaOptions = this.configService
102-
.videoQuotaOptions.map(q => ({
103-
value: q.value?.toString(),
104-
label: q.label,
105-
disabled: q.disabled
106-
}))
107-
108-
this.videoQuotaDailyOptions = this.configService
109-
.videoQuotaDailyOptions.map(q => ({
110-
value: q.value?.toString(),
111-
label: q.label,
112-
disabled: q.disabled
113-
}))
101+
this.videoQuotaOptions = this.configService.videoQuotaOptions
102+
this.videoQuotaDailyOptions = this.configService.videoQuotaDailyOptions
114103
}
115104
}

client/src/app/+my-library/my-video-playlists/my-video-playlist-edit.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { FormReactive, SelectChannelItem } from '@app/shared/shared-forms'
1+
import { FormReactive } from '@app/shared/shared-forms'
22
import { VideoConstant, VideoPlaylistPrivacy } from '@shared/models'
33
import { VideoPlaylist } from '@shared/models/videos/playlist/video-playlist.model'
4+
import { SelectChannelItem } from '../../../types/select-options-item.model'
45

56
export abstract class MyVideoPlaylistEdit extends FormReactive {
67
// Declare it here to avoid errors in create template

client/src/app/+videos/+video-edit/shared/video-edit.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { forkJoin } from 'rxjs'
22
import { map } from 'rxjs/operators'
3+
import { SelectChannelItem } from 'src/types/select-options-item.model'
34
import { Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'
45
import { FormArray, FormControl, FormGroup, ValidatorFn, Validators } from '@angular/forms'
56
import { HooksService, PluginService, ServerService } from '@app/core'
@@ -17,10 +18,10 @@ import {
1718
VIDEO_SUPPORT_VALIDATOR,
1819
VIDEO_TAGS_ARRAY_VALIDATOR
1920
} from '@app/shared/form-validators/video-validators'
20-
import { FormReactiveValidationMessages, FormValidatorService, SelectChannelItem } from '@app/shared/shared-forms'
21+
import { FormReactiveValidationMessages, FormValidatorService } from '@app/shared/shared-forms'
2122
import { InstanceService } from '@app/shared/shared-instance'
2223
import { VideoCaptionEdit, VideoEdit, VideoService } from '@app/shared/shared-main'
23-
import { ServerConfig, VideoConstant, LiveVideo, VideoPrivacy } from '@shared/models'
24+
import { LiveVideo, ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'
2425
import { RegisterClientFormFieldOptions, RegisterClientVideoFieldOptions } from '@shared/models/plugins/register-client-form-field.model'
2526
import { I18nPrimengCalendarService } from './i18n-primeng-calendar.service'
2627
import { VideoCaptionAddModalComponent } from './video-caption-add-modal.component'

client/src/app/+videos/+video-edit/video-add-components/video-send.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { catchError, switchMap, tap } from 'rxjs/operators'
2+
import { SelectChannelItem } from 'src/types/select-options-item.model'
23
import { Directive, EventEmitter, OnInit } from '@angular/core'
34
import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core'
45
import { populateAsyncUserVideoChannels } from '@app/helpers'
5-
import { FormReactive, SelectChannelItem } from '@app/shared/shared-forms'
6+
import { FormReactive } from '@app/shared/shared-forms'
67
import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
78
import { LoadingBarService } from '@ngx-loading-bar/core'
89
import { ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'

0 commit comments

Comments
 (0)