]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/moderation/user-ban-modal.component.ts
Add ListOverflow component to prevent sub-menu overflow
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / moderation / user-ban-modal.component.ts
CommitLineData
141b177d 1import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
f8b2c1b4 2import { Notifier } from '@app/core'
141b177d
C
3import { I18n } from '@ngx-translate/i18n-polyfill'
4import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
5import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
6import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
e724fa93 7import { FormReactive, UserValidatorsService } from '@app/shared/forms'
79bd2632
C
8import { UserService } from '@app/shared/users'
9import { User } from '../../../../../shared'
141b177d
C
10
11@Component({
12 selector: 'my-user-ban-modal',
13 templateUrl: './user-ban-modal.component.html',
14 styleUrls: [ './user-ban-modal.component.scss' ]
15})
16export class UserBanModalComponent extends FormReactive implements OnInit {
f36da21e 17 @ViewChild('modal', { static: true }) modal: NgbModal
791645e6 18 @Output() userBanned = new EventEmitter<User | User[]>()
141b177d 19
791645e6 20 private usersToBan: User | User[]
141b177d
C
21 private openedModal: NgbModalRef
22
23 constructor (
24 protected formValidatorService: FormValidatorService,
25 private modalService: NgbModal,
f8b2c1b4 26 private notifier: Notifier,
141b177d
C
27 private userService: UserService,
28 private userValidatorsService: UserValidatorsService,
29 private i18n: I18n
30 ) {
31 super()
32 }
33
34 ngOnInit () {
35 this.buildForm({
36 reason: this.userValidatorsService.USER_BAN_REASON
37 })
38 }
39
791645e6
C
40 openModal (user: User | User[]) {
41 this.usersToBan = user
24e7916c 42 this.openedModal = this.modalService.open(this.modal, { centered: true })
141b177d
C
43 }
44
457bb213 45 hide () {
791645e6 46 this.usersToBan = undefined
141b177d
C
47 this.openedModal.close()
48 }
49
50 async banUser () {
51 const reason = this.form.value['reason'] || undefined
52
791645e6 53 this.userService.banUsers(this.usersToBan, reason)
141b177d
C
54 .subscribe(
55 () => {
791645e6
C
56 const message = Array.isArray(this.usersToBan)
57 ? this.i18n('{{num}} users banned.', { num: this.usersToBan.length })
58 : this.i18n('User {{username}} banned.', { username: this.usersToBan.username })
141b177d 59
f8b2c1b4 60 this.notifier.success(message)
791645e6
C
61
62 this.userBanned.emit(this.usersToBan)
457bb213 63 this.hide()
141b177d
C
64 },
65
f8b2c1b4 66 err => this.notifier.error(err.message)
141b177d
C
67 )
68 }
69
70}