From bad9dc4c4624e5866956976f2db17838c42c4a35 Mon Sep 17 00:00:00 2001 From: Jordan Dichev Date: Wed, 25 Jan 2023 18:38:53 +0200 Subject: [PATCH] fix: display odata v4 binding context properly Fixes https://github.com/SAP/ui5-inspector/issues/81 --- app/vendor/ToolsAPI.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/vendor/ToolsAPI.js b/app/vendor/ToolsAPI.js index f41076aa..2082a178 100644 --- a/app/vendor/ToolsAPI.js +++ b/app/vendor/ToolsAPI.js @@ -458,6 +458,8 @@ sap.ui.define(["jquery.sap.global", "sap/ui/core/ElementMetadata"], var isResourceModel = type === "sap.ui.model.resource.ResourceModel"; var fullPath; var contextPath; + // Remember the context in case it is odata.v4.Context + var context = type === 'sap.ui.model.odata.v4.Context' && model; // we dont care about the context if path is absolute if(!isRelative) { @@ -475,9 +477,15 @@ sap.ui.define(["jquery.sap.global", "sap/ui/core/ElementMetadata"], // in case its a model context, retrieve the underlying model model = model.getModel && model.getModel() || model; - // functions in the model cannot communicated via message - modelInfo.modelData = isResourceModel ? "" : model.getObject(contextPath || "/"); - modelInfo.pathData = model.getProperty(fullPath); + // in case it is v4 ODataContext we get the data from the context + if (context) { + // There is no modelData in OData v4 just pathData + modelInfo.pathData = path !== context.getPath() ? context.getObject(path) : context.getObject(); + } else { + // functions in the model cannot communicated via message + modelInfo.modelData = isResourceModel ? "" : model.getObject(contextPath || "/"); + modelInfo.pathData = model.getProperty(fullPath); + } modelInfo.fullPath = fullPath; modelInfo.path = pathWithoutModel; modelInfo.mode = model.getDefaultBindingMode(); @@ -609,8 +617,10 @@ sap.ui.define(["jquery.sap.global", "sap/ui/core/ElementMetadata"], if (bindingContexts && Object.keys(bindingContexts).length) { return { parts: Object.keys(bindingContexts).map(function (key) { - return controlInformation._getModelInfo(bindingContexts[key].getModel(), - (key && key !== "undefined" && key !== "null" ? key + ">" : "") + bindingContexts[key].getPath()); + var context = bindingContexts[key]; + var modelOrContext = context.getMetadata().getName() === 'sap.ui.model.odata.v4.Context' ? context : context.getModel(); + return controlInformation._getModelInfo(modelOrContext, + (key && key !== "undefined" && key !== "null" ? key + ">" : "") + context.getPath()); }) }; }