</div>
<div ngbDropdownMenu class="dropdown-menu">
- <ng-container *ngFor="let action of actions">
- <ng-container *ngIf="action.isDisplayed === undefined || action.isDisplayed(entry) === true">
- <a *ngIf="action.linkBuilder" class="dropdown-item" [routerLink]="action.linkBuilder(entry)">{{ action.label }}</a>
+ <ng-container *ngFor="let actions of getActions()">
- <span *ngIf="!action.linkBuilder" class="custom-action dropdown-item" (click)="action.handler(entry)" role="button">
- {{ action.label }}
- </span>
+ <ng-container *ngFor="let action of actions">
+ <ng-container *ngIf="action.isDisplayed === undefined || action.isDisplayed(entry) === true">
+ <a *ngIf="action.linkBuilder" class="dropdown-item" [routerLink]="action.linkBuilder(entry)">{{ action.label }}</a>
+
+ <span *ngIf="!action.linkBuilder" class="custom-action dropdown-item" (click)="action.handler(entry)" role="button">
+ {{ action.label }}
+ </span>
+ </ng-container>
</ng-container>
+
+ <div class="dropdown-divider"></div>
+
</ng-container>
</div>
-</div>
\ No newline at end of file
+</div>
})
export class ActionDropdownComponent<T> {
- @Input() actions: DropdownAction<T>[] = []
+ @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = []
@Input() entry: T
@Input() placement = 'bottom-left'
@Input() buttonSize: 'normal' | 'small' = 'normal'
@Input() label: string
@Input() theme: 'orange' | 'grey' = 'grey'
+
+ getActions () {
+ if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions
+
+ return [ this.actions ]
+ }
}
@Output() userChanged = new EventEmitter()
@Output() userDeleted = new EventEmitter()
- userActions: DropdownAction<{ user: User, account: Account }>[] = []
+ userActions: DropdownAction<{ user: User, account: Account }>[][] = []
constructor (
private authService: AuthService,
if (this.user && authUser.id === this.user.id) return
if (this.user && authUser.hasRight(UserRight.MANAGE_USERS)) {
- this.userActions = this.userActions.concat([
+ this.userActions.push([
{
label: this.i18n('Edit'),
linkBuilder: ({ user }) => this.getRouterUserEditLink(user)
// Actions on accounts/servers
if (this.account) {
// User actions
- this.userActions = this.userActions.concat([
+ this.userActions.push([
{
label: this.i18n('Mute this account'),
isDisplayed: ({ account }: { account: Account }) => account.mutedByUser === false,
}
])
+ let instanceActions: DropdownAction<{ user: User, account: Account }>[] = []
+
// Instance actions
if (authUser.hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)) {
- this.userActions = this.userActions.concat([
+ instanceActions = instanceActions.concat([
{
label: this.i18n('Mute this account by your instance'),
isDisplayed: ({ account }: { account: Account }) => account.mutedByInstance === false,
// Instance actions
if (authUser.hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)) {
- this.userActions = this.userActions.concat([
+ instanceActions = instanceActions.concat([
{
label: this.i18n('Mute the instance by your instance'),
isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === false,
}
])
}
+
+ if (instanceActions.length !== 0) {
+ this.userActions.push(instanceActions)
+ }
}
}
}