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