]>
Commit | Line | Data |
---|---|---|
efc9e845 | 1 | import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier } from '@app/core' |
7ed1edbb | 3 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' |
d95d1559 | 4 | import { AbuseService } from '@app/shared/shared-moderation' |
efc9e845 C |
5 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
6 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | |
441e453a | 7 | import { AdminAbuse } from '@shared/models' |
7ed1edbb | 8 | import { 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 | }) | |
15 | export 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 ( | |
23 | protected formValidatorService: FormValidatorService, | |
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 | ||
52 | async banUser () { | |
f8b2c1b4 | 53 | const moderationComment: string = this.form.value[ 'moderationComment' ] |
efc9e845 | 54 | |
d95d1559 | 55 | this.abuseService.updateAbuse(this.abuseToComment, { moderationComment }) |
f8b2c1b4 C |
56 | .subscribe( |
57 | () => { | |
66357162 | 58 | this.notifier.success($localize`Comment updated.`) |
efc9e845 | 59 | |
f8b2c1b4 | 60 | this.commentUpdated.emit(moderationComment) |
457bb213 | 61 | this.hide() |
f8b2c1b4 | 62 | }, |
efc9e845 | 63 | |
f8b2c1b4 C |
64 | err => this.notifier.error(err.message) |
65 | ) | |
efc9e845 C |
66 | } |
67 | ||
68 | } |