aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-25 15:11:25 +0200
committerChocobozzz <me@florianbigard.com>2018-07-25 15:11:25 +0200
commitad77475251c3516dd5851a08655be79d7bf76245 (patch)
tree3b816fa225a8b9f50bbdc6edd8bdc2d2dfbe5ce2 /client/src
parentf842e810b450a34275d8d453d5d9431a4e1b882a (diff)
downloadPeerTube-ad77475251c3516dd5851a08655be79d7bf76245.tar.gz
PeerTube-ad77475251c3516dd5851a08655be79d7bf76245.tar.zst
PeerTube-ad77475251c3516dd5851a08655be79d7bf76245.zip
Sort video captions
Diffstat (limited to 'client/src')
-rw-r--r--client/src/app/core/server/server.service.ts13
-rw-r--r--client/src/app/shared/misc/utils.ts12
-rw-r--r--client/src/app/shared/video-caption/video-caption.service.ts7
-rw-r--r--client/src/app/videos/+video-edit/shared/video-edit.component.ts18
-rw-r--r--client/src/assets/player/peertube-videojs-plugin.ts2
5 files changed, 37 insertions, 15 deletions
diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts
index 87280e16f..7b11c068e 100644
--- a/client/src/app/core/server/server.service.ts
+++ b/client/src/app/core/server/server.service.ts
@@ -2,13 +2,14 @@ import { map, share, switchMap, tap } from 'rxjs/operators'
2import { HttpClient } from '@angular/common/http' 2import { HttpClient } from '@angular/common/http'
3import { Inject, Injectable, LOCALE_ID } from '@angular/core' 3import { Inject, Injectable, LOCALE_ID } from '@angular/core'
4import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' 4import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage'
5import { Observable, ReplaySubject, of } from 'rxjs' 5import { Observable, of, ReplaySubject } from 'rxjs'
6import { getCompleteLocale, ServerConfig } from '../../../../../shared' 6import { getCompleteLocale, ServerConfig } from '../../../../../shared'
7import { About } from '../../../../../shared/models/server/about.model' 7import { About } from '../../../../../shared/models/server/about.model'
8import { environment } from '../../../environments/environment' 8import { environment } from '../../../environments/environment'
9import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos' 9import { VideoConstant } from '../../../../../shared/models/videos'
10import { isDefaultLocale } from '../../../../../shared/models/i18n' 10import { isDefaultLocale } from '../../../../../shared/models/i18n'
11import { getDevLocale, isOnDevLocale, peertubeTranslate } from '@app/shared/i18n/i18n-utils' 11import { getDevLocale, isOnDevLocale, peertubeTranslate } from '@app/shared/i18n/i18n-utils'
12import { sortBy } from '@app/shared/misc/utils'
12 13
13@Injectable() 14@Injectable()
14export class ServerService { 15export class ServerService {
@@ -156,13 +157,7 @@ export class ServerService {
156 }) 157 })
157 }) 158 })
158 159
159 if (sort === true) { 160 if (sort === true) sortBy(hashToPopulate, 'label')
160 hashToPopulate.sort((a, b) => {
161 if (a.label < b.label) return -1
162 if (a.label === b.label) return 0
163 return 1
164 })
165 }
166 161
167 notifier.next(true) 162 notifier.next(true)
168 }) 163 })
diff --git a/client/src/app/shared/misc/utils.ts b/client/src/app/shared/misc/utils.ts
index 8381745f5..018271efe 100644
--- a/client/src/app/shared/misc/utils.ts
+++ b/client/src/app/shared/misc/utils.ts
@@ -101,7 +101,19 @@ function removeElementFromArray <T> (arr: T[], elem: T) {
101 if (index !== -1) arr.splice(index, 1) 101 if (index !== -1) arr.splice(index, 1)
102} 102}
103 103
104function sortBy (obj: any[], key1: string, key2?: string) {
105 return obj.sort((a, b) => {
106 const elem1 = key2 ? a[key1][key2] : a[key1]
107 const elem2 = key2 ? b[key1][key2] : b[key1]
108
109 if (elem1 < elem2) return -1
110 if (elem1 === elem2) return 0
111 return 1
112 })
113}
114
104export { 115export {
116 sortBy,
105 objectToUrlEncoded, 117 objectToUrlEncoded,
106 getParameterByName, 118 getParameterByName,
107 populateAsyncUserVideoChannels, 119 populateAsyncUserVideoChannels,
diff --git a/client/src/app/shared/video-caption/video-caption.service.ts b/client/src/app/shared/video-caption/video-caption.service.ts
index e835981dd..0ff094d1f 100644
--- a/client/src/app/shared/video-caption/video-caption.service.ts
+++ b/client/src/app/shared/video-caption/video-caption.service.ts
@@ -6,7 +6,7 @@ import { ResultList } from '../../../../../shared'
6import { RestExtractor, RestService } from '../rest' 6import { RestExtractor, RestService } from '../rest'
7import { VideoCaption } from '../../../../../shared/models/videos/video-caption.model' 7import { VideoCaption } from '../../../../../shared/models/videos/video-caption.model'
8import { VideoService } from '@app/shared/video/video.service' 8import { VideoService } from '@app/shared/video/video.service'
9import { objectToFormData } from '@app/shared/misc/utils' 9import { objectToFormData, sortBy } from '@app/shared/misc/utils'
10import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model' 10import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
11 11
12@Injectable() 12@Injectable()
@@ -19,6 +19,11 @@ export class VideoCaptionService {
19 19
20 listCaptions (videoId: number | string): Observable<ResultList<VideoCaption>> { 20 listCaptions (videoId: number | string): Observable<ResultList<VideoCaption>> {
21 return this.authHttp.get<ResultList<VideoCaption>>(VideoService.BASE_VIDEO_URL + videoId + '/captions') 21 return this.authHttp.get<ResultList<VideoCaption>>(VideoService.BASE_VIDEO_URL + videoId + '/captions')
22 .pipe(map(res => {
23 sortBy(res.data, 'language', 'label')
24
25 return res
26 }))
22 .pipe(catchError(res => this.restExtractor.handleError(res))) 27 .pipe(catchError(res => this.restExtractor.handleError(res)))
23 } 28 }
24 29
diff --git a/client/src/app/videos/+video-edit/shared/video-edit.component.ts b/client/src/app/videos/+video-edit/shared/video-edit.component.ts
index b8aef99dd..b394a13e4 100644
--- a/client/src/app/videos/+video-edit/shared/video-edit.component.ts
+++ b/client/src/app/videos/+video-edit/shared/video-edit.component.ts
@@ -142,12 +142,13 @@ export class VideoEditComponent implements OnInit, OnDestroy {
142 // Replace existing caption? 142 // Replace existing caption?
143 if (existingCaption) { 143 if (existingCaption) {
144 Object.assign(existingCaption, caption, { action: 'CREATE' as 'CREATE' }) 144 Object.assign(existingCaption, caption, { action: 'CREATE' as 'CREATE' })
145 return 145 } else {
146 this.videoCaptions.push(
147 Object.assign(caption, { action: 'CREATE' as 'CREATE' })
148 )
146 } 149 }
147 150
148 this.videoCaptions.push( 151 this.sortVideoCaptions()
149 Object.assign(caption, { action: 'CREATE' as 'CREATE' })
150 )
151 } 152 }
152 153
153 async deleteCaption (caption: VideoCaptionEdit) { 154 async deleteCaption (caption: VideoCaptionEdit) {
@@ -170,6 +171,15 @@ export class VideoEditComponent implements OnInit, OnDestroy {
170 this.videoCaptionAddModal.show() 171 this.videoCaptionAddModal.show()
171 } 172 }
172 173
174 private sortVideoCaptions () {
175 this.videoCaptions.sort((v1, v2) => {
176 if (v1.language.label < v2.language.label) return -1
177 if (v1.language.label === v2.language.label) return 0
178
179 return 1
180 })
181 }
182
173 private trackPrivacyChange () { 183 private trackPrivacyChange () {
174 // We will update the "support" field depending on the channel 184 // We will update the "support" field depending on the channel
175 this.form.controls[ 'privacy' ] 185 this.form.controls[ 'privacy' ]
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts
index b02f4373a..4b0677fab 100644
--- a/client/src/assets/player/peertube-videojs-plugin.ts
+++ b/client/src/assets/player/peertube-videojs-plugin.ts
@@ -590,7 +590,7 @@ class PeerTubePlugin extends Plugin {
590 this.player.options_.inactivityTimeout = 0 590 this.player.options_.inactivityTimeout = 0
591 } 591 }
592 const enableInactivity = () => { 592 const enableInactivity = () => {
593 // this.player.options_.inactivityTimeout = saveInactivityTimeout 593 this.player.options_.inactivityTimeout = saveInactivityTimeout
594 } 594 }
595 595
596 const settingsDialog = this.player.children_.find(c => c.name_ === 'SettingsDialog') 596 const settingsDialog = this.player.children_.find(c => c.name_ === 'SettingsDialog')