]>
Commit | Line | Data |
---|---|---|
3a0fb65c | 1 | import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier, RedirectService } from '@app/core' |
5baee5fc | 3 | import { VideoBlockService } from '../../video-block' |
26b7305a C |
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' | |
5baee5fc | 8 | import { FormReactive, VideoBlockValidatorsService } from '@app/shared/forms' |
be27ef3b | 9 | import { Video } from '@app/shared/video/video.model' |
26b7305a C |
10 | |
11 | @Component({ | |
5baee5fc RK |
12 | selector: 'my-video-block', |
13 | templateUrl: './video-block.component.html', | |
14 | styleUrls: [ './video-block.component.scss' ] | |
26b7305a | 15 | }) |
5baee5fc | 16 | export class VideoBlockComponent extends FormReactive implements OnInit { |
be27ef3b | 17 | @Input() video: Video = null |
26b7305a | 18 | |
f36da21e | 19 | @ViewChild('modal', { static: true }) modal: NgbModal |
26b7305a | 20 | |
5baee5fc | 21 | @Output() videoBlocked = new EventEmitter() |
3a0fb65c | 22 | |
26b7305a C |
23 | error: string = null |
24 | ||
25 | private openedModal: NgbModalRef | |
26 | ||
27 | constructor ( | |
28 | protected formValidatorService: FormValidatorService, | |
29 | private modalService: NgbModal, | |
5baee5fc RK |
30 | private videoBlockValidatorsService: VideoBlockValidatorsService, |
31 | private videoBlocklistService: VideoBlockService, | |
f8b2c1b4 | 32 | private notifier: Notifier, |
26b7305a C |
33 | private i18n: I18n |
34 | ) { | |
35 | super() | |
36 | } | |
37 | ||
38 | ngOnInit () { | |
5abb9fbb C |
39 | const defaultValues = { unfederate: 'true' } |
40 | ||
26b7305a | 41 | this.buildForm({ |
5baee5fc | 42 | reason: this.videoBlockValidatorsService.VIDEO_BLOCK_REASON, |
5abb9fbb C |
43 | unfederate: null |
44 | }, defaultValues) | |
26b7305a C |
45 | } |
46 | ||
47 | show () { | |
24e7916c | 48 | this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false }) |
26b7305a C |
49 | } |
50 | ||
51 | hide () { | |
52 | this.openedModal.close() | |
53 | this.openedModal = null | |
54 | } | |
55 | ||
5baee5fc | 56 | block () { |
26b7305a | 57 | const reason = this.form.value[ 'reason' ] || undefined |
5abb9fbb | 58 | const unfederate = this.video.isLocal ? this.form.value[ 'unfederate' ] : undefined |
26b7305a | 59 | |
5baee5fc | 60 | this.videoBlocklistService.blockVideo(this.video.id, reason, unfederate) |
26b7305a C |
61 | .subscribe( |
62 | () => { | |
5baee5fc | 63 | this.notifier.success(this.i18n('Video blocked.')) |
26b7305a | 64 | this.hide() |
3a0fb65c C |
65 | |
66 | this.video.blacklisted = true | |
5baee5fc | 67 | this.video.blockedReason = reason |
3a0fb65c | 68 | |
5baee5fc | 69 | this.videoBlocked.emit() |
26b7305a C |
70 | }, |
71 | ||
f8b2c1b4 | 72 | err => this.notifier.error(err.message) |
26b7305a C |
73 | ) |
74 | } | |
75 | } |