2018-08-13 11:54:11 +02:00
|
|
|
import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
|
2018-12-19 16:04:34 +01:00
|
|
|
import { Notifier } from '@app/core'
|
2022-10-07 15:26:53 +02:00
|
|
|
import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
|
2020-07-01 16:05:30 +02:00
|
|
|
import { AbuseService } from '@app/shared/shared-moderation'
|
2018-08-13 11:54:11 +02:00
|
|
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
|
|
|
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
|
2020-07-24 17:21:25 +02:00
|
|
|
import { AdminAbuse } from '@shared/models'
|
2020-08-17 11:47:04 +02:00
|
|
|
import { ABUSE_MODERATION_COMMENT_VALIDATOR } from '../form-validators/abuse-validators'
|
2018-08-13 11:54:11 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-moderation-comment-modal',
|
|
|
|
templateUrl: './moderation-comment-modal.component.html',
|
|
|
|
styleUrls: [ './moderation-comment-modal.component.scss' ]
|
|
|
|
})
|
|
|
|
export class ModerationCommentModalComponent extends FormReactive implements OnInit {
|
2019-07-24 16:05:59 +02:00
|
|
|
@ViewChild('modal', { static: true }) modal: NgbModal
|
2018-08-13 11:54:11 +02:00
|
|
|
@Output() commentUpdated = new EventEmitter<string>()
|
|
|
|
|
2020-07-24 17:21:25 +02:00
|
|
|
private abuseToComment: AdminAbuse
|
2018-08-13 11:54:11 +02:00
|
|
|
private openedModal: NgbModalRef
|
|
|
|
|
|
|
|
constructor (
|
2022-10-07 15:26:53 +02:00
|
|
|
protected formReactiveService: FormReactiveService,
|
2018-08-13 11:54:11 +02:00
|
|
|
private modalService: NgbModal,
|
2018-12-19 16:04:34 +01:00
|
|
|
private notifier: Notifier,
|
2020-08-17 11:47:04 +02:00
|
|
|
private abuseService: AbuseService
|
2018-08-13 11:54:11 +02:00
|
|
|
) {
|
|
|
|
super()
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit () {
|
|
|
|
this.buildForm({
|
2020-08-17 11:47:04 +02:00
|
|
|
moderationComment: ABUSE_MODERATION_COMMENT_VALIDATOR
|
2018-08-13 11:54:11 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-24 17:21:25 +02:00
|
|
|
openModal (abuseToComment: AdminAbuse) {
|
2018-08-13 11:54:11 +02:00
|
|
|
this.abuseToComment = abuseToComment
|
2020-02-05 20:54:37 +01:00
|
|
|
this.openedModal = this.modalService.open(this.modal, { centered: true })
|
2018-08-13 11:54:11 +02:00
|
|
|
|
|
|
|
this.form.patchValue({
|
|
|
|
moderationComment: this.abuseToComment.moderationComment
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-16 16:05:40 +01:00
|
|
|
hide () {
|
2018-08-13 11:54:11 +02:00
|
|
|
this.abuseToComment = undefined
|
|
|
|
this.openedModal.close()
|
|
|
|
this.form.reset()
|
|
|
|
}
|
|
|
|
|
2021-08-25 16:14:11 +02:00
|
|
|
banUser () {
|
2021-08-17 14:42:53 +02:00
|
|
|
const moderationComment: string = this.form.value['moderationComment']
|
2018-08-13 11:54:11 +02:00
|
|
|
|
2020-07-01 16:05:30 +02:00
|
|
|
this.abuseService.updateAbuse(this.abuseToComment, { moderationComment })
|
2021-08-17 11:27:47 +02:00
|
|
|
.subscribe({
|
|
|
|
next: () => {
|
2020-08-12 10:40:04 +02:00
|
|
|
this.notifier.success($localize`Comment updated.`)
|
2018-08-13 11:54:11 +02:00
|
|
|
|
2018-12-19 16:04:34 +01:00
|
|
|
this.commentUpdated.emit(moderationComment)
|
2019-01-16 16:05:40 +01:00
|
|
|
this.hide()
|
2018-12-19 16:04:34 +01:00
|
|
|
},
|
2018-08-13 11:54:11 +02:00
|
|
|
|
2021-08-17 11:27:47 +02:00
|
|
|
error: err => this.notifier.error(err.message)
|
|
|
|
})
|
2018-08-13 11:54:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|