aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.ts
blob: f4bce7c48a69de977210e7eb7aa6b2a4720ed88f (plain) (blame)
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
import { Component, OnInit } from '@angular/core'
import { SortMeta } from 'primeng/components/common/sortmeta'
import { Notifier, ServerService } from '@app/core'
import { ConfirmService } from '../../../core'
import { RestPagination, RestTable, VideoBlacklistService } from '../../../shared'
import { VideoBlacklist, VideoBlacklistType } from '../../../../../../shared'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { DropdownAction } from '../../../shared/buttons/action-dropdown.component'
import { Video } from '../../../shared/video/video.model'
import { MarkdownService } from '@app/shared/renderer'

@Component({
  selector: 'my-video-blacklist-list',
  templateUrl: './video-blacklist-list.component.html',
  styleUrls: [ '../moderation.component.scss' ]
})
export class VideoBlacklistListComponent extends RestTable implements OnInit {
  blacklist: (VideoBlacklist & { reasonHtml?: string })[] = []
  totalRecords = 0
  rowsPerPage = 10
  sort: SortMeta = { field: 'createdAt', order: 1 }
  pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
  listBlacklistTypeFilter: VideoBlacklistType = undefined

  videoBlacklistActions: DropdownAction<VideoBlacklist>[] = []

  constructor (
    private notifier: Notifier,
    private serverService: ServerService,
    private confirmService: ConfirmService,
    private videoBlacklistService: VideoBlacklistService,
    private markdownRenderer: MarkdownService,
    private i18n: I18n
  ) {
    super()

    // don't filter if auto-blacklist not enabled as this will be only list
    if (this.serverService.getConfig().autoBlacklist.videos.ofUsers.enabled) {
      this.listBlacklistTypeFilter = VideoBlacklistType.MANUAL
    }

    this.videoBlacklistActions = [
      {
        label: this.i18n('Unblacklist'),
        handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist)
      }
    ]
  }

  ngOnInit () {
    this.initialize()
  }

  getVideoUrl (videoBlacklist: VideoBlacklist) {
    return Video.buildClientUrl(videoBlacklist.video.uuid)
  }

  booleanToText (value: boolean) {
    if (value === true) return this.i18n('yes')

    return this.i18n('no')
  }

  toHtml (text: string) {
    return this.markdownRenderer.textMarkdownToHTML(text)
  }

  async removeVideoFromBlacklist (entry: VideoBlacklist) {
    const confirmMessage = this.i18n(
      'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
    )

    const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist'))
    if (res === false) return

    this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe(
      () => {
        this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name }))
        this.loadData()
      },

      err => this.notifier.error(err.message)
    )
  }

  protected loadData () {
    this.videoBlacklistService.listBlacklist(this.pagination, this.sort, this.listBlacklistTypeFilter)
      .subscribe(
        async resultList => {
          this.totalRecords = resultList.total

          this.blacklist = resultList.data

          for (const element of this.blacklist) {
            Object.assign(element, { reasonHtml: await this.toHtml(element.reason) })
          }
        },

        err => this.notifier.error(err.message)
      )
  }
}