From aa25d15367c99ead0ae44a85927e285f33cc8a88 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 28 Mar 2022 16:31:01 -0400 Subject: [PATCH] LP1839341 YAOUS editor batch operation improvements * Apply batch updates serially to avoid large parallel batches. * Replace manual JSON string compilation with JSON.stringify() * Show progress dialog during batch updates / hide toasts since they occur too fast to read. * Batch update avoids applying the value "0" for numerics when the value is null or undefined. * Minor linting Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander Signed-off-by: Terran McCanna Signed-off-by: Jane Sandberg --- .../org-unit-settings.component.html | 2 + .../org-unit-settings.component.ts | 54 ++++++++++++++-------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-settings.component.html b/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-settings.component.html index 1cb314604b..e09bdcfe45 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-settings.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-settings.component.html @@ -11,6 +11,8 @@ + +
diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-settings.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-settings.component.ts index 788755dbaa..842fb85d48 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-settings.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-settings.component.ts @@ -10,6 +10,7 @@ import {GridDataSource} from '@eg/share/grid/grid'; import {GridComponent} from '@eg/share/grid/grid.component'; import {ToastService} from '@eg/share/toast/toast.service'; import {LocaleService} from '@eg/core/locale.service'; +import {ProgressDialogComponent} from '@eg/share/dialog/progress.component'; import {EditOuSettingDialogComponent } from '@eg/staff/admin/local/org-unit-settings/edit-org-unit-setting-dialog.component'; @@ -58,6 +59,8 @@ export class OrgUnitSettingsComponent implements OnInit { @ViewChild('ouSettingJsonDialog', { static: true }) private ouSettingJsonDialog: OuSettingJsonDialogComponent; + @ViewChild('progress') private progress: ProgressDialogComponent; + refreshSettings: boolean; renderFromPrefs: boolean; @@ -128,7 +131,7 @@ export class OrgUnitSettingsComponent implements OnInit { }); settingVals.forEach(key => { if (key.setting) { - if(orgs.indexOf(this.org.get(key.setting.org)) || this.contextOrg.id() == key.setting.org) { + if (orgs.indexOf(this.org.get(key.setting.org)) || this.contextOrg.id() === key.setting.org) { const settingsObj = this.settingTypeArr.filter( setting => setting.name === key.name )[0]; @@ -231,17 +234,20 @@ export class OrgUnitSettingsComponent implements OnInit { applyFilter(clear?: boolean) { if (clear) { this.filterString = ''; } - this.orgUnitSettingsGrid.context.pager.toFirst() + this.orgUnitSettingsGrid.context.pager.toFirst(); this.updateGrid(this.contextOrg); } - updateSetting(obj, entry) { - this.net.request( + updateSetting(obj, entry, noToast?: boolean): Promise { + return this.net.request( 'open-ils.actor', 'open-ils.actor.org_unit.settings.update', this.auth.token(), obj.context.id(), obj.setting ).toPromise().then(res => { - this.toast.success(entry.label + ' Updated.'); + if (!noToast) { + this.toast.success(entry.label + ' Updated.'); + } + if (!obj.setting[entry.name]) { const settingsObj = this.settingTypeArr.filter( setting => setting.name === entry.name @@ -289,41 +295,49 @@ export class OrgUnitSettingsComponent implements OnInit { showJsonDialog(isExport: boolean) { this.ouSettingJsonDialog.isExport = isExport; this.ouSettingJsonDialog.jsonData = ''; + if (isExport) { - this.ouSettingJsonDialog.jsonData = '{'; + const jsonObj: any = {}; this.gridDataSource.data.forEach(entry => { - this.ouSettingJsonDialog.jsonData += - '"' + entry.name + '": {"org": "' + - this.contextOrg.id() + '", "value": '; - if (entry.value) { - this.ouSettingJsonDialog.jsonData += '"' + entry.value + '"'; - } else { - this.ouSettingJsonDialog.jsonData += 'null'; - } - this.ouSettingJsonDialog.jsonData += '}'; - if (this.gridDataSource.data.indexOf(entry) !== (this.gridDataSource.data.length - 1)) { - this.ouSettingJsonDialog.jsonData += ','; - } + jsonObj[entry.name] = { + org: this.contextOrg.id(), + value: entry.value === undefined ? null : entry.value + }; }); - this.ouSettingJsonDialog.jsonData += '}'; + + this.ouSettingJsonDialog.jsonData = JSON.stringify(jsonObj); } this.ouSettingJsonDialog.open({size: 'lg'}).subscribe(res => { if (res.apply && res.jsonData) { const jsonSettings = JSON.parse(res.jsonData); + + this.progress.update({ + max: Object.entries(jsonSettings).length, + value: 1 + }); + + this.progress.open(); + + let promise = Promise.resolve(); Object.entries(jsonSettings).forEach((fields) => { const entry = this.settingTypeArr.find(x => x.name === fields[0]); const obj = {setting: {}, context: {}}; const val = this.parseValType(fields[1]['value'], entry.dataType); obj.setting[fields[0]] = val; obj.context = this.org.get(fields[1]['org']); - this.updateSetting(obj, entry); + promise = promise + .then(_ => this.updateSetting(obj, entry, true)) + .then(_ => this.progress.increment()); }); + + promise.finally(() => this.progress.close()); } }); } parseValType(value, dataType) { + if (value === null || value === undefined) { return null; } if (dataType === 'integer' || 'currency' || 'link') { return Number(value); } else if (dataType === 'bool') { -- 2.11.0