import { SortMeta } from 'primeng/api'
import { finalize } from 'rxjs/operators'
-import { Component, OnInit } from '@angular/core'
+import { Component, OnInit, ViewChild } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { AuthService, ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
import { AdvancedInputFilter } from '@app/shared/shared-forms'
import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
+import { VideoBlockComponent, VideoBlockService } from '@app/shared/shared-moderation'
import { VideoActionsDisplayType } from '@app/shared/shared-video-miniature'
import { UserRight, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
+import { VideoAdminService } from './video-admin.service'
@Component({
selector: 'my-video-list',
styleUrls: [ './video-list.component.scss' ]
})
export class VideoListComponent extends RestTable implements OnInit {
+ @ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent
+
videos: Video[] = []
totalRecords = 0
selectedVideos: Video[] = []
- inputFilters: AdvancedInputFilter[] = [
- {
- title: $localize`Advanced filters`,
- children: [
- {
- queryParams: { search: 'isLocal:false' },
- label: $localize`Remote videos`
- },
- {
- queryParams: { search: 'isLocal:true' },
- label: $localize`Local videos`
- }
- ]
- }
- ]
+ inputFilters: AdvancedInputFilter[]
videoActionsOptions: VideoActionsDisplayType = {
playlist: false,
liveInfo: false
}
- loading = false
+ loading = true
constructor (
protected route: ActivatedRoute,
private confirmService: ConfirmService,
private auth: AuthService,
private notifier: Notifier,
- private videoService: VideoService
+ private videoService: VideoService,
+ private videoAdminService: VideoAdminService,
+ private videoBlockService: VideoBlockService
) {
super()
}
ngOnInit () {
this.initialize()
+ this.inputFilters = this.videoAdminService.buildAdminInputFilter()
+
this.bulkVideoActions = [
[
{
label: $localize`Delete`,
handler: videos => this.removeVideos(videos),
isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO)
+ },
+ {
+ label: $localize`Block`,
+ handler: videos => this.videoBlockModal.show(videos),
+ isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => !v.blacklisted)
+ },
+ {
+ label: $localize`Unblock`,
+ handler: videos => this.unblockVideos(videos),
+ isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => v.blacklisted)
}
]
]
this.reloadData()
}
- getPrivacyBadgeClass (privacy: VideoPrivacy) {
- if (privacy === VideoPrivacy.PUBLIC) return 'badge-blue'
+ getPrivacyBadgeClass (video: Video) {
+ if (video.privacy.id === VideoPrivacy.PUBLIC) return 'badge-green'
return 'badge-yellow'
}
- isUnpublished (state: VideoState) {
- return state !== VideoState.LIVE_ENDED && state !== VideoState.PUBLISHED
+ isUnpublished (video: Video) {
+ return video.state.id !== VideoState.LIVE_ENDED && video.state.id !== VideoState.PUBLISHED
}
isAccountBlocked (video: Video) {
return video.blacklisted
}
+ isImport (video: Video) {
+ return video.state.id === VideoState.TO_IMPORT
+ }
+
isHLS (video: Video) {
- return video.streamingPlaylists.some(p => p.type === VideoStreamingPlaylistType.HLS)
+ const p = video.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
+ if (!p) return false
+
+ return p.files.length !== 0
}
isWebTorrent (video: Video) {
return files.reduce((p, f) => p += f.size, 0)
}
+ onVideoBlocked () {
+ this.reloadData()
+ }
+
protected reloadData () {
this.selectedVideos = []
this.loading = true
- this.videoService.getAdminVideos({
+ this.videoAdminService.getAdminVideos({
pagination: this.pagination,
sort: this.sort,
search: this.search
this.videoService.removeVideo(videos.map(v => v.id))
.subscribe({
next: () => {
- this.notifier.success($localize`${videos.length} videos deleted.`)
+ this.notifier.success($localize`Deleted ${videos.length} videos.`)
+ this.reloadData()
+ },
+
+ error: err => this.notifier.error(err.message)
+ })
+ }
+
+ private unblockVideos (videos: Video[]) {
+ this.videoBlockService.unblockVideo(videos.map(v => v.id))
+ .subscribe({
+ next: () => {
+ this.notifier.success($localize`Unblocked ${videos.length} videos.`)
this.reloadData()
},