]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Sort video categories/languages
authorChocobozzz <me@florianbigard.com>
Tue, 20 Feb 2018 08:50:44 +0000 (09:50 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 20 Feb 2018 08:50:44 +0000 (09:50 +0100)
client/src/app/core/server/server.service.ts

index 553ad8af6f8550cdf7dff72f643ffaf161b614ad..f54e63efd5c867a2fb6ca7d49340de848f27597e 100644 (file)
@@ -60,7 +60,7 @@ export class ServerService {
   }
 
   loadVideoCategories () {
-    return this.loadVideoAttributeEnum('categories', this.videoCategories, this.videoCategoriesLoaded)
+    return this.loadVideoAttributeEnum('categories', this.videoCategories, this.videoCategoriesLoaded, true)
   }
 
   loadVideoLicences () {
@@ -68,7 +68,7 @@ export class ServerService {
   }
 
   loadVideoLanguages () {
-    return this.loadVideoAttributeEnum('languages', this.videoLanguages, this.videoLanguagesLoaded)
+    return this.loadVideoAttributeEnum('languages', this.videoLanguages, this.videoLanguagesLoaded, true)
   }
 
   loadVideoPrivacies () {
@@ -102,7 +102,8 @@ export class ServerService {
   private loadVideoAttributeEnum (
     attributeName: 'categories' | 'licences' | 'languages' | 'privacies',
     hashToPopulate: { id: number, label: string }[],
-    notifier: ReplaySubject<boolean>
+    notifier: ReplaySubject<boolean>,
+    sort = false
   ) {
     return this.http.get(ServerService.BASE_VIDEO_URL + attributeName)
        .subscribe(data => {
@@ -114,6 +115,14 @@ export class ServerService {
                  })
                })
 
+         if (sort === true) {
+           hashToPopulate.sort((a, b) => {
+             if (a.label < b.label) return -1
+             if (a.label === b.label) return 0
+             return 1
+           })
+         }
+
          notifier.next(true)
        })
   }