1 import { Component, Input, OnInit, ViewChild } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { FormReactive, VideoBlacklistService, VideoBlacklistValidatorsService } from '../../../shared/index'
4 import { VideoDetails } from '../../../shared/video/video-details.model'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
7 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
8 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
9 import { RedirectService } from '@app/core'
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: VideoDetails = null
19 @ViewChild('modal') modal: NgbModal
23 private openedModal: NgbModalRef
26 protected formValidatorService: FormValidatorService,
27 private modalService: NgbModal,
28 private videoBlacklistValidatorsService: VideoBlacklistValidatorsService,
29 private videoBlacklistService: VideoBlacklistService,
30 private notificationsService: NotificationsService,
31 private redirectService: RedirectService,
39 reason: this.videoBlacklistValidatorsService.VIDEO_BLACKLIST_REASON
44 this.openedModal = this.modalService.open(this.modal, { keyboard: false })
48 this.openedModal.close()
49 this.openedModal = null
53 const reason = this.form.value[ 'reason' ] || undefined
55 this.videoBlacklistService.blacklistVideo(this.video.id, reason)
58 this.notificationsService.success(this.i18n('Success'), this.i18n('Video blacklisted.'))
60 this.redirectService.redirectToHomepage()
63 err => this.notificationsService.error(this.i18n('Error'), err.message)