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