]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/users/user-list/user-ban-modal.component.ts
Update FAQ.md
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-list / user-ban-modal.component.ts
1 import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { FormReactive, UserValidatorsService } from '../../../shared'
4 import { UserService } from '../shared'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
8 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
9 import { User } from '../../../../../../shared'
10
11 @Component({
12 selector: 'my-user-ban-modal',
13 templateUrl: './user-ban-modal.component.html',
14 styleUrls: [ './user-ban-modal.component.scss' ]
15 })
16 export class UserBanModalComponent extends FormReactive implements OnInit {
17 @ViewChild('modal') modal: NgbModal
18 @Output() userBanned = new EventEmitter<User>()
19
20 private userToBan: User
21 private openedModal: NgbModalRef
22
23 constructor (
24 protected formValidatorService: FormValidatorService,
25 private modalService: NgbModal,
26 private notificationsService: NotificationsService,
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
40 openModal (user: User) {
41 this.userToBan = user
42 this.openedModal = this.modalService.open(this.modal)
43 }
44
45 hideBanUserModal () {
46 this.userToBan = undefined
47 this.openedModal.close()
48 }
49
50 async banUser () {
51 const reason = this.form.value['reason'] || undefined
52
53 this.userService.banUser(this.userToBan, reason)
54 .subscribe(
55 () => {
56 this.notificationsService.success(
57 this.i18n('Success'),
58 this.i18n('User {{username}} banned.', { username: this.userToBan.username })
59 )
60
61 this.userBanned.emit(this.userToBan)
62 this.hideBanUserModal()
63 },
64
65 err => this.notificationsService.error(this.i18n('Error'), err.message)
66 )
67 }
68
69 }