1 import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier, RedirectService } from '@app/core'
3 import { VideoBlacklistService } from '../../../shared/video-blacklist'
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, VideoBlacklistValidatorsService } from '@app/shared/forms'
9 import { Video } from '@app/shared/video/video.model'
12 selector: 'my-video-blacklist',
13 templateUrl: './video-blacklist.component.html',
14 styleUrls: [ './video-blacklist.component.scss' ]
16 export class VideoBlacklistComponent extends FormReactive implements OnInit {
17 @Input() video: Video = null
19 @ViewChild('modal', { static: true }) modal: NgbModal
21 @Output() videoBlacklisted = new EventEmitter()
25 private openedModal: NgbModalRef
28 protected formValidatorService: FormValidatorService,
29 private modalService: NgbModal,
30 private videoBlacklistValidatorsService: VideoBlacklistValidatorsService,
31 private videoBlacklistService: VideoBlacklistService,
32 private notifier: Notifier,
33 private redirectService: RedirectService,
40 const defaultValues = { unfederate: 'true' }
43 reason: this.videoBlacklistValidatorsService.VIDEO_BLACKLIST_REASON,
49 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
53 this.openedModal.close()
54 this.openedModal = null
58 const reason = this.form.value[ 'reason' ] || undefined
59 const unfederate = this.video.isLocal ? this.form.value[ 'unfederate' ] : undefined
61 this.videoBlacklistService.blacklistVideo(this.video.id, reason, unfederate)
64 this.notifier.success(this.i18n('Video blacklisted.'))
67 this.video.blacklisted = true
68 this.video.blacklistedReason = reason
70 this.videoBlacklisted.emit()
73 err => this.notifier.error(err.message)