Federated video streaming platform using ActivityPub and P2P in the web browser with Angular. https://joinpeertube.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

71 lines
2.1 KiB

  1. import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
  2. import { Notifier, UserService } from '@app/core'
  3. import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
  4. import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
  5. import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
  6. import { User } from '@shared/models'
  7. import { USER_BAN_REASON_VALIDATOR } from '../form-validators/user-validators'
  8. @Component({
  9. selector: 'my-user-ban-modal',
  10. templateUrl: './user-ban-modal.component.html',
  11. styleUrls: [ './user-ban-modal.component.scss' ]
  12. })
  13. export class UserBanModalComponent extends FormReactive implements OnInit {
  14. @ViewChild('modal', { static: true }) modal: NgbModal
  15. @Output() userBanned = new EventEmitter<User | User[]>()
  16. private usersToBan: User | User[]
  17. private openedModal: NgbModalRef
  18. modalMessage = ''
  19. constructor (
  20. protected formValidatorService: FormValidatorService,
  21. private modalService: NgbModal,
  22. private notifier: Notifier,
  23. private userService: UserService
  24. ) {
  25. super()
  26. }
  27. ngOnInit () {
  28. this.buildForm({
  29. reason: USER_BAN_REASON_VALIDATOR
  30. })
  31. }
  32. openModal (user: User | User[]) {
  33. this.usersToBan = user
  34. this.openedModal = this.modalService.open(this.modal, { centered: true })
  35. const isSingleUser = !(Array.isArray(this.usersToBan) && this.usersToBan.length > 1)
  36. this.modalMessage = isSingleUser ? $localize`Ban this user` : $localize`Ban these users`
  37. }
  38. hide () {
  39. this.usersToBan = undefined
  40. this.openedModal.close()
  41. }
  42. banUser () {
  43. const reason = this.form.value['reason'] || undefined
  44. this.userService.banUsers(this.usersToBan, reason)
  45. .subscribe({
  46. next: () => {
  47. const message = Array.isArray(this.usersToBan)
  48. ? $localize`${this.usersToBan.length} users banned.`
  49. : $localize`User ${this.usersToBan.username} banned.`
  50. this.notifier.success(message)
  51. this.userBanned.emit(this.usersToBan)
  52. this.hide()
  53. },
  54. error: err => this.notifier.error(err.message)
  55. })
  56. }
  57. }