]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+admin/users/user-edit/user-update.component.ts
Refractor notification service
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-update.component.ts
index 3e60991d2e218722d17e0749f38abc207c88299e..61e64182391173e4674329c66b9157175860e7c3 100644 (file)
@@ -1,15 +1,15 @@
 import { Component, OnDestroy, OnInit } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
 import { Subscription } from 'rxjs'
-import { NotificationsService } from 'angular2-notifications'
-import { UserService } from '../shared'
-import { User } from '../../../shared'
+import { Notifier } from '@app/core'
 import { ServerService } from '../../../core'
 import { UserEdit } from './user-edit'
-import { UserUpdate } 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'
+import { UserService } from '@app/shared'
 
 @Component({
   selector: 'my-user-update',
@@ -26,22 +26,26 @@ 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,
-    private notificationsService: NotificationsService,
+    private notifier: Notifier,
     private userService: UserService,
     private i18n: I18n
   ) {
     super()
+
+    this.buildQuotaOptions()
   }
 
   ngOnInit () {
-    const defaultValues = { videoQuota: '-1' }
+    const defaultValues = { videoQuota: '-1', videoQuotaDaily: '-1' }
     this.buildForm({
       email: this.userValidatorsService.USER_EMAIL,
       role: this.userValidatorsService.USER_ROLE,
-      videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA
+      videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
+      videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
     }, defaultValues)
 
     this.paramsSub = this.route.params.subscribe(routeParams => {
@@ -65,13 +69,11 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
 
     // A select in HTML is always mapped as a string, we convert it to number
     userUpdate.videoQuota = parseInt(this.form.value['videoQuota'], 10)
+    userUpdate.videoQuotaDaily = parseInt(this.form.value['videoQuotaDaily'], 10)
 
     this.userService.updateUser(this.userId, userUpdate).subscribe(
       () => {
-        this.notificationsService.success(
-          this.i18n('Success'),
-          this.i18n('User {{username}} updated.', { username: this.username })
-        )
+        this.notifier.success(this.i18n('User {{username}} updated.', { username: this.username }))
         this.router.navigate([ '/admin/users/list' ])
       },
 
@@ -94,7 +96,8 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
     this.form.patchValue({
       email: userJson.email,
       role: userJson.role,
-      videoQuota: userJson.videoQuota
+      videoQuota: userJson.videoQuota,
+      videoQuotaDaily: userJson.videoQuotaDaily
     })
   }
 }