diff options
Diffstat (limited to 'client/src/app/shared/video/modals/video-report.component.ts')
-rw-r--r-- | client/src/app/shared/video/modals/video-report.component.ts | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/client/src/app/shared/video/modals/video-report.component.ts b/client/src/app/shared/video/modals/video-report.component.ts new file mode 100644 index 000000000..725dd020f --- /dev/null +++ b/client/src/app/shared/video/modals/video-report.component.ts | |||
@@ -0,0 +1,81 @@ | |||
1 | import { Component, Input, OnInit, ViewChild } from '@angular/core' | ||
2 | import { Notifier } from '@app/core' | ||
3 | import { FormReactive } from '../../../shared/forms' | ||
4 | import { VideoDetails } from '../../../shared/video/video-details.model' | ||
5 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
6 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | ||
7 | import { VideoAbuseValidatorsService } from '@app/shared/forms/form-validators/video-abuse-validators.service' | ||
8 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
9 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | ||
10 | import { VideoAbuseService } from '@app/shared/video-abuse' | ||
11 | |||
12 | @Component({ | ||
13 | selector: 'my-video-report', | ||
14 | templateUrl: './video-report.component.html', | ||
15 | styleUrls: [ './video-report.component.scss' ] | ||
16 | }) | ||
17 | export class VideoReportComponent extends FormReactive implements OnInit { | ||
18 | @Input() video: VideoDetails = null | ||
19 | |||
20 | @ViewChild('modal') modal: NgbModal | ||
21 | |||
22 | error: string = null | ||
23 | |||
24 | private openedModal: NgbModalRef | ||
25 | |||
26 | constructor ( | ||
27 | protected formValidatorService: FormValidatorService, | ||
28 | private modalService: NgbModal, | ||
29 | private videoAbuseValidatorsService: VideoAbuseValidatorsService, | ||
30 | private videoAbuseService: VideoAbuseService, | ||
31 | private notifier: Notifier, | ||
32 | private i18n: I18n | ||
33 | ) { | ||
34 | super() | ||
35 | } | ||
36 | |||
37 | get currentHost () { | ||
38 | return window.location.host | ||
39 | } | ||
40 | |||
41 | get originHost () { | ||
42 | if (this.isRemoteVideo()) { | ||
43 | return this.video.account.host | ||
44 | } | ||
45 | |||
46 | return '' | ||
47 | } | ||
48 | |||
49 | ngOnInit () { | ||
50 | this.buildForm({ | ||
51 | reason: this.videoAbuseValidatorsService.VIDEO_ABUSE_REASON | ||
52 | }) | ||
53 | } | ||
54 | |||
55 | show () { | ||
56 | this.openedModal = this.modalService.open(this.modal, { keyboard: false }) | ||
57 | } | ||
58 | |||
59 | hide () { | ||
60 | this.openedModal.close() | ||
61 | this.openedModal = null | ||
62 | } | ||
63 | |||
64 | report () { | ||
65 | const reason = this.form.value['reason'] | ||
66 | |||
67 | this.videoAbuseService.reportVideo(this.video.id, reason) | ||
68 | .subscribe( | ||
69 | () => { | ||
70 | this.notifier.success(this.i18n('Video reported.')) | ||
71 | this.hide() | ||
72 | }, | ||
73 | |||
74 | err => this.notifier.error(err.message) | ||
75 | ) | ||
76 | } | ||
77 | |||
78 | isRemoteVideo () { | ||
79 | return !this.video.isLocal | ||
80 | } | ||
81 | } | ||