From 90dff0ffe01b1d4e1fc4ba88434bbbdb510ebb57 Mon Sep 17 00:00:00 2001 From: yingfeng Date: Fri, 16 Aug 2024 10:51:41 -0400 Subject: [PATCH] AMP-2532: - fix task manager async issue - code clean up: remove redundant and bad practice code related to getting config property - add debugging logs --- src/components/entity/EntityList.vue | 86 ++++++---------------------- src/service/entity-service.js | 11 ---- src/service/item-service.js | 10 ---- src/store/state.js | 4 -- 4 files changed, 19 insertions(+), 92 deletions(-) diff --git a/src/components/entity/EntityList.vue b/src/components/entity/EntityList.vue index 70518f3..64d13cb 100644 --- a/src/components/entity/EntityList.vue +++ b/src/components/entity/EntityList.vue @@ -228,7 +228,7 @@ @change="onInputChange" > @@ -409,7 +409,7 @@ @change="onInputChange" > @@ -964,7 +964,6 @@ export default { selectedCollection: sync("selectedCollection"), selectedItem: sync("selectedItem"), selectedFile: sync("selectedFile"), - entityConfigs: sync("entityConfigs"), configProperties: sync("configProperties"), baseUrl() { const self = this; @@ -976,7 +975,6 @@ export default { window.location.hash.toLowerCase().indexOf("collection") > -1 && window.location.hash.toLowerCase().indexOf("item") === -1 ) { - this.getEntityConfigs(); return "collection"; } else if (window.location.hash.toLowerCase().indexOf("item") > -1) { return "item"; @@ -994,12 +992,6 @@ export default { window.location.hash.toLowerCase().indexOf("add-item") > -1 ); }, - listOfTaskManager() { - return this.entityConfigs.taskManagers; - }, - listOfExternalResources() { - return this.entityConfigs.externalSources; - }, mediaInfo() { return this.selectedFile && this.selectedFile.mediaInfo ? JSON.stringify(JSON.parse(this.selectedFile.mediaInfo), undefined, 4) @@ -1020,7 +1012,6 @@ export default { ); self.selectedUser = ""; self.idsExcluding.push(getUser.id); - // self.showLoader = true; self.accessControlService .findActiveUsersByNameStartingIdsExcluding("", self.idsExcluding) .then((response) => { @@ -1028,12 +1019,10 @@ export default { response.data, "username" ); - // self.showLoader = false; }); }, async handleAssignRolesSaveBtn() { const self = this; - // self.showLoader = true; self.accessControlService .updateRoleAssignments(self.unitEntity.currentUnit, self.newRoles) .then(async (res) => { @@ -1052,10 +1041,8 @@ export default { } } self.refreshRoleAssignments(true); - // self.showLoader = false; }) .catch((e) => { - // self.showLoader = false; self.$bvToast.toast( "Oops! Something went wrong.", self.sharedService.erorrToastConfig @@ -1101,15 +1088,13 @@ export default { } // otherwise retrieve RoleAssignments and initialize/reset data - // self.showLoader = true; const assignRolesResponse = await self.accessControlService.retrieveRoleAssignments(self.unitEntity.currentUnit); self.assignedRoles = assignRolesResponse.data; self.idsExcluding = self.assignedRoles.users.map((user) => user.id); let userResponse = await self.accessControlService .findActiveUsersByNameStartingIdsExcluding("", self.idsExcluding); - self.userList = self.sharedService.sortByAlphabatical(userResponse.data, "username"); - // self.showLoader = false; + self.userList = self.sharedService.sortByAlphabatical(userResponse.data, "username"); // reset newRoles and assignedRolesUnitChanged self.newRoles = []; @@ -1127,7 +1112,6 @@ export default { } // otherwise retrieve RolesSettings and initialize/reset settingsRoles - // self.showLoader = true; const settingsRolesResponse = await self.accessControlService.retrieveRoleActionConfig(self.unitEntity.currentUnit); self.settingsRoles = settingsRolesResponse.data; @@ -1159,7 +1143,6 @@ export default { self.settingsRoles["rolesUpdated"] = new Set(); self.settingsRolesUnitChanged = false; - // self.showLoader = false; console.log ("Refreshed RolesSettings."); return true; }, @@ -1216,7 +1199,6 @@ export default { console.log("Updating role " + roleName + " with " + actionIds.length + " actions: " + actionIds); } // call updateRoleActionConfig API - // self.showLoader = true; self.accessControlService .updateRoleActionConfig(self.unitEntity.currentUnit, roles) .then(async (res) => { @@ -1233,10 +1215,8 @@ export default { ); } self.refreshRolesSettings(true); - // self.showLoader = false; }) .catch((e) => { - // self.showLoader = false; self.$bvToast.toast( "Oops! Something went wrong.", self.sharedService.erorrToastConfig @@ -1314,21 +1294,10 @@ export default { const unitSelectHtml = document.getElementById("unit-select"); if (unitSelectHtml) unitSelectHtml.focus(); } - console.log("EntityList.getAllUnits: unitList.length = " + self.unitEntity.unitList.length); + console.log("EntityList.getAllUnits: unitList = " + self.unitEntity.unitList); + return self.unitEntity.unitList; }); } catch (error) { - // self.showLoader = false; - console.log(error); - } - }, - async getConfigs() { - const self = this; - try { - // self.showLoader = true; - self.configProperties = await self.configPropertiesService.getConfigProperties(); - // self.showLoader = false; - } catch (error) { - // self.showLoader = false; console.log(error); } }, @@ -1375,6 +1344,7 @@ export default { console.log("EntityList.getEntityData: mediaType = " + self.entity.mediaType); // self.showLoader = false; } + return self.entity; }, async getUnitCollections() { const self = this; @@ -1413,7 +1383,7 @@ export default { }); // self.showLoader = false; }, - async onView(objInstance) { + onView(objInstance) { const self = this; if (self.baseUrl === "collection" && self.purpose) { self.selectedItem = objInstance; @@ -1449,10 +1419,6 @@ export default { onInputChange(ev) { this.isDataChanged = true; }, - async getEntityConfigs() { - const self = this; - self.entityService.getEntityConfigs(self); - }, handleSearchItem() { this.$router.push("/collections/items/item-search"); }, @@ -1482,26 +1448,6 @@ export default { next(); } }, - // beforeCreate() { - // console.log ("EntityList.beforeCreate(): showLoader = " + this.showLoader); - // console.log ("EntityList.beforeCreate(): mediaSource = " + this.entity.mediaSource); - // }, - // created() { - // console.log ("EntityList.created(): showLoader = " + this.showLoader); - // console.log ("EntityList.created(): mediaSource = " + this.entity.mediaSource); - // }, - // beforeUpdate() { - // console.log ("EntityList.beforeUpdate(): showLoader = " + this.showLoader); - // console.log ("EntityList.beforeUpdate(): mediaSource = " + this.entity.mediaSource); - // }, - // updated() { - // console.log ("EntityList.updated(): showLoader = " + this.showLoader); - // console.log ("EntityList.created(): mediaSource = " + this.entity.mediaSource); - // }, - // beforeMount() { - // console.log ("EntityList.beforeMount(): showLoader = " + this.showLoader); - // console.log ("EntityList.beforeMount(): mediaSource = " + this.entity.mediaSource); - // }, async mounted() { const self = this; @@ -1509,29 +1455,35 @@ export default { // retrieve configProperties if not yet populated if (!self.configProperties || Object.keys(self.configProperties).length === 0) { - await self.getConfigs(); - // console.log("EntityList.mounted: configs.length = " + self.configProperties.length); + try { + self.configProperties = await self.configPropertiesService.getConfigProperties(); + console.log("EntityList.mounted: taskManagers = " + self.configProperties.taskManagers + ", externalSources = " + self.configProperties.externalSources); + } catch (error) { + console.log(error); + } } // retrieve units list and currentUnit info from storage if available, otherwise initialize them const uEntity = JSON.parse(sessionStorage.getItem("unitEntity")); if (!uEntity) { self.unitEntity = { unitList: [], currentUnit: "" }; + console.log("EntityList.mounted: unitEntity initialized."); } else { self.unitEntity = uEntity; + console.log("EntityList.mounted: unitList = " + self.unitEntity.unitList + ", currentUnit = " + self.unitEntity.currentUnit); } // retrieve units list if not yet populated if (!self.unitEntity.unitList || !self.unitEntity.unitList.length) { - await self.getAllUnits(); - // console.log("EntityList.mounted: unitList.length = " + self.unitEntity.unitList.length); + let unitList = await self.getAllUnits(); + console.log("EntityList.mounted - after getAllUnits: unitList = " + unitList); } // if currentUnit set, getEntityData for the page if (self.unitEntity.currentUnit) { - await self.getEntityData(); - // console.log("EntityList.mounted: mediaSource = " + this.entity.mediaSource); + let entity = await self.getEntityData(); + console.log("EntityList.mounted: mediaSource = " + entity.mediaSource); } // adjust size of PFile fields for PFile page diff --git a/src/service/entity-service.js b/src/service/entity-service.js index b33cead..42c26b8 100644 --- a/src/service/entity-service.js +++ b/src/service/entity-service.js @@ -153,15 +153,4 @@ export default class EntityService { } } - async getEntityConfigs(self) { - if(!self.entityConfigs.externalSources.length || !self.entityConfigs.taskManagers.length) { - await self.itemService.getEntityConfigs().then(res => { - self.entityConfigs.externalSources = res.externalSources; - self.entityConfigs.taskManagers = res.taskManagers; - }).catch(err => { - self.$bvToast.toast("Unable to retrive config details. Please try again!", self.sharedService.erorrToastConfig); - }) - } - } - } \ No newline at end of file diff --git a/src/service/item-service.js b/src/service/item-service.js index 6440ab5..75c8dc1 100644 --- a/src/service/item-service.js +++ b/src/service/item-service.js @@ -64,14 +64,4 @@ export default class ItemService extends BaseService{ return await super.get_auth(`/items/search?keyword=${keyword}`).then(result => result.data) } - /*** - * To get a list of external resources and task managers - * @params obj, id - */ - - async getEntityConfigs(){ - var data = ""; - await super.get_auth(`/config?properties=externalSources,taskManagers`).then(result => data = result.data); - return data; - } } \ No newline at end of file diff --git a/src/store/state.js b/src/store/state.js index 30a93ce..70b97af 100644 --- a/src/store/state.js +++ b/src/store/state.js @@ -111,10 +111,6 @@ const state = { isAuthenticated: false, selectedFile: {}, selectedFilters: {}, - entityConfigs: { - externalSources: [], - taskManagers: [], - }, configProperties: {}, allUnits: {}, // all units the current user can read mgmEvaluation: {