]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-moderation/video-block.component.ts
Merge branch 'release/4.3.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / video-block.component.ts
CommitLineData
3cfa8176 1import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
67ed6552 2import { Notifier } from '@app/core'
eaa52952 3import { prepareIcu } from '@app/helpers'
5c5bcea2 4import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
67ed6552 5import { Video } from '@app/shared/shared-main'
26b7305a
C
6import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
7ed1edbb 8import { VIDEO_BLOCK_REASON_VALIDATOR } from '../form-validators/video-block-validators'
67ed6552 9import { VideoBlockService } from './video-block.service'
26b7305a
C
10
11@Component({
5baee5fc
RK
12 selector: 'my-video-block',
13 templateUrl: './video-block.component.html',
14 styleUrls: [ './video-block.component.scss' ]
26b7305a 15})
5baee5fc 16export class VideoBlockComponent extends FormReactive implements OnInit {
f36da21e 17 @ViewChild('modal', { static: true }) modal: NgbModal
26b7305a 18
5baee5fc 19 @Output() videoBlocked = new EventEmitter()
3a0fb65c 20
3cfa8176
C
21 videos: Video[]
22
26b7305a
C
23 error: string = null
24
25 private openedModal: NgbModalRef
26
27 constructor (
5c5bcea2 28 protected formReactiveService: FormReactiveService,
26b7305a 29 private modalService: NgbModal,
5baee5fc 30 private videoBlocklistService: VideoBlockService,
66357162 31 private notifier: Notifier
26b7305a
C
32 ) {
33 super()
34 }
35
36 ngOnInit () {
5abb9fbb
C
37 const defaultValues = { unfederate: 'true' }
38
26b7305a 39 this.buildForm({
7ed1edbb 40 reason: VIDEO_BLOCK_REASON_VALIDATOR,
5abb9fbb
C
41 unfederate: null
42 }, defaultValues)
26b7305a
C
43 }
44
3cfa8176
C
45 isMultiple () {
46 return this.videos.length > 1
47 }
48
49 getSingleVideo () {
50 return this.videos[0]
51 }
52
53 hasLive () {
54 return this.videos.some(v => v.isLive)
55 }
56
57 hasLocal () {
58 return this.videos.some(v => v.isLocal)
59 }
60
61 show (videos: Video[]) {
62 this.videos = videos
63
24e7916c 64 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
26b7305a
C
65 }
66
67 hide () {
68 this.openedModal.close()
69 this.openedModal = null
70 }
71
5baee5fc 72 block () {
3cfa8176
C
73 const options = this.videos.map(v => ({
74 videoId: v.id,
75 reason: this.form.value['reason'] || undefined,
76 unfederate: v.isLocal
77 ? this.form.value['unfederate']
78 : undefined
79 }))
26b7305a 80
3cfa8176 81 this.videoBlocklistService.blockVideo(options)
1378c0d3
C
82 .subscribe({
83 next: () => {
baf99fcc 84 const message = prepareIcu($localize`{count, plural, =1 {Blocked {videoName}.} other {Blocked {count} videos.}}`)(
eaa52952
C
85 { count: this.videos.length, videoName: this.getSingleVideo().name },
86 $localize`Blocked ${this.videos.length} videos.`
87 )
3cfa8176
C
88
89 this.notifier.success(message)
26b7305a 90 this.hide()
3a0fb65c 91
3cfa8176
C
92 for (const o of options) {
93 const video = this.videos.find(v => v.id === o.videoId)
94
95 video.blacklisted = true
96 video.blacklistedReason = o.reason
97 }
3a0fb65c 98
5baee5fc 99 this.videoBlocked.emit()
26b7305a
C
100 },
101
1378c0d3
C
102 error: err => this.notifier.error(err.message)
103 })
26b7305a
C
104 }
105}