Skip to content

Commit

Permalink
feat(admin-ui): Truncate display of role permissions if too long
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Nov 13, 2019
1 parent 5a2ddc5 commit 98d971f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,26 @@
<ng-container *ngIf="!isDefaultRole(role)">
<vdr-chip *ngFor="let channel of role.channels">
<vdr-channel-badge [channelCode]="channel.code"></vdr-channel-badge>
{{ channel.code }}
{{ channel.code | channelCodeToLabel | translate }}
</vdr-chip>
</ng-container>
</td>
<td class="left align-middle">
<ng-container *ngIf="!isDefaultRole(role); else defaultRole">
<vdr-chip *ngFor="let permission of role.permissions">{{ permission }}</vdr-chip>
<vdr-chip *ngFor="let permission of role.permissions | slice: 0:displayLimit[role.id] || 3">{{ permission }}</vdr-chip>
<button
class="btn btn-sm btn-secondary btn-icon"
*ngIf="role.permissions.length > initialLimit"
(click)="toggleDisplayLimit(role)"
>
<ng-container *ngIf="(displayLimit[role.id] || 0) < role.permissions.length; else collapse">
<clr-icon shape="plus"></clr-icon>
{{ role.permissions.length - initialLimit }}
</ng-container>
<ng-template #collapse>
<clr-icon shape="minus"></clr-icon>
</ng-template>
</button>
</ng-container>
<ng-template #defaultRole>
<span class="default-role-label">{{ 'settings.default-role-label' | translate }}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { DataService } from '../../../data/providers/data.service';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RoleListComponent extends BaseListComponent<GetRoles.Query, GetRoles.Items> {
readonly initialLimit = 3;
displayLimit: { [id: string]: number } = {};

constructor(private dataService: DataService, router: Router, route: ActivatedRoute) {
super(router, route);
super.setQueryFn(
Expand All @@ -21,6 +24,14 @@ export class RoleListComponent extends BaseListComponent<GetRoles.Query, GetRole
);
}

toggleDisplayLimit(role: GetRoles.Items) {
if (this.displayLimit[role.id] === role.permissions.length) {
this.displayLimit[role.id] = this.initialLimit;
} else {
this.displayLimit[role.id] = role.permissions.length;
}
}

isDefaultRole(role: Role): boolean {
return role.code === SUPER_ADMIN_ROLE_CODE || role.code === CUSTOMER_ROLE_CODE;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/admin-ui/src/i18n-messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,4 +604,4 @@
"update": "Update",
"zone": "Zone"
}
}
}

0 comments on commit 98d971f

Please sign in to comment.