1
0
Fork 0
peertube/client/src/app/shared/moderation/user-ban-modal.component.ts

71 lines
2.1 KiB
TypeScript
Raw Normal View History

2018-08-09 15:51:25 +00:00
import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
import { Notifier } from '@app/core'
2018-08-09 15:51:25 +00:00
import { I18n } from '@ngx-translate/i18n-polyfill'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
import { FormReactive, UserValidatorsService } from '@app/shared/forms'
import { UserService } from '@app/shared/users'
import { User } from '../../../../../shared'
2018-08-09 15:51:25 +00:00
@Component({
selector: 'my-user-ban-modal',
templateUrl: './user-ban-modal.component.html',
styleUrls: [ './user-ban-modal.component.scss' ]
})
export class UserBanModalComponent extends FormReactive implements OnInit {
2019-07-24 14:05:59 +00:00
@ViewChild('modal', { static: true }) modal: NgbModal
2018-10-08 13:15:11 +00:00
@Output() userBanned = new EventEmitter<User | User[]>()
2018-08-09 15:51:25 +00:00
2018-10-08 13:15:11 +00:00
private usersToBan: User | User[]
2018-08-09 15:51:25 +00:00
private openedModal: NgbModalRef
constructor (
protected formValidatorService: FormValidatorService,
private modalService: NgbModal,
private notifier: Notifier,
2018-08-09 15:51:25 +00:00
private userService: UserService,
private userValidatorsService: UserValidatorsService,
private i18n: I18n
) {
super()
}
ngOnInit () {
this.buildForm({
reason: this.userValidatorsService.USER_BAN_REASON
})
}
2018-10-08 13:15:11 +00:00
openModal (user: User | User[]) {
this.usersToBan = user
2018-08-09 15:51:25 +00:00
this.openedModal = this.modalService.open(this.modal)
}
hide () {
2018-10-08 13:15:11 +00:00
this.usersToBan = undefined
2018-08-09 15:51:25 +00:00
this.openedModal.close()
}
async banUser () {
const reason = this.form.value['reason'] || undefined
2018-10-08 13:15:11 +00:00
this.userService.banUsers(this.usersToBan, reason)
2018-08-09 15:51:25 +00:00
.subscribe(
() => {
2018-10-08 13:15:11 +00:00
const message = Array.isArray(this.usersToBan)
? this.i18n('{{num}} users banned.', { num: this.usersToBan.length })
: this.i18n('User {{username}} banned.', { username: this.usersToBan.username })
2018-08-09 15:51:25 +00:00
this.notifier.success(message)
2018-10-08 13:15:11 +00:00
this.userBanned.emit(this.usersToBan)
this.hide()
2018-08-09 15:51:25 +00:00
},
err => this.notifier.error(err.message)
2018-08-09 15:51:25 +00:00
)
}
}