Browse Source

update: selecting only filtered elements if necessary

pull/21184/head
sumeyyeKurtulus 2 years ago
parent
commit
1e6096512e
  1. 56
      npm/ng-packs/packages/permission-management/src/lib/components/permission-management.component.ts

56
npm/ng-packs/packages/permission-management/src/lib/components/permission-management.component.ts

@ -160,27 +160,28 @@ export class PermissionManagementComponent
permissionGroups = computed(() => { permissionGroups = computed(() => {
const search = this.filter().toLowerCase().trim(); const search = this.filter().toLowerCase().trim();
const groups = this.permissionGroupSignal(); let groups = this.permissionGroupSignal();
if (!search) { if (!search) {
return groups; return groups;
} }
const includesSearch = text => text.toLowerCase().includes(search); const includesSearch = text => text.toLowerCase().includes(search);
const matchingGroups = groups.filter(group => groups = groups.filter(group =>
group.permissions.some( group.permissions.some(
permission => includesSearch(permission.displayName) || includesSearch(group.displayName), permission => includesSearch(permission.displayName) || includesSearch(group.displayName),
), ),
); );
if (matchingGroups.length) { if (groups.length) {
this.setSelectedGroup(matchingGroups[0]); this.setSelectedGroup(groups[0]);
this.disabledSelectAllInAllTabs = false; this.disabledSelectAllInAllTabs = false;
return matchingGroups;
} else { } else {
this.disabledSelectAllInAllTabs = true; this.disabledSelectAllInAllTabs = true;
this.selectedGroupPermissions = []; this.selectedGroupPermissions = [];
} }
return groups;
}); });
trackByFn: TrackByFunction<PermissionGroupDto> = (_, item) => item.name; trackByFn: TrackByFunction<PermissionGroupDto> = (_, item) => item.name;
@ -369,27 +370,38 @@ export class PermissionManagementComponent
} }
onClickSelectAll() { onClickSelectAll() {
// TODO: To be updated for the latest point if (this.filter()) {
// const filteredPermissions = getPermissions(this.permissionGroups()); this.permissionGroups().forEach(group => {
group.permissions.forEach(permission => {
// if (filteredPermissions) { if (
// this.permissions = filteredPermissions; permission.isGranted &&
// } this.isGrantedByOtherProviderName(permission.grantedProviders)
)
this.permissions = this.permissions.map(permission => ({ return;
...permission,
isGranted: const index = this.permissions.findIndex(per => per.name === permission.name);
this.isGrantedByOtherProviderName(permission.grantedProviders) || !this.selectAllTab,
})); this.permissions = [
// .filter(permission => { ...this.permissions.slice(0, index),
// return filteredPermissions.find( { ...this.permissions[index], isGranted: !this.selectAllTab },
// filteredPermission => filteredPermission.name === permission.name, ...this.permissions.slice(index + 1),
// ); ];
// }); });
});
} else {
this.permissions = this.permissions.map(permission => ({
...permission,
isGranted:
this.isGrantedByOtherProviderName(permission.grantedProviders) || !this.selectAllTab,
}));
}
if (!this.disableSelectAllTab) { if (!this.disableSelectAllTab) {
this.selectThisTab = !this.selectAllTab; this.selectThisTab = !this.selectAllTab;
this.setTabCheckboxState(); this.setTabCheckboxState();
if (this.filter()) {
this.setGrantCheckboxState();
}
} }
this.onChangeGroup(this.selectedGroup); this.onChangeGroup(this.selectedGroup);
} }

Loading…
Cancel
Save