]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-abuse-list/moderation-comment-modal.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-abuse-list / moderation-comment-modal.component.ts
CommitLineData
efc9e845 1import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
f8b2c1b4 2import { Notifier } from '@app/core'
5c5bcea2 3import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
d95d1559 4import { AbuseService } from '@app/shared/shared-moderation'
efc9e845
C
5import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
6import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
441e453a 7import { AdminAbuse } from '@shared/models'
7ed1edbb 8import { ABUSE_MODERATION_COMMENT_VALIDATOR } from '../form-validators/abuse-validators'
efc9e845
C
9
10@Component({
11 selector: 'my-moderation-comment-modal',
12 templateUrl: './moderation-comment-modal.component.html',
13 styleUrls: [ './moderation-comment-modal.component.scss' ]
14})
15export class ModerationCommentModalComponent extends FormReactive implements OnInit {
f36da21e 16 @ViewChild('modal', { static: true }) modal: NgbModal
efc9e845
C
17 @Output() commentUpdated = new EventEmitter<string>()
18
441e453a 19 private abuseToComment: AdminAbuse
efc9e845
C
20 private openedModal: NgbModalRef
21
22 constructor (
5c5bcea2 23 protected formReactiveService: FormReactiveService,
efc9e845 24 private modalService: NgbModal,
f8b2c1b4 25 private notifier: Notifier,
7ed1edbb 26 private abuseService: AbuseService
efc9e845
C
27 ) {
28 super()
29 }
30
31 ngOnInit () {
32 this.buildForm({
7ed1edbb 33 moderationComment: ABUSE_MODERATION_COMMENT_VALIDATOR
efc9e845
C
34 })
35 }
36
441e453a 37 openModal (abuseToComment: AdminAbuse) {
efc9e845 38 this.abuseToComment = abuseToComment
24e7916c 39 this.openedModal = this.modalService.open(this.modal, { centered: true })
efc9e845
C
40
41 this.form.patchValue({
42 moderationComment: this.abuseToComment.moderationComment
43 })
44 }
45
457bb213 46 hide () {
efc9e845
C
47 this.abuseToComment = undefined
48 this.openedModal.close()
49 this.form.reset()
50 }
51
98ab5dc8 52 banUser () {
9df52d66 53 const moderationComment: string = this.form.value['moderationComment']
efc9e845 54
d95d1559 55 this.abuseService.updateAbuse(this.abuseToComment, { moderationComment })
1378c0d3
C
56 .subscribe({
57 next: () => {
66357162 58 this.notifier.success($localize`Comment updated.`)
efc9e845 59
f8b2c1b4 60 this.commentUpdated.emit(moderationComment)
457bb213 61 this.hide()
f8b2c1b4 62 },
efc9e845 63
1378c0d3
C
64 error: err => this.notifier.error(err.message)
65 })
efc9e845
C
66 }
67
68}