]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/server/server.service.ts
First upload step is ok
[github/Chocobozzz/PeerTube.git] / client / src / app / core / server / server.service.ts
index cbc4074c9daf40c8908a36c739217db0a0abf2b5..43a836c5a5423f121927dfa6e9582f4e0e7622b3 100644 (file)
@@ -1,5 +1,7 @@
-import { Injectable } from '@angular/core'
 import { HttpClient } from '@angular/common/http'
+import { Injectable } from '@angular/core'
+import 'rxjs/add/operator/do'
+import { ReplaySubject } from 'rxjs/ReplaySubject'
 
 import { ServerConfig } from '../../../../../shared'
 
@@ -8,6 +10,11 @@ export class ServerService {
   private static BASE_CONFIG_URL = API_URL + '/api/v1/config/'
   private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'
 
+  videoPrivaciesLoaded = new ReplaySubject<boolean>(1)
+  videoCategoriesLoaded = new ReplaySubject<boolean>(1)
+  videoLicencesLoaded = new ReplaySubject<boolean>(1)
+  videoLanguagesLoaded = new ReplaySubject<boolean>(1)
+
   private config: ServerConfig = {
     signup: {
       allowed: false
@@ -29,19 +36,19 @@ export class ServerService {
   }
 
   loadVideoCategories () {
-    return this.loadVideoAttributeEnum('categories', this.videoCategories)
+    return this.loadVideoAttributeEnum('categories', this.videoCategories, this.videoCategoriesLoaded)
   }
 
   loadVideoLicences () {
-    return this.loadVideoAttributeEnum('licences', this.videoLicences)
+    return this.loadVideoAttributeEnum('licences', this.videoLicences, this.videoLicencesLoaded)
   }
 
   loadVideoLanguages () {
-    return this.loadVideoAttributeEnum('languages', this.videoLanguages)
+    return this.loadVideoAttributeEnum('languages', this.videoLanguages, this.videoLanguagesLoaded)
   }
 
   loadVideoPrivacies () {
-    return this.loadVideoAttributeEnum('privacies', this.videoPrivacies)
+    return this.loadVideoAttributeEnum('privacies', this.videoPrivacies, this.videoPrivaciesLoaded)
   }
 
   getConfig () {
@@ -66,17 +73,19 @@ export class ServerService {
 
   private loadVideoAttributeEnum (
     attributeName: 'categories' | 'licences' | 'languages' | 'privacies',
-    hashToPopulate: { id: number, label: string }[]
+    hashToPopulate: { id: number, label: string }[],
+    notifier: ReplaySubject<boolean>
   ) {
     return this.http.get(ServerService.BASE_VIDEO_URL + attributeName)
-               .subscribe(data => {
-                 Object.keys(data)
-                       .forEach(dataKey => {
-                         hashToPopulate.push({
-                           id: parseInt(dataKey, 10),
-                           label: data[dataKey]
-                         })
-                       })
+      .do(() => notifier.next(true))
+       .subscribe(data => {
+         Object.keys(data)
+               .forEach(dataKey => {
+                 hashToPopulate.push({
+                   id: parseInt(dataKey, 10),
+                   label: data[dataKey]
+                 })
                })
+       })
   }
 }