]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-moderation/video-block.component.ts
We don't need services anymore for validators
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / video-block.component.ts
CommitLineData
3a0fb65c 1import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
67ed6552 2import { Notifier } from '@app/core'
7ed1edbb 3import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
67ed6552 4import { Video } from '@app/shared/shared-main'
26b7305a
C
5import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
6import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
7ed1edbb 7import { VIDEO_BLOCK_REASON_VALIDATOR } from '../form-validators/video-block-validators'
67ed6552 8import { VideoBlockService } from './video-block.service'
26b7305a
C
9
10@Component({
5baee5fc
RK
11 selector: 'my-video-block',
12 templateUrl: './video-block.component.html',
13 styleUrls: [ './video-block.component.scss' ]
26b7305a 14})
5baee5fc 15export class VideoBlockComponent extends FormReactive implements OnInit {
be27ef3b 16 @Input() video: Video = null
26b7305a 17
f36da21e 18 @ViewChild('modal', { static: true }) modal: NgbModal
26b7305a 19
5baee5fc 20 @Output() videoBlocked = new EventEmitter()
3a0fb65c 21
26b7305a
C
22 error: string = null
23
24 private openedModal: NgbModalRef
25
26 constructor (
27 protected formValidatorService: FormValidatorService,
28 private modalService: NgbModal,
5baee5fc 29 private videoBlocklistService: VideoBlockService,
66357162 30 private notifier: Notifier
26b7305a
C
31 ) {
32 super()
33 }
34
35 ngOnInit () {
5abb9fbb
C
36 const defaultValues = { unfederate: 'true' }
37
26b7305a 38 this.buildForm({
7ed1edbb 39 reason: VIDEO_BLOCK_REASON_VALIDATOR,
5abb9fbb
C
40 unfederate: null
41 }, defaultValues)
26b7305a
C
42 }
43
44 show () {
24e7916c 45 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
26b7305a
C
46 }
47
48 hide () {
49 this.openedModal.close()
50 this.openedModal = null
51 }
52
5baee5fc 53 block () {
26b7305a 54 const reason = this.form.value[ 'reason' ] || undefined
5abb9fbb 55 const unfederate = this.video.isLocal ? this.form.value[ 'unfederate' ] : undefined
26b7305a 56
5baee5fc 57 this.videoBlocklistService.blockVideo(this.video.id, reason, unfederate)
26b7305a
C
58 .subscribe(
59 () => {
66357162 60 this.notifier.success($localize`Video blocked.`)
26b7305a 61 this.hide()
3a0fb65c
C
62
63 this.video.blacklisted = true
5baee5fc 64 this.video.blockedReason = reason
3a0fb65c 65
5baee5fc 66 this.videoBlocked.emit()
26b7305a
C
67 },
68
f8b2c1b4 69 err => this.notifier.error(err.message)
26b7305a
C
70 )
71 }
72}