Skip to content

Commit

Permalink
fix: display odata v4 binding context properly (#220)
Browse files Browse the repository at this point in the history
Fixes #81
  • Loading branch information
jdichev authored Feb 3, 2023
1 parent 8b079bb commit 374e3d4
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions app/vendor/ToolsAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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());
})
};
}
Expand Down

0 comments on commit 374e3d4

Please sign in to comment.