]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-moderation/report-modals/account-report.component.ts
Update build steps for localization
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / report-modals / account-report.component.ts
1 import { mapValues, pickBy } from 'lodash-es'
2 import { Component, Input, OnInit, ViewChild } from '@angular/core'
3 import { Notifier } from '@app/core'
4 import { AbuseValidatorsService, FormReactive, FormValidatorService } from '@app/shared/shared-forms'
5 import { Account } from '@app/shared/shared-main'
6 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
8 import { I18n } from '@ngx-translate/i18n-polyfill'
9 import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
10 import { AbusePredefinedReasonsString } from '@shared/models'
11 import { AbuseService } from '../abuse.service'
12
13 @Component({
14 selector: 'my-account-report',
15 templateUrl: './report.component.html',
16 styleUrls: [ './report.component.scss' ]
17 })
18 export class AccountReportComponent extends FormReactive implements OnInit {
19 @Input() account: Account = null
20
21 @ViewChild('modal', { static: true }) modal: NgbModal
22
23 error: string = null
24 predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
25 modalTitle: string
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 () {
45 if (this.isRemote()) {
46 return this.account.host
47 }
48
49 return ''
50 }
51
52 ngOnInit () {
53 this.modalTitle = this.i18n('Report {{displayName}}', { displayName: this.account.displayName })
54
55 this.buildForm({
56 reason: this.abuseValidatorsService.ABUSE_REASON,
57 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null)
58 })
59
60 this.predefinedReasons = this.abuseService.getPrefefinedReasons('account')
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,
79 account: {
80 id: this.account.id
81 }
82 }).subscribe(
83 () => {
84 this.notifier.success(this.i18n('Account reported.'))
85 this.hide()
86 },
87
88 err => this.notifier.error(err.message)
89 )
90 }
91
92 isRemote () {
93 return !this.account.isLocal
94 }
95 }