Skip to content

Commit

Permalink
Merge pull request #370 from dreamfactorysoftware/task/368-unable-rem…
Browse files Browse the repository at this point in the history
…ove-access

#368 - Unable to remove access line of roles tab
  • Loading branch information
thekevinm authored Nov 20, 2024
2 parents 63c5f52 + a1aa85a commit 6546d9e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<div formArrayName="serviceAccess" class="full-width">
<df-roles-access
[visible]="visibilityArray"
[formArray]="serviceAccess"
[roleForm]="roleForm"
class="full-width"></df-roles-access>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class DfRoleDetailsComponent implements OnInit {
alertMsg = '';
showAlert = false;
alertType: AlertType = 'error';
visibilityArray: boolean[] = [];

constructor(
@Inject(ROLE_SERVICE_TOKEN)
Expand Down Expand Up @@ -100,6 +101,7 @@ export class DfRoleDetailsComponent implements OnInit {
this.filterOp = data.roleServiceAccessByRoleId[0].filterOp;
data.roleServiceAccessByRoleId.forEach(
(item: RoleServiceAccessType) => {
this.visibilityArray.push(true);
const advancedFilters = new FormArray(
(item.filters || []).map(
(each: any) =>
Expand Down Expand Up @@ -266,7 +268,7 @@ export class DfRoleDetailsComponent implements OnInit {
description: formValue.description,
isActive: formValue.active,
roleServiceAccessByRoleId: formValue.serviceAccess.map(
(val: AccessForm) => {
(val: AccessForm, index: number) => {
const filtersArray = val.advancedFilters.map((filter: any) => ({
name: filter.expandField,
operator: filter.expandOperator,
Expand All @@ -275,8 +277,10 @@ export class DfRoleDetailsComponent implements OnInit {
const filterOp = val.advancedFilters.map(
(filter: any) => filter.filterOp
);
const roleId = this.visibilityArray[index] ? formValue.id : null;
return {
id: val.id,
roleId: roleId,
serviceId: val.service === 0 ? null : val.service,
component: val.component,
verbMask: val.access.reduce((acc, cur) => acc + cur, 0), // add up all the values in the array
Expand Down
13 changes: 9 additions & 4 deletions src/app/adf-roles/df-roles-access/df-roles-access.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { CommonModule } from '@angular/common';
export class DfRolesAccessComponent implements OnInit {
@Input() formArray: FormArray;
@Input() roleForm: FormGroup;
@Input() visible: boolean[];
rootForm: FormGroup;
serviceAccess: FormArray;
dataSource: MatTableDataSource<any>;
Expand Down Expand Up @@ -268,8 +269,10 @@ export class DfRolesAccessComponent implements OnInit {
}

updateDataSource() {
if (!this.formArray) return;
this.dataSource = new MatTableDataSource(this.formArray.controls);
const visibleControls = this.formArray.controls.filter(
(control, index) => this.visible[index]
);
this.dataSource = new MatTableDataSource(visibleControls);
}

get hasServiceAccess() {
Expand All @@ -290,7 +293,7 @@ export class DfRolesAccessComponent implements OnInit {
serviceAccess: new FormControl(''),
})
);

this.visible.push(true);
this.updateDataSource();
}

Expand Down Expand Up @@ -320,7 +323,9 @@ export class DfRolesAccessComponent implements OnInit {
}

remove(index: number) {
this.formArray.removeAt(index);
if (index >= 0 && index < this.formArray.length) {
this.visible[index] = false;
}
this.updateDataSource();
}

Expand Down

0 comments on commit 6546d9e

Please sign in to comment.