Skip to content

Commit

Permalink
feat(permission-management): add hide badges input
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmet-erim committed Dec 2, 2019
1 parent 1b54da2 commit b9d2e5f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,6 @@ <h3>{{ (selected?.id ? 'AbpIdentity::Edit' : 'AbpIdentity::NewRole') | abpLocali
[(visible)]="visiblePermissions"
providerName="R"
[providerKey]="providerKey"
[hideBadges]="true"
>
</abp-permission-management>
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ <h4>{{ selectedGroup?.displayName }}</h4>
[attr.for]="permission.name"
(click)="onClickCheckbox(permission, permissionCheckbox.value)"
>{{ permission.displayName }}
<ng-container *ngIf="providerName !== 'R'">
<ng-container *ngIf="!hideBadges">
<span
*ngFor="let provider of permission.grantedProviders"
class="badge badge-light"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class PermissionManagementComponent implements OnInit, OnChanges {
@Input()
providerKey: string;

@Input()
hideBadges = false;

protected _visible;

@Input()
Expand Down Expand Up @@ -72,7 +75,9 @@ export class PermissionManagementComponent implements OnInit, OnChanges {
get selectedGroupPermissions$(): Observable<PermissionWithMargin[]> {
return this.groups$.pipe(
map(groups =>
this.selectedGroup ? groups.find(group => group.name === this.selectedGroup.name).permissions : [],
this.selectedGroup
? groups.find(group => group.name === this.selectedGroup.name).permissions
: [],
),
map<PermissionManagement.Permission[], PermissionWithMargin[]>(permissions =>
permissions.map(
Expand Down Expand Up @@ -103,7 +108,11 @@ export class PermissionManagementComponent implements OnInit, OnChanges {
}

onClickCheckbox(clickedPermission: PermissionManagement.Permission, value) {
if (clickedPermission.isGranted && this.isGrantedByOtherProviderName(clickedPermission.grantedProviders)) return;
if (
clickedPermission.isGranted &&
this.isGrantedByOtherProviderName(clickedPermission.grantedProviders)
)
return;

setTimeout(() => {
this.permissions = this.permissions.map(per => {
Expand Down Expand Up @@ -158,7 +167,8 @@ export class PermissionManagementComponent implements OnInit, OnChanges {
onClickSelectThisTab() {
this.selectedGroupPermissions$.pipe(take(1)).subscribe(permissions => {
permissions.forEach(permission => {
if (permission.isGranted && this.isGrantedByOtherProviderName(permission.grantedProviders)) return;
if (permission.isGranted && this.isGrantedByOtherProviderName(permission.grantedProviders))
return;

const index = this.permissions.findIndex(per => per.name === permission.name);

Expand All @@ -176,7 +186,8 @@ export class PermissionManagementComponent implements OnInit, OnChanges {
onClickSelectAll() {
this.permissions = this.permissions.map(permission => ({
...permission,
isGranted: this.isGrantedByOtherProviderName(permission.grantedProviders) || !this.selectAllTab,
isGranted:
this.isGrantedByOtherProviderName(permission.grantedProviders) || !this.selectAllTab,
}));

this.selectThisTab = !this.selectAllTab;
Expand All @@ -195,7 +206,10 @@ export class PermissionManagementComponent implements OnInit, OnChanges {

const changedPermissions: PermissionManagement.MinimumPermission[] = this.permissions
.filter(per =>
unchangedPermissions.find(unchanged => unchanged.name === per.name).isGranted === per.isGranted ? false : true,
unchangedPermissions.find(unchanged => unchanged.name === per.name).isGranted ===
per.isGranted
? false
: true,
)
.map(({ name, isGranted }) => ({ name, isGranted }));

Expand Down Expand Up @@ -255,7 +269,10 @@ export class PermissionManagementComponent implements OnInit, OnChanges {
}
}

function findMargin(permissions: PermissionManagement.Permission[], permission: PermissionManagement.Permission) {
function findMargin(
permissions: PermissionManagement.Permission[],
permission: PermissionManagement.Permission,
) {
const parentPermission = permissions.find(per => per.name === permission.parentName);

if (parentPermission && parentPermission.parentName) {
Expand Down

0 comments on commit b9d2e5f

Please sign in to comment.