2022-10-12 09:10:07 +02:00
|
|
|
import { SortMeta } from 'primeng/api'
|
|
|
|
import { mergeMap } from 'rxjs'
|
2022-08-10 09:53:39 +02:00
|
|
|
import { Component, OnInit } from '@angular/core'
|
|
|
|
import { AuthService, Notifier, RestPagination, RestTable, ServerService } from '@app/core'
|
|
|
|
import { DropdownAction, VideoChannelService, VideoChannelSyncService } from '@app/shared/shared-main'
|
|
|
|
import { HTMLServerConfig } from '@shared/models/server'
|
|
|
|
import { VideoChannelSync, VideoChannelSyncState } from '@shared/models/videos'
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: './my-video-channel-syncs.component.html',
|
|
|
|
styleUrls: [ './my-video-channel-syncs.component.scss' ]
|
|
|
|
})
|
|
|
|
export class MyVideoChannelSyncsComponent extends RestTable implements OnInit {
|
|
|
|
error: string
|
|
|
|
|
|
|
|
channelSyncs: VideoChannelSync[] = []
|
|
|
|
totalRecords = 0
|
|
|
|
|
|
|
|
videoChannelSyncActions: DropdownAction<VideoChannelSync>[][] = []
|
|
|
|
sort: SortMeta = { field: 'createdAt', order: 1 }
|
|
|
|
pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
|
|
|
|
|
|
|
|
private static STATE_CLASS_BY_ID = {
|
|
|
|
[VideoChannelSyncState.FAILED]: 'badge-red',
|
|
|
|
[VideoChannelSyncState.PROCESSING]: 'badge-blue',
|
|
|
|
[VideoChannelSyncState.SYNCED]: 'badge-green',
|
|
|
|
[VideoChannelSyncState.WAITING_FIRST_RUN]: 'badge-yellow'
|
|
|
|
}
|
|
|
|
|
|
|
|
private serverConfig: HTMLServerConfig
|
|
|
|
|
|
|
|
constructor (
|
|
|
|
private videoChannelsSyncService: VideoChannelSyncService,
|
|
|
|
private serverService: ServerService,
|
|
|
|
private notifier: Notifier,
|
|
|
|
private authService: AuthService,
|
|
|
|
private videoChannelService: VideoChannelService
|
|
|
|
) {
|
|
|
|
super()
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit () {
|
|
|
|
this.serverConfig = this.serverService.getHTMLConfig()
|
|
|
|
this.initialize()
|
|
|
|
|
|
|
|
this.videoChannelSyncActions = [
|
2022-10-10 10:20:07 +02:00
|
|
|
[
|
|
|
|
{
|
|
|
|
label: $localize`List imports`,
|
2022-10-12 09:10:07 +02:00
|
|
|
linkBuilder: () => [ '/my-library/video-imports' ],
|
|
|
|
queryParamsBuilder: sync => ({ search: `videoChannelSyncId:${sync.id}` }),
|
2022-10-10 10:20:07 +02:00
|
|
|
iconName: 'cloud-download'
|
|
|
|
}
|
|
|
|
],
|
2022-08-10 09:53:39 +02:00
|
|
|
[
|
|
|
|
{
|
|
|
|
label: $localize`Delete`,
|
|
|
|
iconName: 'delete',
|
|
|
|
handler: videoChannelSync => this.deleteSync(videoChannelSync)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: $localize`Fully synchronize the channel`,
|
|
|
|
description: $localize`This fetches any missing videos on the local channel`,
|
|
|
|
iconName: 'refresh',
|
|
|
|
handler: videoChannelSync => this.fullySynchronize(videoChannelSync)
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
protected reloadData () {
|
|
|
|
this.error = undefined
|
|
|
|
|
|
|
|
this.authService.userInformationLoaded
|
|
|
|
.pipe(mergeMap(() => {
|
|
|
|
const user = this.authService.getUser()
|
|
|
|
return this.videoChannelsSyncService.listAccountVideoChannelsSyncs({
|
|
|
|
sort: this.sort,
|
|
|
|
account: user.account,
|
|
|
|
pagination: this.pagination
|
|
|
|
})
|
|
|
|
}))
|
|
|
|
.subscribe({
|
|
|
|
next: res => {
|
|
|
|
this.channelSyncs = res.data
|
2022-09-14 15:18:05 +02:00
|
|
|
this.totalRecords = res.total
|
2022-08-10 09:53:39 +02:00
|
|
|
},
|
|
|
|
error: err => {
|
|
|
|
this.error = err.message
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
syncEnabled () {
|
|
|
|
return this.serverConfig.import.videoChannelSynchronization.enabled
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteSync (videoChannelSync: VideoChannelSync) {
|
|
|
|
this.videoChannelsSyncService.deleteSync(videoChannelSync.id)
|
|
|
|
.subscribe({
|
|
|
|
next: () => {
|
|
|
|
this.notifier.success($localize`Synchronization removed successfully for ${videoChannelSync.channel.displayName}.`)
|
|
|
|
this.reloadData()
|
|
|
|
},
|
|
|
|
error: err => {
|
|
|
|
this.error = err.message
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fullySynchronize (videoChannelSync: VideoChannelSync) {
|
2022-08-10 11:51:13 +02:00
|
|
|
this.videoChannelService.importVideos(videoChannelSync.channel.name, videoChannelSync.externalChannelUrl, videoChannelSync.id)
|
2022-08-10 09:53:39 +02:00
|
|
|
.subscribe({
|
|
|
|
next: () => {
|
|
|
|
this.notifier.success($localize`Full synchronization requested successfully for ${videoChannelSync.channel.displayName}.`)
|
|
|
|
},
|
|
|
|
error: err => {
|
|
|
|
this.error = err.message
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
getSyncCreateLink () {
|
|
|
|
return '/my-library/video-channel-syncs/create'
|
|
|
|
}
|
|
|
|
|
|
|
|
getSyncStateClass (stateId: number) {
|
|
|
|
return [ 'pt-badge', MyVideoChannelSyncsComponent.STATE_CLASS_BY_ID[stateId] ]
|
|
|
|
}
|
|
|
|
|
|
|
|
getIdentifier () {
|
|
|
|
return 'MyVideoChannelsSyncComponent'
|
|
|
|
}
|
|
|
|
|
|
|
|
getChannelUrl (name: string) {
|
|
|
|
return '/c/' + name
|
|
|
|
}
|
|
|
|
}
|