Skip to content

Commit

Permalink
gh-512 Fix code that assigns itself
Browse files Browse the repository at this point in the history
  • Loading branch information
pjmonks committed Apr 28, 2022
1 parent 73eb2c4 commit 4318068
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 66 deletions.
19 changes: 7 additions & 12 deletions src/app/shared/data-classes-list/data-classes-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,18 @@ export class DataClassesListComponent implements AfterViewInit {
}

bulkEdit() {
const dataElementIdLst = [];
this.dataClassRecords.forEach((record) => {
if (record.checked) {
dataElementIdLst.push({
const dataClassIds = this.dataClassRecords
.filter((record) => record.checked)
.map((record) => {
return {
id: record.id,
domainType: record.domainType
});
}
});
}});

this.dialog
.open(BulkEditModalComponent, {
data: {
dataElementIdLst,
dataElementIdLst: dataClassIds,
parentDataModel: this.parentDataModel,
parentDataClass: this.parentDataClass
},
Expand All @@ -306,8 +305,6 @@ export class DataClassesListComponent implements AfterViewInit {
.subscribe((result) => {
if (result) {
this.dataClassRecords.forEach((x) => (x.checked = false));
// eslint-disable-next-line no-self-assign
this.dataClassRecords = this.dataClassRecords;
this.checkAllCheckbox = false;
this.bulkActionsVisible = 0;
this.filterEvent.emit();
Expand All @@ -330,8 +327,6 @@ export class DataClassesListComponent implements AfterViewInit {
.subscribe((result) => {
if (result != null && result.status === 'ok') {
this.dataClassRecords.forEach((x) => (x.checked = false));
// eslint-disable-next-line no-self-assign
this.dataClassRecords = this.dataClassRecords;
this.checkAllCheckbox = false;
this.bulkActionsVisible = 0;
this.filterEvent.emit();
Expand Down
85 changes: 31 additions & 54 deletions src/app/shared/data-elements-list/data-elements-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,74 +254,51 @@ export class DataElementsListComponent implements AfterViewInit {
}

bulkEdit() {
const dataElementIdLst = [];
this.dataElementRecords.forEach((record) => {
if (record.checked) {
dataElementIdLst.push({
const dataElementIds = this.dataElementRecords
.filter((record) => record.checked)
.map((record) => {
return {
id: record.id,
domainType: record.domainType
});
}
});
const promise = new Promise<void>((resolve, reject) => {
const dialog = this.dialog.open(BulkEditModalComponent, {
data: {
dataElementIdLst,
parentDataModel: this.parentDataModel,
parentDataClass: this.parentDataClass
},
panelClass: 'bulk-edit-modal'
});
}});

dialog.afterClosed().subscribe((result) => {
if (result != null && result.status === 'ok') {
resolve();
} else {
reject();
}
});
});
promise
.then(() => {
this.dialog.open(BulkEditModalComponent, {
data: {
dataElementIdLst: dataElementIds,
parentDataModel: this.parentDataModel,
parentDataClass: this.parentDataClass
},
panelClass: 'bulk-edit-modal'
})
.afterClosed()
.subscribe((result) => {
if (result) {
this.dataElementRecords.forEach((x) => (x.checked = false));
// eslint-disable-next-line no-self-assign
this.dataElementRecords = this.dataElementRecords;
this.checkAllCheckbox = false;
this.bulkActionsVisible = 0;
this.filterEvent.emit();
})
.catch(() => {});
}
});
}

bulkDelete() {
const dataElementIdLst = this.dataElementRecords.filter(record => record.checked);
const promise = new Promise<void>((resolve, reject) => {
const dialog = this.dialog.open(BulkDeleteModalComponent, {
data: {
dataElementIdLst,
parentDataModel: this.parentDataModel,
parentDataClass: this.parentDataClass
},
panelClass: 'bulk-delete-modal'
});

dialog.afterClosed().subscribe((result) => {
if (result != null && result.status === 'ok') {
resolve();
} else {
reject();
}
});
});
promise
.then(() => {
this.dialog.open(BulkDeleteModalComponent, {
data: {
dataElementIdLst,
parentDataModel: this.parentDataModel,
parentDataClass: this.parentDataClass
},
panelClass: 'bulk-delete-modal'
})
.afterClosed()
.subscribe((result) => {
if (result) {
this.dataElementRecords.forEach((x) => (x.checked = false));
// eslint-disable-next-line no-self-assign
this.dataElementRecords = this.dataElementRecords;
this.checkAllCheckbox = false;
this.bulkActionsVisible = 0;
this.filterEvent.emit();
})
.catch(() => {});
}
});
}
}

0 comments on commit 4318068

Please sign in to comment.