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