1
0
Fork 0
peertube/client/src/app/+admin/users/user-edit/user-edit.ts

114 lines
3.6 KiB
TypeScript
Raw Normal View History

2020-06-26 06:37:26 +00:00
import { OnInit, Directive } from '@angular/core'
2020-06-23 12:10:17 +00:00
import { ConfigService } from '@app/+admin/config/shared/config.service'
import { AuthService, ScreenService, ServerService, User } from '@app/core'
import { FormReactive } from '@app/shared/shared-forms'
import { ServerConfig, USER_ROLE_LABELS, UserAdminFlag, UserRole, VideoResolution } from '@shared/models'
2017-09-05 19:29:39 +00:00
2020-06-26 06:37:26 +00:00
@Directive()
2019-12-18 14:31:54 +00:00
export abstract class UserEdit extends FormReactive implements OnInit {
videoQuotaOptions: { value: string, label: string, disabled?: boolean }[] = []
videoQuotaDailyOptions: { value: string, label: string, disabled?: boolean }[] = []
2018-11-15 08:24:56 +00:00
username: string
user: User
2020-03-18 09:22:36 +00:00
roles: { value: string, label: string }[] = []
2019-12-18 14:31:54 +00:00
protected serverConfig: ServerConfig
protected abstract serverService: ServerService
2018-09-26 12:46:54 +00:00
protected abstract configService: ConfigService
protected abstract screenService: ScreenService
2019-07-30 07:59:19 +00:00
protected abstract auth: AuthService
2017-09-05 19:29:39 +00:00
abstract isCreation (): boolean
abstract getFormButtonTitle (): string
2019-12-18 14:31:54 +00:00
ngOnInit (): void {
this.serverConfig = this.serverService.getTmpConfig()
this.serverService.getConfig()
.subscribe(config => this.serverConfig = config)
2020-03-18 09:22:36 +00:00
this.buildRoles()
2019-12-18 14:31:54 +00:00
}
get subscribersCount () {
const forAccount = this.user
? this.user.account.followersCount
: 0
const forChannels = this.user
? this.user.videoChannels.map(c => c.followersCount).reduce((a, b) => a + b, 0)
: 0
return forAccount + forChannels
}
isInBigView () {
return this.screenService.getWindowInnerWidth() > 1600
}
2020-03-18 09:22:36 +00:00
buildRoles () {
2019-07-30 07:59:19 +00:00
const authUser = this.auth.getUser()
if (authUser.role === UserRole.ADMINISTRATOR) {
2020-03-18 09:22:36 +00:00
this.roles = Object.keys(USER_ROLE_LABELS)
2019-07-30 07:59:19 +00:00
.map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
2020-03-18 09:22:36 +00:00
return
2019-07-30 07:59:19 +00:00
}
2020-03-18 09:22:36 +00:00
this.roles = [
2019-07-30 07:59:19 +00:00
{ value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
]
}
isTranscodingInformationDisplayed () {
const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
2019-12-18 14:31:54 +00:00
return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
formVideoQuota > 0
}
computeQuotaWithTranscoding () {
2019-12-18 14:31:54 +00:00
const transcodingConfig = this.serverConfig.transcoding
2019-01-29 07:37:25 +00:00
const resolutions = transcodingConfig.enabledResolutions
const higherResolution = VideoResolution.H_4K
let multiplier = 0
for (const resolution of resolutions) {
multiplier += resolution / higherResolution
}
2019-01-29 07:37:25 +00:00
if (transcodingConfig.hls.enabled) multiplier *= 2
return multiplier * parseInt(this.form.value['videoQuota'], 10)
}
2018-09-26 12:46:54 +00:00
resetPassword () {
return
}
2019-04-15 08:49:46 +00:00
protected buildAdminFlags (formValue: any) {
return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
2019-04-15 08:49:46 +00:00
}
2018-09-26 12:46:54 +00:00
protected buildQuotaOptions () {
// These are used by a HTML select, so convert key into strings
this.videoQuotaOptions = this.configService
2020-04-14 07:46:42 +00:00
.videoQuotaOptions.map(q => ({
2020-04-13 23:38:41 +00:00
value: q.value?.toString(),
label: q.label,
disabled: q.disabled
2020-04-14 07:46:42 +00:00
}))
2018-09-26 12:46:54 +00:00
this.videoQuotaDailyOptions = this.configService
2020-04-13 23:38:41 +00:00
.videoQuotaDailyOptions.map(q => ({
value: q.value?.toString(),
label: q.label,
disabled: q.disabled
}))
console.log(
this.videoQuotaOptions,
this.videoQuotaDailyOptions
)
2018-09-26 12:46:54 +00:00
}
2017-09-05 19:29:39 +00:00
}