]>
Commit | Line | Data |
---|---|---|
3a0fb65c | 1 | import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' |
67ed6552 C |
2 | import { Notifier } from '@app/core' |
3 | import { FormReactive, FormValidatorService, VideoBlockValidatorsService } from '@app/shared/shared-forms' | |
4 | import { Video } from '@app/shared/shared-main' | |
26b7305a C |
5 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
6 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | |
67ed6552 C |
7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
8 | import { 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 | 15 | export 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 RK |
29 | private videoBlockValidatorsService: VideoBlockValidatorsService, |
30 | private videoBlocklistService: VideoBlockService, | |
f8b2c1b4 | 31 | private notifier: Notifier, |
26b7305a C |
32 | private i18n: I18n |
33 | ) { | |
34 | super() | |
35 | } | |
36 | ||
37 | ngOnInit () { | |
5abb9fbb C |
38 | const defaultValues = { unfederate: 'true' } |
39 | ||
26b7305a | 40 | this.buildForm({ |
5baee5fc | 41 | reason: this.videoBlockValidatorsService.VIDEO_BLOCK_REASON, |
5abb9fbb C |
42 | unfederate: null |
43 | }, defaultValues) | |
26b7305a C |
44 | } |
45 | ||
46 | show () { | |
24e7916c | 47 | this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false }) |
26b7305a C |
48 | } |
49 | ||
50 | hide () { | |
51 | this.openedModal.close() | |
52 | this.openedModal = null | |
53 | } | |
54 | ||
5baee5fc | 55 | block () { |
26b7305a | 56 | const reason = this.form.value[ 'reason' ] || undefined |
5abb9fbb | 57 | const unfederate = this.video.isLocal ? this.form.value[ 'unfederate' ] : undefined |
26b7305a | 58 | |
5baee5fc | 59 | this.videoBlocklistService.blockVideo(this.video.id, reason, unfederate) |
26b7305a C |
60 | .subscribe( |
61 | () => { | |
5baee5fc | 62 | this.notifier.success(this.i18n('Video blocked.')) |
26b7305a | 63 | this.hide() |
3a0fb65c C |
64 | |
65 | this.video.blacklisted = true | |
5baee5fc | 66 | this.video.blockedReason = reason |
3a0fb65c | 67 | |
5baee5fc | 68 | this.videoBlocked.emit() |
26b7305a C |
69 | }, |
70 | ||
f8b2c1b4 | 71 | err => this.notifier.error(err.message) |
26b7305a C |
72 | ) |
73 | } | |
74 | } |