Sort video captions

pull/850/head
Chocobozzz 2018-07-25 15:11:25 +02:00
parent f842e810b4
commit ad77475251
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 37 additions and 15 deletions

View File

@ -2,13 +2,14 @@ import { map, share, switchMap, tap } from 'rxjs/operators'
import { HttpClient } from '@angular/common/http' import { HttpClient } from '@angular/common/http'
import { Inject, Injectable, LOCALE_ID } from '@angular/core' import { Inject, Injectable, LOCALE_ID } from '@angular/core'
import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage'
import { Observable, ReplaySubject, of } from 'rxjs' import { Observable, of, ReplaySubject } from 'rxjs'
import { getCompleteLocale, ServerConfig } from '../../../../../shared' import { getCompleteLocale, ServerConfig } from '../../../../../shared'
import { About } from '../../../../../shared/models/server/about.model' import { About } from '../../../../../shared/models/server/about.model'
import { environment } from '../../../environments/environment' import { environment } from '../../../environments/environment'
import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos' import { VideoConstant } from '../../../../../shared/models/videos'
import { isDefaultLocale } from '../../../../../shared/models/i18n' import { isDefaultLocale } from '../../../../../shared/models/i18n'
import { getDevLocale, isOnDevLocale, peertubeTranslate } from '@app/shared/i18n/i18n-utils' import { getDevLocale, isOnDevLocale, peertubeTranslate } from '@app/shared/i18n/i18n-utils'
import { sortBy } from '@app/shared/misc/utils'
@Injectable() @Injectable()
export class ServerService { export class ServerService {
@ -156,13 +157,7 @@ export class ServerService {
}) })
}) })
if (sort === true) { if (sort === true) sortBy(hashToPopulate, 'label')
hashToPopulate.sort((a, b) => {
if (a.label < b.label) return -1
if (a.label === b.label) return 0
return 1
})
}
notifier.next(true) notifier.next(true)
}) })

View File

@ -101,7 +101,19 @@ function removeElementFromArray <T> (arr: T[], elem: T) {
if (index !== -1) arr.splice(index, 1) if (index !== -1) arr.splice(index, 1)
} }
function sortBy (obj: any[], key1: string, key2?: string) {
return obj.sort((a, b) => {
const elem1 = key2 ? a[key1][key2] : a[key1]
const elem2 = key2 ? b[key1][key2] : b[key1]
if (elem1 < elem2) return -1
if (elem1 === elem2) return 0
return 1
})
}
export { export {
sortBy,
objectToUrlEncoded, objectToUrlEncoded,
getParameterByName, getParameterByName,
populateAsyncUserVideoChannels, populateAsyncUserVideoChannels,

View File

@ -6,7 +6,7 @@ import { ResultList } from '../../../../../shared'
import { RestExtractor, RestService } from '../rest' import { RestExtractor, RestService } from '../rest'
import { VideoCaption } from '../../../../../shared/models/videos/video-caption.model' import { VideoCaption } from '../../../../../shared/models/videos/video-caption.model'
import { VideoService } from '@app/shared/video/video.service' import { VideoService } from '@app/shared/video/video.service'
import { objectToFormData } from '@app/shared/misc/utils' import { objectToFormData, sortBy } from '@app/shared/misc/utils'
import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model' import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
@Injectable() @Injectable()
@ -19,6 +19,11 @@ export class VideoCaptionService {
listCaptions (videoId: number | string): Observable<ResultList<VideoCaption>> { listCaptions (videoId: number | string): Observable<ResultList<VideoCaption>> {
return this.authHttp.get<ResultList<VideoCaption>>(VideoService.BASE_VIDEO_URL + videoId + '/captions') return this.authHttp.get<ResultList<VideoCaption>>(VideoService.BASE_VIDEO_URL + videoId + '/captions')
.pipe(map(res => {
sortBy(res.data, 'language', 'label')
return res
}))
.pipe(catchError(res => this.restExtractor.handleError(res))) .pipe(catchError(res => this.restExtractor.handleError(res)))
} }

View File

@ -142,12 +142,13 @@ export class VideoEditComponent implements OnInit, OnDestroy {
// Replace existing caption? // Replace existing caption?
if (existingCaption) { if (existingCaption) {
Object.assign(existingCaption, caption, { action: 'CREATE' as 'CREATE' }) Object.assign(existingCaption, caption, { action: 'CREATE' as 'CREATE' })
return } else {
this.videoCaptions.push(
Object.assign(caption, { action: 'CREATE' as 'CREATE' })
)
} }
this.videoCaptions.push( this.sortVideoCaptions()
Object.assign(caption, { action: 'CREATE' as 'CREATE' })
)
} }
async deleteCaption (caption: VideoCaptionEdit) { async deleteCaption (caption: VideoCaptionEdit) {
@ -170,6 +171,15 @@ export class VideoEditComponent implements OnInit, OnDestroy {
this.videoCaptionAddModal.show() this.videoCaptionAddModal.show()
} }
private sortVideoCaptions () {
this.videoCaptions.sort((v1, v2) => {
if (v1.language.label < v2.language.label) return -1
if (v1.language.label === v2.language.label) return 0
return 1
})
}
private trackPrivacyChange () { private trackPrivacyChange () {
// We will update the "support" field depending on the channel // We will update the "support" field depending on the channel
this.form.controls[ 'privacy' ] this.form.controls[ 'privacy' ]

View File

@ -590,7 +590,7 @@ class PeerTubePlugin extends Plugin {
this.player.options_.inactivityTimeout = 0 this.player.options_.inactivityTimeout = 0
} }
const enableInactivity = () => { const enableInactivity = () => {
// this.player.options_.inactivityTimeout = saveInactivityTimeout this.player.options_.inactivityTimeout = saveInactivityTimeout
} }
const settingsDialog = this.player.children_.find(c => c.name_ === 'SettingsDialog') const settingsDialog = this.player.children_.find(c => c.name_ === 'SettingsDialog')