1 import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { FormReactive, FormValidatorService, VideoBlockValidatorsService } 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 { VideoBlockService } from './video-block.service'
10 selector: 'my-video-block',
11 templateUrl: './video-block.component.html',
12 styleUrls: [ './video-block.component.scss' ]
14 export class VideoBlockComponent extends FormReactive implements OnInit {
15 @Input() video: Video = null
17 @ViewChild('modal', { static: true }) modal: NgbModal
19 @Output() videoBlocked = new EventEmitter()
23 private openedModal: NgbModalRef
26 protected formValidatorService: FormValidatorService,
27 private modalService: NgbModal,
28 private videoBlockValidatorsService: VideoBlockValidatorsService,
29 private videoBlocklistService: VideoBlockService,
30 private notifier: Notifier
36 const defaultValues = { unfederate: 'true' }
39 reason: this.videoBlockValidatorsService.VIDEO_BLOCK_REASON,
45 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
49 this.openedModal.close()
50 this.openedModal = null
54 const reason = this.form.value[ 'reason' ] || undefined
55 const unfederate = this.video.isLocal ? this.form.value[ 'unfederate' ] : undefined
57 this.videoBlocklistService.blockVideo(this.video.id, reason, unfederate)
60 this.notifier.success($localize`Video blocked.`)
63 this.video.blacklisted = true
64 this.video.blockedReason = reason
66 this.videoBlocked.emit()
69 err => this.notifier.error(err.message)