2020-06-02 18:50:42 +00:00
|
|
|
import { SortMeta } from 'primeng/api'
|
|
|
|
import { filter, switchMap } from 'rxjs/operators'
|
2020-06-23 12:10:17 +00:00
|
|
|
import { AfterViewInit, Component, OnInit } from '@angular/core'
|
|
|
|
import { ActivatedRoute, Params, Router } from '@angular/router'
|
|
|
|
import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable, ServerService } from '@app/core'
|
|
|
|
import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
|
|
|
|
import { VideoBlockService } from '@app/shared/shared-moderation'
|
|
|
|
import { I18n } from '@ngx-translate/i18n-polyfill'
|
|
|
|
import { VideoBlacklist, VideoBlacklistType } from '@shared/models'
|
2020-07-02 14:30:33 +00:00
|
|
|
import { buildVideoEmbed, buildVideoLink } from 'src/assets/player/utils'
|
|
|
|
import { environment } from 'src/environments/environment'
|
|
|
|
import { DomSanitizer } from '@angular/platform-browser'
|
2020-06-02 18:50:42 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-video-block-list',
|
|
|
|
templateUrl: './video-block-list.component.html',
|
2020-08-03 16:06:49 +00:00
|
|
|
styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-block-list.component.scss' ]
|
2020-06-02 18:50:42 +00:00
|
|
|
})
|
2020-06-12 06:12:13 +00:00
|
|
|
export class VideoBlockListComponent extends RestTable implements OnInit, AfterViewInit {
|
2020-07-02 14:30:33 +00:00
|
|
|
blocklist: (VideoBlacklist & { reasonHtml?: string, embedHtml?: string })[] = []
|
2020-06-02 18:50:42 +00:00
|
|
|
totalRecords = 0
|
|
|
|
sort: SortMeta = { field: 'createdAt', order: -1 }
|
|
|
|
pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
|
2020-06-09 14:07:10 +00:00
|
|
|
blocklistTypeFilter: VideoBlacklistType = undefined
|
2020-06-02 18:50:42 +00:00
|
|
|
|
2020-06-09 14:07:10 +00:00
|
|
|
videoBlocklistActions: DropdownAction<VideoBlacklist>[][] = []
|
2020-06-02 18:50:42 +00:00
|
|
|
|
|
|
|
constructor (
|
|
|
|
private notifier: Notifier,
|
|
|
|
private serverService: ServerService,
|
|
|
|
private confirmService: ConfirmService,
|
|
|
|
private videoBlocklistService: VideoBlockService,
|
|
|
|
private markdownRenderer: MarkdownService,
|
2020-07-02 14:30:33 +00:00
|
|
|
private sanitizer: DomSanitizer,
|
2020-06-02 18:50:42 +00:00
|
|
|
private videoService: VideoService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private i18n: I18n
|
|
|
|
) {
|
|
|
|
super()
|
|
|
|
|
|
|
|
this.videoBlocklistActions = [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
label: this.i18n('Internal actions'),
|
2020-06-28 18:28:59 +00:00
|
|
|
isHeader: true,
|
|
|
|
isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED
|
2020-06-02 18:50:42 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: this.i18n('Switch video block to manual'),
|
|
|
|
handler: videoBlock => {
|
|
|
|
this.videoBlocklistService.unblockVideo(videoBlock.video.id).pipe(
|
|
|
|
switchMap(_ => this.videoBlocklistService.blockVideo(videoBlock.video.id, undefined, true))
|
|
|
|
).subscribe(
|
|
|
|
() => {
|
|
|
|
this.notifier.success(this.i18n('Video {{name}} switched to manual block.', { name: videoBlock.video.name }))
|
|
|
|
this.loadData()
|
|
|
|
},
|
2020-06-12 06:12:13 +00:00
|
|
|
|
2020-06-02 18:50:42 +00:00
|
|
|
err => this.notifier.error(err.message)
|
|
|
|
)
|
2020-06-28 18:28:59 +00:00
|
|
|
},
|
|
|
|
isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED
|
2020-06-02 18:50:42 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
label: this.i18n('Actions for the video'),
|
2020-06-12 06:12:13 +00:00
|
|
|
isHeader: true
|
2020-06-02 18:50:42 +00:00
|
|
|
},
|
|
|
|
{
|
2020-06-28 18:28:59 +00:00
|
|
|
label: this.i18n('Unblock'),
|
2020-06-02 18:50:42 +00:00
|
|
|
handler: videoBlock => this.unblockVideo(videoBlock)
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2020-06-28 18:28:59 +00:00
|
|
|
label: this.i18n('Delete'),
|
2020-06-02 18:50:42 +00:00
|
|
|
handler: async videoBlock => {
|
|
|
|
const res = await this.confirmService.confirm(
|
|
|
|
this.i18n('Do you really want to delete this video?'),
|
|
|
|
this.i18n('Delete')
|
|
|
|
)
|
|
|
|
if (res === false) return
|
|
|
|
|
|
|
|
this.videoService.removeVideo(videoBlock.video.id)
|
|
|
|
.subscribe(
|
|
|
|
() => {
|
|
|
|
this.notifier.success(this.i18n('Video deleted.'))
|
|
|
|
},
|
|
|
|
|
|
|
|
err => this.notifier.error(err.message)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit () {
|
|
|
|
this.serverService.getConfig()
|
|
|
|
.subscribe(config => {
|
|
|
|
// don't filter if auto-blacklist is not enabled as this will be the only list
|
|
|
|
if (config.autoBlacklist.videos.ofUsers.enabled) {
|
2020-06-09 14:07:10 +00:00
|
|
|
this.blocklistTypeFilter = VideoBlacklistType.MANUAL
|
2020-06-02 18:50:42 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
this.initialize()
|
|
|
|
|
|
|
|
this.route.queryParams
|
|
|
|
.pipe(filter(params => params.search !== undefined && params.search !== null))
|
|
|
|
.subscribe(params => {
|
|
|
|
this.search = params.search
|
|
|
|
this.setTableFilter(params.search)
|
|
|
|
this.loadData()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterViewInit () {
|
|
|
|
if (this.search) this.setTableFilter(this.search)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Table filter functions */
|
|
|
|
onBlockSearch (event: Event) {
|
|
|
|
this.onSearch(event)
|
|
|
|
this.setQueryParams((event.target as HTMLInputElement).value)
|
|
|
|
}
|
|
|
|
|
|
|
|
setQueryParams (search: string) {
|
|
|
|
const queryParams: Params = {}
|
|
|
|
if (search) Object.assign(queryParams, { search })
|
|
|
|
this.router.navigate([ '/admin/moderation/video-blocks/list' ], { queryParams })
|
|
|
|
}
|
|
|
|
|
|
|
|
resetTableFilter () {
|
|
|
|
this.setTableFilter('')
|
|
|
|
this.setQueryParams('')
|
|
|
|
this.resetSearch()
|
|
|
|
}
|
|
|
|
/* END Table filter functions */
|
|
|
|
|
|
|
|
getIdentifier () {
|
|
|
|
return 'VideoBlockListComponent'
|
|
|
|
}
|
|
|
|
|
2020-06-09 14:07:10 +00:00
|
|
|
getVideoUrl (videoBlock: VideoBlacklist) {
|
2020-06-02 18:50:42 +00:00
|
|
|
return Video.buildClientUrl(videoBlock.video.uuid)
|
|
|
|
}
|
|
|
|
|
|
|
|
booleanToText (value: boolean) {
|
|
|
|
if (value === true) return this.i18n('yes')
|
|
|
|
|
|
|
|
return this.i18n('no')
|
|
|
|
}
|
|
|
|
|
|
|
|
toHtml (text: string) {
|
|
|
|
return this.markdownRenderer.textMarkdownToHTML(text)
|
|
|
|
}
|
|
|
|
|
2020-06-09 14:07:10 +00:00
|
|
|
async unblockVideo (entry: VideoBlacklist) {
|
2020-06-02 18:50:42 +00:00
|
|
|
const confirmMessage = this.i18n(
|
|
|
|
'Do you really want to unblock this video? It will be available again in the videos list.'
|
|
|
|
)
|
|
|
|
|
|
|
|
const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblock'))
|
|
|
|
if (res === false) return
|
|
|
|
|
|
|
|
this.videoBlocklistService.unblockVideo(entry.video.id).subscribe(
|
|
|
|
() => {
|
|
|
|
this.notifier.success(this.i18n('Video {{name}} unblocked.', { name: entry.video.name }))
|
|
|
|
this.loadData()
|
|
|
|
},
|
|
|
|
|
|
|
|
err => this.notifier.error(err.message)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-07-02 14:30:33 +00:00
|
|
|
getVideoEmbed (entry: VideoBlacklist) {
|
|
|
|
return buildVideoEmbed(
|
|
|
|
buildVideoLink({
|
|
|
|
baseUrl: `${environment.embedUrl}/videos/embed/${entry.video.uuid}`,
|
|
|
|
title: false,
|
|
|
|
warningTitle: false
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-06-02 18:50:42 +00:00
|
|
|
protected loadData () {
|
|
|
|
this.videoBlocklistService.listBlocks({
|
|
|
|
pagination: this.pagination,
|
|
|
|
sort: this.sort,
|
2020-06-12 06:12:13 +00:00
|
|
|
search: this.search
|
2020-06-02 18:50:42 +00:00
|
|
|
})
|
|
|
|
.subscribe(
|
|
|
|
async resultList => {
|
|
|
|
this.totalRecords = resultList.total
|
|
|
|
|
|
|
|
this.blocklist = resultList.data
|
|
|
|
|
|
|
|
for (const element of this.blocklist) {
|
2020-07-02 14:30:33 +00:00
|
|
|
Object.assign(element, {
|
|
|
|
reasonHtml: await this.toHtml(element.reason),
|
|
|
|
embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(element))
|
|
|
|
})
|
2020-06-02 18:50:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
err => this.notifier.error(err.message)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|