diff options
author | Chocobozzz <me@florianbigard.com> | 2018-10-05 15:24:29 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-05 17:02:09 +0200 |
commit | e724fa93c71d76d709e819a05e5e2904a3c4205b (patch) | |
tree | c9bd410253f4ceac8e330541580445ca313583ac /client/src/app/shared/moderation/user-ban-modal.component.ts | |
parent | 21c54ac5f684f8b72bcde45cd8327ee21f574f22 (diff) | |
download | PeerTube-e724fa93c71d76d709e819a05e5e2904a3c4205b.tar.gz PeerTube-e724fa93c71d76d709e819a05e5e2904a3c4205b.tar.zst PeerTube-e724fa93c71d76d709e819a05e5e2904a3c4205b.zip |
Move user moderation tool in a separate component
Diffstat (limited to 'client/src/app/shared/moderation/user-ban-modal.component.ts')
-rw-r--r-- | client/src/app/shared/moderation/user-ban-modal.component.ts | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/client/src/app/shared/moderation/user-ban-modal.component.ts b/client/src/app/shared/moderation/user-ban-modal.component.ts new file mode 100644 index 000000000..d49783cd2 --- /dev/null +++ b/client/src/app/shared/moderation/user-ban-modal.component.ts | |||
@@ -0,0 +1,68 @@ | |||
1 | import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' | ||
2 | import { NotificationsService } from 'angular2-notifications' | ||
3 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
4 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
5 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | ||
6 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | ||
7 | import { FormReactive, UserValidatorsService } from '@app/shared/forms' | ||
8 | import { User, UserService } from '@app/shared/users' | ||
9 | |||
10 | @Component({ | ||
11 | selector: 'my-user-ban-modal', | ||
12 | templateUrl: './user-ban-modal.component.html', | ||
13 | styleUrls: [ './user-ban-modal.component.scss' ] | ||
14 | }) | ||
15 | export class UserBanModalComponent extends FormReactive implements OnInit { | ||
16 | @ViewChild('modal') modal: NgbModal | ||
17 | @Output() userBanned = new EventEmitter<User>() | ||
18 | |||
19 | private userToBan: User | ||
20 | private openedModal: NgbModalRef | ||
21 | |||
22 | constructor ( | ||
23 | protected formValidatorService: FormValidatorService, | ||
24 | private modalService: NgbModal, | ||
25 | private notificationsService: NotificationsService, | ||
26 | private userService: UserService, | ||
27 | private userValidatorsService: UserValidatorsService, | ||
28 | private i18n: I18n | ||
29 | ) { | ||
30 | super() | ||
31 | } | ||
32 | |||
33 | ngOnInit () { | ||
34 | this.buildForm({ | ||
35 | reason: this.userValidatorsService.USER_BAN_REASON | ||
36 | }) | ||
37 | } | ||
38 | |||
39 | openModal (user: User) { | ||
40 | this.userToBan = user | ||
41 | this.openedModal = this.modalService.open(this.modal) | ||
42 | } | ||
43 | |||
44 | hideBanUserModal () { | ||
45 | this.userToBan = undefined | ||
46 | this.openedModal.close() | ||
47 | } | ||
48 | |||
49 | async banUser () { | ||
50 | const reason = this.form.value['reason'] || undefined | ||
51 | |||
52 | this.userService.banUser(this.userToBan, reason) | ||
53 | .subscribe( | ||
54 | () => { | ||
55 | this.notificationsService.success( | ||
56 | this.i18n('Success'), | ||
57 | this.i18n('User {{username}} banned.', { username: this.userToBan.username }) | ||
58 | ) | ||
59 | |||
60 | this.userBanned.emit(this.userToBan) | ||
61 | this.hideBanUserModal() | ||
62 | }, | ||
63 | |||
64 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
65 | ) | ||
66 | } | ||
67 | |||
68 | } | ||