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 { I18n } from '@ngx-translate/i18n-polyfill'
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 @Input() video: Video = null
18 @ViewChild('modal', { static: true }) modal: NgbModal
20 @Output() videoBlocked = new EventEmitter()
24 private openedModal: NgbModalRef
27 protected formValidatorService: FormValidatorService,
28 private modalService: NgbModal,
29 private videoBlockValidatorsService: VideoBlockValidatorsService,
30 private videoBlocklistService: VideoBlockService,
31 private notifier: Notifier,
38 const defaultValues = { unfederate: 'true' }
41 reason: this.videoBlockValidatorsService.VIDEO_BLOCK_REASON,
47 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
51 this.openedModal.close()
52 this.openedModal = null
56 const reason = this.form.value[ 'reason' ] || undefined
57 const unfederate = this.video.isLocal ? this.form.value[ 'unfederate' ] : undefined
59 this.videoBlocklistService.blockVideo(this.video.id, reason, unfederate)
62 this.notifier.success(this.i18n('Video blocked.'))
65 this.video.blacklisted = true
66 this.video.blockedReason = reason
68 this.videoBlocked.emit()
71 err => this.notifier.error(err.message)