]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-moderation/report-modals/video-report.component.ts
Fix report modal error
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / report-modals / video-report.component.ts
1 import { mapValues, pickBy } from 'lodash-es'
2 import { Component, Input, OnInit, ViewChild } from '@angular/core'
3 import { DomSanitizer } from '@angular/platform-browser'
4 import { Notifier } from '@app/core'
5 import { ABUSE_REASON_VALIDATOR } from '@app/shared/form-validators/abuse-validators'
6 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
7 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
8 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
9 import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
10 import { AbusePredefinedReasonsString } from '@shared/models'
11 import { Video } from '../../shared-main'
12 import { AbuseService } from '../abuse.service'
13
14 @Component({
15 selector: 'my-video-report',
16 templateUrl: './video-report.component.html',
17 styleUrls: [ './report.component.scss' ]
18 })
19 export class VideoReportComponent extends FormReactive implements OnInit {
20 @Input() video: Video = null
21
22 @ViewChild('modal', { static: true }) modal: NgbModal
23
24 error: string = null
25 predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
26
27 private openedModal: NgbModalRef
28
29 constructor (
30 protected formValidatorService: FormValidatorService,
31 private modalService: NgbModal,
32 private abuseService: AbuseService,
33 private notifier: Notifier,
34 private sanitizer: DomSanitizer
35 ) {
36 super()
37 }
38
39 get currentHost () {
40 return window.location.host
41 }
42
43 get originHost () {
44 if (this.isRemote()) {
45 return this.video.account.host
46 }
47
48 return ''
49 }
50
51 get timestamp () {
52 return this.form.get('timestamp').value
53 }
54
55 ngOnInit () {
56 this.buildForm({
57 reason: ABUSE_REASON_VALIDATOR,
58 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null),
59 timestamp: {
60 hasStart: null,
61 startAt: null,
62 hasEnd: null,
63 endAt: null
64 }
65 })
66
67 this.predefinedReasons = this.abuseService.getPrefefinedReasons('video')
68 }
69
70 show () {
71 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
72 }
73
74 hide () {
75 this.openedModal.close()
76 this.openedModal = null
77 }
78
79 report () {
80 const reason = this.form.get('reason').value
81 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
82 const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value
83
84 this.abuseService.reportVideo({
85 reason,
86 predefinedReasons,
87 video: {
88 id: this.video.id,
89 startAt: hasStart && startAt ? startAt : undefined,
90 endAt: hasEnd && endAt ? endAt : undefined
91 }
92 }).subscribe({
93 next: () => {
94 this.notifier.success($localize`Video reported.`)
95 this.hide()
96 },
97
98 error: err => this.notifier.error(err.message)
99 })
100 }
101
102 isRemote () {
103 return !this.video.isLocal
104 }
105 }