1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
import { SortMeta } from 'primeng/api'
import { mergeMap } from 'rxjs'
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 = [
[
{
label: $localize`List imports`,
linkBuilder: () => [ '/my-library/video-imports' ],
queryParamsBuilder: sync => ({ search: `videoChannelSyncId:${sync.id}` }),
iconName: 'cloud-download'
}
],
[
{
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
this.totalRecords = res.total
},
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) {
this.videoChannelService.importVideos(videoChannelSync.channel.name, videoChannelSync.externalChannelUrl, videoChannelSync.id)
.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
}
}
|