1 import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
4 import { Video } from '@app/shared/shared-main'
5 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
6 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
7 import { VIDEO_BLOCK_REASON_VALIDATOR } from '../form-validators/video-block-validators'
8 import { VideoBlockService } from './video-block.service'
11 selector: 'my-video-block',
12 templateUrl: './video-block.component.html',
13 styleUrls: [ './video-block.component.scss' ]
15 export class VideoBlockComponent extends FormReactive implements OnInit {
16 @ViewChild('modal', { static: true }) modal: NgbModal
18 @Output() videoBlocked = new EventEmitter()
24 private openedModal: NgbModalRef
27 protected formValidatorService: FormValidatorService,
28 private modalService: NgbModal,
29 private videoBlocklistService: VideoBlockService,
30 private notifier: Notifier
36 const defaultValues = { unfederate: 'true' }
39 reason: VIDEO_BLOCK_REASON_VALIDATOR,
45 return this.videos.length > 1
53 return this.videos.some(v => v.isLive)
57 return this.videos.some(v => v.isLocal)
60 show (videos: Video[]) {
63 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
67 this.openedModal.close()
68 this.openedModal = null
72 const options = this.videos.map(v => ({
74 reason: this.form.value['reason'] || undefined,
76 ? this.form.value['unfederate']
80 this.videoBlocklistService.blockVideo(options)
83 const message = this.isMultiple
84 ? $localize`Blocked ${this.videos.length} videos.`
85 : $localize`Blocked ${this.getSingleVideo().name}`
87 this.notifier.success(message)
90 for (const o of options) {
91 const video = this.videos.find(v => v.id === o.videoId)
93 video.blacklisted = true
94 video.blacklistedReason = o.reason
97 this.videoBlocked.emit()
100 error: err => this.notifier.error(err.message)