1 import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { FormReactive, VideoAbuseService, VideoAbuseValidatorsService } from '../../../shared'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
6 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
7 import { FormValidatorService } from '../../../shared/forms/form-validators/form-validator.service'
8 import { VideoAbuse } from '../../../../../../shared/models/videos'
11 selector: 'my-moderation-comment-modal',
12 templateUrl: './moderation-comment-modal.component.html',
13 styleUrls: [ './moderation-comment-modal.component.scss' ]
15 export class ModerationCommentModalComponent extends FormReactive implements OnInit {
16 @ViewChild('modal') modal: NgbModal
17 @Output() commentUpdated = new EventEmitter<string>()
19 private abuseToComment: VideoAbuse
20 private openedModal: NgbModalRef
23 protected formValidatorService: FormValidatorService,
24 private modalService: NgbModal,
25 private notifier: Notifier,
26 private videoAbuseService: VideoAbuseService,
27 private videoAbuseValidatorsService: VideoAbuseValidatorsService,
35 moderationComment: this.videoAbuseValidatorsService.VIDEO_ABUSE_REASON
39 openModal (abuseToComment: VideoAbuse) {
40 this.abuseToComment = abuseToComment
41 this.openedModal = this.modalService.open(this.modal)
43 this.form.patchValue({
44 moderationComment: this.abuseToComment.moderationComment
49 this.abuseToComment = undefined
50 this.openedModal.close()
55 const moderationComment: string = this.form.value[ 'moderationComment' ]
57 this.videoAbuseService.updateVideoAbuse(this.abuseToComment, { moderationComment })
60 this.notifier.success(this.i18n('Comment updated.'))
62 this.commentUpdated.emit(moderationComment)
66 err => this.notifier.error(err.message)