]>
Commit | Line | Data |
---|---|---|
df98563e | 1 | import { Component, Input, OnInit, ViewChild } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier } from '@app/core' |
e309822b | 3 | import { FormReactive, VideoAbuseService } from '../../../shared/index' |
4635f59d | 4 | import { VideoDetails } from '../../../shared/video/video-details.model' |
b1d40cff | 5 | import { I18n } from '@ngx-translate/i18n-polyfill' |
d18d6478 | 6 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
e309822b | 7 | import { VideoAbuseValidatorsService } from '@app/shared/forms/form-validators/video-abuse-validators.service' |
63347a0f C |
8 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
9 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | |
4f8c0eb0 C |
10 | |
11 | @Component({ | |
12 | selector: 'my-video-report', | |
5f0805d3 C |
13 | templateUrl: './video-report.component.html', |
14 | styleUrls: [ './video-report.component.scss' ] | |
4f8c0eb0 C |
15 | }) |
16 | export class VideoReportComponent extends FormReactive implements OnInit { | |
404b54e1 | 17 | @Input() video: VideoDetails = null |
4f8c0eb0 | 18 | |
63347a0f | 19 | @ViewChild('modal') modal: NgbModal |
4f8c0eb0 | 20 | |
df98563e | 21 | error: string = null |
4f8c0eb0 | 22 | |
63347a0f C |
23 | private openedModal: NgbModalRef |
24 | ||
df98563e | 25 | constructor ( |
d18d6478 | 26 | protected formValidatorService: FormValidatorService, |
63347a0f | 27 | private modalService: NgbModal, |
e309822b | 28 | private videoAbuseValidatorsService: VideoAbuseValidatorsService, |
7ddd02c9 | 29 | private videoAbuseService: VideoAbuseService, |
f8b2c1b4 | 30 | private notifier: Notifier, |
b1d40cff C |
31 | private i18n: I18n |
32 | ) { | |
df98563e | 33 | super() |
4f8c0eb0 C |
34 | } |
35 | ||
a1b2f876 C |
36 | get currentHost () { |
37 | return window.location.host | |
38 | } | |
39 | ||
40 | get originHost () { | |
41 | if (this.isRemoteVideo()) { | |
42 | return this.video.account.host | |
43 | } | |
44 | ||
45 | return '' | |
46 | } | |
47 | ||
df98563e | 48 | ngOnInit () { |
d18d6478 | 49 | this.buildForm({ |
e309822b | 50 | reason: this.videoAbuseValidatorsService.VIDEO_ABUSE_REASON |
df98563e | 51 | }) |
4f8c0eb0 C |
52 | } |
53 | ||
df98563e | 54 | show () { |
63347a0f | 55 | this.openedModal = this.modalService.open(this.modal, { keyboard: false }) |
4f8c0eb0 C |
56 | } |
57 | ||
df98563e | 58 | hide () { |
63347a0f C |
59 | this.openedModal.close() |
60 | this.openedModal = null | |
4f8c0eb0 C |
61 | } |
62 | ||
df98563e C |
63 | report () { |
64 | const reason = this.form.value['reason'] | |
4f8c0eb0 | 65 | |
11ac88de | 66 | this.videoAbuseService.reportVideo(this.video.id, reason) |
5769e1db C |
67 | .subscribe( |
68 | () => { | |
f8b2c1b4 | 69 | this.notifier.success(this.i18n('Video reported.')) |
df98563e | 70 | this.hide() |
5769e1db | 71 | }, |
4f8c0eb0 | 72 | |
f8b2c1b4 | 73 | err => this.notifier.error(err.message) |
df98563e | 74 | ) |
4f8c0eb0 | 75 | } |
a1b2f876 C |
76 | |
77 | isRemoteVideo () { | |
78 | return !this.video.isLocal | |
79 | } | |
4f8c0eb0 | 80 | } |