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