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