1 import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier, RedirectService } from '@app/core'
3 import { VideoBlockService } from '../../video-block'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
6 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
8 import { FormReactive, VideoBlockValidatorsService } from '@app/shared/forms'
9 import { Video } from '@app/shared/video/video.model'
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 @Input() video: Video = null
19 @ViewChild('modal', { static: true }) modal: NgbModal
21 @Output() videoBlocked = new EventEmitter()
25 private openedModal: NgbModalRef
28 protected formValidatorService: FormValidatorService,
29 private modalService: NgbModal,
30 private videoBlockValidatorsService: VideoBlockValidatorsService,
31 private videoBlocklistService: VideoBlockService,
32 private notifier: Notifier,
39 const defaultValues = { unfederate: 'true' }
42 reason: this.videoBlockValidatorsService.VIDEO_BLOCK_REASON,
48 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
52 this.openedModal.close()
53 this.openedModal = null
57 const reason = this.form.value[ 'reason' ] || undefined
58 const unfederate = this.video.isLocal ? this.form.value[ 'unfederate' ] : undefined
60 this.videoBlocklistService.blockVideo(this.video.id, reason, unfederate)
63 this.notifier.success(this.i18n('Video blocked.'))
66 this.video.blacklisted = true
67 this.video.blockedReason = reason
69 this.videoBlocked.emit()
72 err => this.notifier.error(err.message)