]>
Commit | Line | Data |
---|---|---|
efc9e845 | 1 | import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier } from '@app/core' |
d95d1559 C |
3 | import { FormReactive, FormValidatorService, AbuseValidatorsService } from '@app/shared/shared-forms' |
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' | |
67ed6552 | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
d95d1559 | 8 | import { Abuse } from '@shared/models' |
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 | ||
d95d1559 | 19 | private abuseToComment: Abuse |
efc9e845 C |
20 | private openedModal: NgbModalRef |
21 | ||
22 | constructor ( | |
23 | protected formValidatorService: FormValidatorService, | |
24 | private modalService: NgbModal, | |
f8b2c1b4 | 25 | private notifier: Notifier, |
d95d1559 C |
26 | private abuseService: AbuseService, |
27 | private abuseValidatorsService: AbuseValidatorsService, | |
efc9e845 C |
28 | private i18n: I18n |
29 | ) { | |
30 | super() | |
31 | } | |
32 | ||
33 | ngOnInit () { | |
34 | this.buildForm({ | |
d95d1559 | 35 | moderationComment: this.abuseValidatorsService.ABUSE_MODERATION_COMMENT |
efc9e845 C |
36 | }) |
37 | } | |
38 | ||
d95d1559 | 39 | openModal (abuseToComment: Abuse) { |
efc9e845 | 40 | this.abuseToComment = abuseToComment |
24e7916c | 41 | this.openedModal = this.modalService.open(this.modal, { centered: true }) |
efc9e845 C |
42 | |
43 | this.form.patchValue({ | |
44 | moderationComment: this.abuseToComment.moderationComment | |
45 | }) | |
46 | } | |
47 | ||
457bb213 | 48 | hide () { |
efc9e845 C |
49 | this.abuseToComment = undefined |
50 | this.openedModal.close() | |
51 | this.form.reset() | |
52 | } | |
53 | ||
54 | async banUser () { | |
f8b2c1b4 | 55 | const moderationComment: string = this.form.value[ 'moderationComment' ] |
efc9e845 | 56 | |
d95d1559 | 57 | this.abuseService.updateAbuse(this.abuseToComment, { moderationComment }) |
f8b2c1b4 C |
58 | .subscribe( |
59 | () => { | |
60 | this.notifier.success(this.i18n('Comment updated.')) | |
efc9e845 | 61 | |
f8b2c1b4 | 62 | this.commentUpdated.emit(moderationComment) |
457bb213 | 63 | this.hide() |
f8b2c1b4 | 64 | }, |
efc9e845 | 65 | |
f8b2c1b4 C |
66 | err => this.notifier.error(err.message) |
67 | ) | |
efc9e845 C |
68 | } |
69 | ||
70 | } |