1 import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { prepareIcu } from '@app/helpers'
4 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
5 import { Video } from '@app/shared/shared-main'
6 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
8 import { VIDEO_BLOCK_REASON_VALIDATOR } from '../form-validators/video-block-validators'
9 import { VideoBlockService } from './video-block.service'
12 selector: 'my-video-block',
13 templateUrl: './video-block.component.html',
14 styleUrls: [ './video-block.component.scss' ]
16 export class VideoBlockComponent extends FormReactive implements OnInit {
17 @ViewChild('modal', { static: true }) modal: NgbModal
19 @Output() videoBlocked = new EventEmitter()
25 private openedModal: NgbModalRef
28 protected formValidatorService: FormValidatorService,
29 private modalService: NgbModal,
30 private videoBlocklistService: VideoBlockService,
31 private notifier: Notifier
37 const defaultValues = { unfederate: 'true' }
40 reason: VIDEO_BLOCK_REASON_VALIDATOR,
46 return this.videos.length > 1
54 return this.videos.some(v => v.isLive)
58 return this.videos.some(v => v.isLocal)
61 show (videos: Video[]) {
64 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
68 this.openedModal.close()
69 this.openedModal = null
73 const options = this.videos.map(v => ({
75 reason: this.form.value['reason'] || undefined,
77 ? this.form.value['unfederate']
81 this.videoBlocklistService.blockVideo(options)
84 const message = prepareIcu($localize`{count, plural, =1 {Blocked {videoName}.} other {Blocked {count} videos.}}`)(
85 { count: this.videos.length, videoName: this.getSingleVideo().name },
86 $localize`Blocked ${this.videos.length} videos.`
89 this.notifier.success(message)
92 for (const o of options) {
93 const video = this.videos.find(v => v.id === o.videoId)
95 video.blacklisted = true
96 video.blacklistedReason = o.reason
99 this.videoBlocked.emit()
102 error: err => this.notifier.error(err.message)