Skip to content

Commit

Permalink
Merge "[FIX] sap/ui/model/odata/v2/ODataListBinding: ContextChange" i…
Browse files Browse the repository at this point in the history
…nto rel-1.65
  • Loading branch information
Marcos Gavilan de Paz authored and Gerrit Code Review committed Jun 27, 2019
2 parents bfb9563 + f56fbd2 commit edb381b
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/sap.ui.core/src/sap/ui/model/odata/v2/ODataListBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ sap.ui.define([
this._initSortersFilters();

if (this.checkExpandedList() && !bForceUpdate) {
// if there are pending requests e.g. previous context requested data which returns null
// the pending requests need to be aborted such that the responded (previous) data doesn't overwrite the current one
this.abortPendingRequest();
this._fireChange({ reason: ChangeReason.Context });
} else {
this._refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ sap.ui.define([], function() {
[200, oXMLHeaders, sProducts3ExpSupplierXML],
"Products(3)?$expand=Supplier%2fProducts":
[200, oXMLHeaders, sProducts3ExpSupplierProductsXML],
"Products(7)/Supplier/Products":
[200, oXMLHeaders, sProducts7EmptyResult],
"Products(7)?$expand=Supplier%2fProducts":
[200, oXMLHeaders, sProducts7ExpSupplierProductsXML],
"Products(7)?$expand=Category":
[200, oXMLHeaders, sProducts7ExpCategoryXML],
"Products(3)?$select=ProductName%2cCategory&$expand=Category":
Expand Down Expand Up @@ -2153,16 +2157,16 @@ sap.ui.define([], function() {
</content>\
</entry>\
<entry>\
<id>http://services.odata.org/V2/northwind/Northwind.svc/Products(3)</id>\
<id>http://services.odata.org/V2/northwind/Northwind.svc/Products(1)</id>\
<title type="text"></title>\
<updated>2016-05-20T13:51:28Z</updated>\
<author>\
<name />\
</author>\
<link rel="edit" title="Product" href="Products(3)" />\
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Category" type="application/atom+xml;type=entry" title="Category" href="Products(3)/Category" />\
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Order_Details" type="application/atom+xml;type=feed" title="Order_Details" href="Products(3)/Order_Details" />\
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier" type="application/atom+xml;type=entry" title="Supplier" href="Products(3)/Supplier" />\
<link rel="edit" title="Product" href="Products(1)" />\
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Category" type="application/atom+xml;type=entry" title="Category" href="Products(1)/Category" />\
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Order_Details" type="application/atom+xml;type=feed" title="Order_Details" href="Products(1)/Order_Details" />\
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier" type="application/atom+xml;type=entry" title="Supplier" href="Products(1)/Supplier" />\
<category term="NorthwindModel.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />\
<content type="application/xml">\
<m:properties>\
Expand Down Expand Up @@ -2220,6 +2224,48 @@ sap.ui.define([], function() {
</entry>\
';

var sProducts7EmptyResult = '\<?xml version="1.0" encoding="utf-8" standalone="yes"?>\
<feed xml:base="https://services.odata.org/V2/Northwind/Northwind.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">\
<title type="text">Products</title>\
<id>https://services.odata.org/V2/Northwind/Northwind.svc/Products(7)/Supplier/Products</id>\
<updated>1985-10-09T08:18:15Z</updated>\
<link rel="self" title="Products" href="Products" />\
</feed>\
';

var sProducts7ExpSupplierProductsXML = '\<?xml version="1.0" encoding="utf-8" standalone="yes"?>\
<entry xml:base="http://services.odata.org/V2/northwind/Northwind.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">\
<id>http://services.odata.org/V2/northwind/Northwind.svc/Products(7)</id>\
<title type="text"></title>\
<updated>2016-05-20T13:51:28Z</updated>\
<author>\
<name />\
</author>\
<link rel="edit" title="Product" href="Products(7)" />\
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Category" type="application/atom+xml;type=entry" title="Category" href="Products(7)/Category" />\
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Order_Details" type="application/atom+xml;type=feed" title="Order_Details" href="Products(7)/Order_Details" />\
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier" type="application/atom+xml;type=entry" title="Supplier" href="Products(7)/Supplier">\
<m:inline>\
</m:inline>\
</link>\
<category term="NorthwindModel.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />\
<content type="application/xml">\
<m:properties>\
<d:ProductID m:type="Edm.Int32">1</d:ProductID>\
<d:ProductName m:type="Edm.String">Chai Foo 7 null</d:ProductName>\
<d:SupplierID m:type="Edm.Int32">1</d:SupplierID>\
<d:CategoryID m:type="Edm.Int32">1</d:CategoryID>\
<d:QuantityPerUnit m:type="Edm.String">10 boxes x 20 bags</d:QuantityPerUnit>\
<d:UnitPrice m:type="Edm.Decimal">18.0000</d:UnitPrice>\
<d:UnitsInStock m:type="Edm.Int16">39</d:UnitsInStock>\
<d:UnitsOnOrder m:type="Edm.Int16">0</d:UnitsOnOrder>\
<d:ReorderLevel m:type="Edm.Int16">10</d:ReorderLevel>\
<d:Discontinued m:type="Edm.Boolean">false</d:Discontinued>\
</m:properties>\
</content>\
</entry>\
';


var sCategoriesOrderDescXML = '\<?xml version="1.0" encoding="utf-8" standalone="yes"?>\
<feed xml:base="http://localhost:8080/uilib-sample/proxy/http/services.odata.org/Northwind/Northwind.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,46 @@ sap.ui.define([
});
});

QUnit.test("ListBinding relative with context and expanded list", function(assert){
var done = assert.async();
var oModel = initModel(false);
var oBinding = oModel.bindList("Supplier/Products");
var iCount = 0;

// Requests:
// /Products(3)?$expand=Supplier/Products
// /Products(7)?$expand=Supplier/Products
// /Products(7)/Supplier/Products

var changeHandler = function() {
iCount++;

// trigger data requests
oBinding.getContexts();

if (iCount === 1) {
assert.equal(oBinding.getLength(), 0, "0 entries retrieved (/Products(7))");
} else if (iCount === 2) {
assert.equal(oBinding.getLength(), 3, "3 entries retrieved (/Products(3))");
oBinding.detachChange(changeHandler);
done();
}
};

oBinding.attachChange(changeHandler);
oBinding.initialize();

// /Products(7)/Supplier --> null
oModel.createBindingContext("/Products(7)", undefined, {expand: "Supplier/Products"}, function(oContext7null) {

// /Products(3)/Supplier/Products --> [3,2,1]
oModel.createBindingContext("/Products(3)", undefined, {expand: "Supplier/Products"}, function(oContext3) {
oBinding.setContext(oContext7null);
oBinding.setContext(oContext3);
});
});
});

QUnit.test("ListBinding relative with context and client-side filters", function(assert){
var done = assert.async();
var oModel = initModel(sURI, false, "Categories");
Expand Down

0 comments on commit edb381b

Please sign in to comment.