]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+videos/+video-edit/video-add.component.ts
Update translations
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add.component.ts
index 016791d59dc76576c343ba767cbc3055fd9dc6ec..460c37a38e007443c8b1905a1e7fe1726d1af632 100644 (file)
@@ -1,6 +1,16 @@
 import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
-import { AuthService, CanComponentDeactivate, ServerService, User } from '@app/core'
-import { ServerConfig } from '@shared/models'
+import { ActivatedRoute, Router } from '@angular/router'
+import {
+  AuthService,
+  AuthUser,
+  CanComponentDeactivate,
+  HooksService,
+  ServerService,
+  UserService
+} from '@app/core'
+import { HTMLServerConfig } from '@shared/models'
+import { VideoEditType } from './shared/video-edit.type'
+import { VideoGoLiveComponent } from './video-add-components/video-go-live.component'
 import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
 import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
 import { VideoUploadComponent } from './video-add-components/video-upload.component'
@@ -14,18 +24,40 @@ export class VideoAddComponent implements OnInit, CanComponentDeactivate {
   @ViewChild('videoUpload') videoUpload: VideoUploadComponent
   @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
   @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
+  @ViewChild('videoGoLive') videoGoLive: VideoGoLiveComponent
 
-  user: User = null
+  user: AuthUser = null
 
-  secondStepType: 'upload' | 'import-url' | 'import-torrent'
+  secondStepType: VideoEditType
   videoName: string
-  serverConfig: ServerConfig
+
+  activeNav: string
+
+  uploadMessages: {
+    noQuota: string
+    autoBlock: string
+    quotaLeftDaily: string
+    quotaLeft: string
+  }
+
+  hasNoQuotaLeft = false
+  hasNoQuotaLeftDaily = false
+
+  serverConfig: HTMLServerConfig
 
   constructor (
     private auth: AuthService,
-    private serverService: ServerService
+    private userService: UserService,
+    private hooks: HooksService,
+    private serverService: ServerService,
+    private route: ActivatedRoute,
+    private router: Router
   ) {}
 
+  get isContactFormEnabled () {
+    return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
+  }
+
   get userInformationLoaded () {
     return this.auth.userInformationLoaded
   }
@@ -33,13 +65,65 @@ export class VideoAddComponent implements OnInit, CanComponentDeactivate {
   ngOnInit () {
     this.user = this.auth.getUser()
 
-    this.serverConfig = this.serverService.getTmpConfig()
+    this.serverConfig = this.serverService.getHTMLConfig()
+
+    if (this.route.snapshot.fragment) {
+      this.onNavChange(this.route.snapshot.fragment)
+    }
+
+    this.buildUploadMessages()
+
+    this.userService.getMyVideoQuotaUsed()
+      .subscribe(data => {
+        // videoQuota left lower than 10%
+        if (data.videoQuotaUsed > this.user.videoQuota * 0.9) {
+          this.hasNoQuotaLeft = true
+        }
 
-    this.serverService.getConfig()
-      .subscribe(config => this.serverConfig = config)
+        // unlimited videoQuota
+        if (this.user.videoQuota === -1) {
+          this.hasNoQuotaLeft = false
+        }
+
+        // videoQuotaDaily left lower than 10%
+        if (data.videoQuotaUsedDaily > this.user.videoQuotaDaily * 0.9) {
+          this.hasNoQuotaLeftDaily = true
+        }
+
+        // unlimited videoQuotaDaily
+        if (this.user.videoQuotaDaily === -1) {
+          this.hasNoQuotaLeftDaily = false
+        }
+      })
   }
 
-  onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
+  private async buildUploadMessages () {
+    // eslint-disable-next-line max-len
+    const noQuota = $localize`Sorry, the upload feature is disabled for your account. If you want to add videos, an admin must unlock your quota.`
+    // eslint-disable-next-line max-len
+    const autoBlock = $localize`Uploaded videos are reviewed before publishing for your account. If you want to add videos without moderation review, an admin must turn off your videos auto-block.`
+    // eslint-disable-next-line max-len
+    const quotaLeftDaily = $localize`Your daily video quota is insufficient. If you want to add more videos, you must wait for 24 hours or an admin must increase your daily quota.`
+    // eslint-disable-next-line max-len
+    const quotaLeft = $localize`Your video quota is insufficient. If you want to add more videos, an admin must increase your quota.`
+
+    const uploadMessages = {
+      noQuota,
+      autoBlock,
+      quotaLeftDaily,
+      quotaLeft
+    }
+
+    this.uploadMessages = await this.hooks.wrapObject(uploadMessages, 'common', 'filter:upload.messages.create.result')
+  }
+
+  onNavChange (newActiveNav: string) {
+    this.activeNav = newActiveNav
+
+    this.router.navigate([], { fragment: this.activeNav })
+  }
+
+  onFirstStepDone (type: VideoEditType, videoName: string) {
     this.secondStepType = type
     this.videoName = videoName
   }
@@ -59,10 +143,11 @@ export class VideoAddComponent implements OnInit, CanComponentDeactivate {
     return text
   }
 
-  canDeactivate (): { canDeactivate: boolean, text?: string} {
+  canDeactivate (): { canDeactivate: boolean, text?: string } {
     if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
     if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
     if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
+    if (this.secondStepType === 'go-live') return this.videoGoLive.canDeactivate()
 
     return { canDeactivate: true }
   }
@@ -75,11 +160,15 @@ export class VideoAddComponent implements OnInit, CanComponentDeactivate {
     return this.serverConfig.import.videos.torrent.enabled
   }
 
+  isVideoLiveEnabled () {
+    return this.serverConfig.live.enabled
+  }
+
   isInSecondStep () {
     return !!this.secondStepType
   }
 
   isRootUser () {
-    return this.auth.getUser().username === 'root'
+    return this.user.username === 'root'
   }
 }