import { DropdownAction } from '@app/shared/buttons/action-dropdown.component'
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
import { UserBanModalComponent } from '@app/shared/moderation/user-ban-modal.component'
-import { User, UserService } from '@app/shared/users'
+import { UserService } from '@app/shared/users'
import { AuthService, ConfirmService } from '@app/core'
-import { UserRight } from '../../../../../shared/models/users'
+import { User, UserRight } from '../../../../../shared/models/users'
@Component({
selector: 'my-user-moderation-dropdown',
@ViewChild('userBanModal') userBanModal: UserBanModalComponent
@Input() user: User
+ @Input() buttonSize: 'normal' | 'small' = 'normal'
+
@Output() userChanged = new EventEmitter()
+ @Output() userDeleted = new EventEmitter()
userActions: DropdownAction<User>[] = []
) { }
ngOnInit () {
- this.userActions = []
-
- if (this.authService.isLoggedIn()) {
- const authUser = this.authService.getUser()
-
- if (authUser.hasRight(UserRight.MANAGE_USERS)) {
- this.userActions = this.userActions.concat([
- {
- label: this.i18n('Edit'),
- linkBuilder: this.getRouterUserEditLink
- },
- {
- label: this.i18n('Delete'),
- handler: user => this.removeUser(user)
- },
- {
- label: this.i18n('Ban'),
- handler: user => this.openBanUserModal(user),
- isDisplayed: user => !user.blocked
- },
- {
- label: this.i18n('Unban'),
- handler: user => this.unbanUser(user),
- isDisplayed: user => user.blocked
- }
- ])
- }
- }
+ this.buildActions()
}
hideBanUserModal () {
this.i18n('Success'),
this.i18n('User {{username}} deleted.', { username: user.username })
)
- this.userChanged.emit()
+ this.userDeleted.emit()
},
err => this.notificationsService.error(this.i18n('Error'), err.message)
getRouterUserEditLink (user: User) {
return [ '/admin', 'users', 'update', user.id ]
}
+
+ private buildActions () {
+ this.userActions = []
+
+ if (this.authService.isLoggedIn()) {
+ const authUser = this.authService.getUser()
+
+ if (authUser.hasRight(UserRight.MANAGE_USERS)) {
+ this.userActions = this.userActions.concat([
+ {
+ label: this.i18n('Edit'),
+ linkBuilder: this.getRouterUserEditLink
+ },
+ {
+ label: this.i18n('Delete'),
+ handler: user => this.removeUser(user)
+ },
+ {
+ label: this.i18n('Ban'),
+ handler: user => this.openBanUserModal(user),
+ isDisplayed: user => !user.blocked
+ },
+ {
+ label: this.i18n('Unban'),
+ handler: user => this.unbanUser(user),
+ isDisplayed: user => user.blocked
+ }
+ ])
+ }
+ }
+ }
}