]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/modals/video-blacklist.component.ts
Add ListOverflow component to prevent sub-menu overflow
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / modals / video-blacklist.component.ts
CommitLineData
3a0fb65c 1import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
f8b2c1b4 2import { Notifier, RedirectService } from '@app/core'
3a0fb65c 3import { VideoBlacklistService } from '../../../shared/video-blacklist'
26b7305a
C
4import { I18n } from '@ngx-translate/i18n-polyfill'
5import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
6import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
3a0fb65c 8import { FormReactive, VideoBlacklistValidatorsService } from '@app/shared/forms'
be27ef3b 9import { Video } from '@app/shared/video/video.model'
26b7305a
C
10
11@Component({
12 selector: 'my-video-blacklist',
13 templateUrl: './video-blacklist.component.html',
14 styleUrls: [ './video-blacklist.component.scss' ]
15})
16export class VideoBlacklistComponent extends FormReactive implements OnInit {
be27ef3b 17 @Input() video: Video = null
26b7305a 18
f36da21e 19 @ViewChild('modal', { static: true }) modal: NgbModal
26b7305a 20
3a0fb65c
C
21 @Output() videoBlacklisted = new EventEmitter()
22
26b7305a
C
23 error: string = null
24
25 private openedModal: NgbModalRef
26
27 constructor (
28 protected formValidatorService: FormValidatorService,
29 private modalService: NgbModal,
30 private videoBlacklistValidatorsService: VideoBlacklistValidatorsService,
31 private videoBlacklistService: VideoBlacklistService,
f8b2c1b4 32 private notifier: Notifier,
26b7305a
C
33 private redirectService: RedirectService,
34 private i18n: I18n
35 ) {
36 super()
37 }
38
39 ngOnInit () {
5abb9fbb
C
40 const defaultValues = { unfederate: 'true' }
41
26b7305a 42 this.buildForm({
5abb9fbb
C
43 reason: this.videoBlacklistValidatorsService.VIDEO_BLACKLIST_REASON,
44 unfederate: null
45 }, defaultValues)
26b7305a
C
46 }
47
48 show () {
24e7916c 49 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
26b7305a
C
50 }
51
52 hide () {
53 this.openedModal.close()
54 this.openedModal = null
55 }
56
57 blacklist () {
58 const reason = this.form.value[ 'reason' ] || undefined
5abb9fbb 59 const unfederate = this.video.isLocal ? this.form.value[ 'unfederate' ] : undefined
26b7305a 60
5abb9fbb 61 this.videoBlacklistService.blacklistVideo(this.video.id, reason, unfederate)
26b7305a
C
62 .subscribe(
63 () => {
f8b2c1b4 64 this.notifier.success(this.i18n('Video blacklisted.'))
26b7305a 65 this.hide()
3a0fb65c
C
66
67 this.video.blacklisted = true
68 this.video.blacklistedReason = reason
69
70 this.videoBlacklisted.emit()
26b7305a
C
71 },
72
f8b2c1b4 73 err => this.notifier.error(err.message)
26b7305a
C
74 )
75 }
76}