Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[INTERNAL][FEATURE] ObjectPageLayout navigation change event
Change-Id: I79bed00ea29d8c7d953f12520e4bd32b3fec94c2
  • Loading branch information
Dimo Petrov committed Apr 22, 2016
1 parent 21f292f commit eb75945
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 26 deletions.
33 changes: 16 additions & 17 deletions src/sap.uxap/src/sap/uxap/ObjectPageLayout.js
Expand Up @@ -10,12 +10,13 @@ sap.ui.define([
"sap/ui/core/CustomData",
"sap/ui/Device",
"sap/ui/core/delegate/ScrollEnablement",
"./ObjectPageSection",
"./ObjectPageSubSection",
"./ObjectPageSubSectionLayout",
"./LazyLoading",
"./ObjectPageLayoutABHelper",
"./library"
], function (jQuery, ResizeHandler, Control, CustomData, Device, ScrollEnablement, ObjectPageSubSection, ObjectPageSubSectionLayout, LazyLoading, ABHelper, library) {
], function (jQuery, ResizeHandler, Control, CustomData, Device, ScrollEnablement, ObjectPageSection, ObjectPageSubSection, ObjectPageSubSectionLayout, LazyLoading, ABHelper, library) {
"use strict";

/**
Expand Down Expand Up @@ -181,10 +182,10 @@ sap.ui.define([
editHeaderButtonPress: {},

/**
* The event is fired when the selected tab changes.
* <b>Note:</b> Event is fired only when IconTabBar is used for navigation.
* The event is fired when the selected section is changed using the navigation.
* @since 1.38.1
*/
tabSelect: {
navigate: {
parameters: {

/**
Expand Down Expand Up @@ -628,9 +629,6 @@ sap.ui.define([
}

if (this._oCurrentTabSection !== oSection) {
if (bIsTabClicked) {
this.fireTabSelect({section: oSection});
}
this._renderSection(oSection);
this._oCurrentTabSection = oSection;
}
Expand Down Expand Up @@ -806,7 +804,7 @@ sap.ui.define([
positionTopMobile: 0,
realTop: 0.0,
buttonId: "",
isSection: (oSectionBase instanceof library.ObjectPageSection),
isSection: (oSectionBase instanceof ObjectPageSection),
sectionReference: oSectionBase
};

Expand All @@ -826,21 +824,22 @@ sap.ui.define([
var oSection = sap.ui.getCore().byId(sId);

if (this.getUseIconTabBar()) {
var oToSelect = oSection;
if (oToSelect instanceof sap.uxap.ObjectPageSubSection) {
oToSelect = oToSelect.getParent();
}
var oToSelect = ObjectPageSection._getClosestSection(oSection);

/* exclude the previously selected tab from propagation chain for performance reasons */
if (this._oCurrentTabSection) {
this._oCurrentTabSection._allowPropagationToLoadedViews(false);
}
oToSelect._allowPropagationToLoadedViews(true); /* include the newly selected tab back to the propagation chain */

this._setCurrentTabSection(oSection, bIsTabClicked);
this._setCurrentTabSection(oSection);
this.getAggregation("_anchorBar").setSelectedButton(this._oSectionInfo[oToSelect.getId()].buttonId);
}

if (bIsTabClicked) {
this.fireNavigate({section: ObjectPageSection._getClosestSection(oSection)});
}

if (this._bIsHeaderExpanded) {
this._expandCollapseHeader(false);
}
Expand Down Expand Up @@ -883,7 +882,7 @@ sap.ui.define([
iDuration = iDuration >= 0 ? iDuration : this._iScrollToSectionDuration;

if (this.getUseIconTabBar()
&& ((oTargetSection instanceof sap.uxap.ObjectPageSection) || this._isFirstVisibleSubSection(oTargetSection))
&& ((oTargetSection instanceof ObjectPageSection) || this._isFirstVisibleSubSection(oTargetSection))
&& this._bStickyAnchorBar) { // in this case we are only scrolling
// a section from expanded to sticky position,
// so the scrolling animation in not needed, instead it looks unnatural, so set a 0 duration
Expand All @@ -894,13 +893,13 @@ sap.ui.define([

ObjectPageLayout.prototype._computeScrollPosition = function (oTargetSection) {

var bFirstLevel = oTargetSection && (oTargetSection instanceof sap.uxap.ObjectPageSection),
var bFirstLevel = oTargetSection && (oTargetSection instanceof ObjectPageSection),
sId = oTargetSection.getId();

var iScrollTo = this._bMobileScenario || bFirstLevel ? this._oSectionInfo[sId].positionTopMobile : this._oSectionInfo[sId].positionTop;

if (this.getUseIconTabBar()
&& ((oTargetSection instanceof sap.uxap.ObjectPageSection) || this._isFirstVisibleSubSection(oTargetSection))
&& ((oTargetSection instanceof ObjectPageSection) || this._isFirstVisibleSubSection(oTargetSection))
&& !this._bStickyAnchorBar) { // preserve expanded header if no need to stick

iScrollTo -= this.iHeaderContentHeight; // scroll to the position where the header is still expanded
Expand All @@ -914,7 +913,7 @@ sap.ui.define([
aToLoad;

if (!this.getEnableLazyLoading() && this.getUseIconTabBar()) {
aToLoad = (oTargetSection instanceof sap.uxap.ObjectPageSection) ? oTargetSection : oTargetSection.getParent();
aToLoad = (oTargetSection instanceof ObjectPageSection) ? oTargetSection : oTargetSection.getParent();
this._connectModelsForSections([aToLoad]);
}

Expand Down
13 changes: 12 additions & 1 deletion src/sap.uxap/src/sap/uxap/ObjectPageSection.js
Expand Up @@ -10,8 +10,9 @@ sap.ui.define([
"sap/ui/Device",
"sap/m/Button",
"sap/ui/core/StashedControlSupport",
"./ObjectPageSubSection",
"./library"
], function (jQuery, InvisibleText, ObjectPageSectionBase, Device, Button, StashedControlSupport, library) {
], function (jQuery, InvisibleText, ObjectPageSectionBase, Device, Button, StashedControlSupport, ObjectPageSubSection, library) {
"use strict";

/**
Expand Down Expand Up @@ -75,6 +76,16 @@ sap.ui.define([

ObjectPageSection.MEDIA_RANGE = Device.media.RANGESETS.SAP_STANDARD;

/**
* Returns the closest ObjectPageSection
* @param {sap.uxap.ObjectPageSectionBase} oSectionBase
* @returns {sap.uxap.ObjectPageSection}
* @private
*/
ObjectPageSection._getClosestSection = function (oSectionBase) {
return (oSectionBase instanceof ObjectPageSubSection) ? oSectionBase.getParent() : oSectionBase;
};

ObjectPageSection.prototype._expandSection = function () {
ObjectPageSectionBase.prototype._expandSection.call(this)
._updateShowHideAllButton(!this._thereAreHiddenSubSections());
Expand Down
17 changes: 14 additions & 3 deletions src/sap.uxap/test/sap/uxap/qunit/js/AnchorBar.qunit.js
Expand Up @@ -108,14 +108,25 @@

});

QUnit.test("Anchors for sections with multiple subsection must have arrow-down icon", function () {
QUnit.test("Anchors for sections with multiple subsection must have arrow-down icon", function (assert) {
var $arrowDownIcons;

this.anchorBarView.setModel(oModel);
this.clock.tick(1000);
this.clock.tick(iRenderingDelay);

$arrowDownIcons = this.oObjectPage.$().find(".sapUxAPAnchorBar .sapUxAPAnchorBarButton .sapMBtnIcon");
ok($arrowDownIcons.length === 1, "Anchorbar has 1 button with arrow-down icon");
assert.ok($arrowDownIcons.length === 1, "Anchorbar has 1 button with arrow-down icon");
});

QUnit.test("When using the objectPageNavigation the 'navigate' event is fired with the appropriate arguments", function (assert) {
var oAnchorBar = this.oObjectPage.getAggregation("_anchorBar"),
oExpectedSection = this.oObjectPage.getSections()[0],
navigateSpy = this.spy(this.oObjectPage, "fireNavigate");

this.oObjectPage.setShowAnchorBarPopover(false);
oAnchorBar.getContent()[0].firePress();

assert.ok(navigateSpy.calledWithMatch(sinon.match.has("section", oExpectedSection)), "Event fired has the correct parameters attached");
});

}(jQuery, QUnit, sinon, sap.uxap.Importance));
22 changes: 17 additions & 5 deletions src/sap.uxap/test/sap/uxap/qunit/js/ObjectPageSection.qunit.js
Expand Up @@ -12,12 +12,12 @@
QUnit.test("ObjectPageSection", function (assert) {

var ObjectPageSectionView = sap.ui.xmlview("UxAP-13_objectPageSection", {
viewName: "view.UxAP-13_ObjectPageSection"
});
var iRenderingDelay = 1000;
viewName: "view.UxAP-13_ObjectPageSection"
});
var iRenderingDelay = 1000;

ObjectPageSectionView.placeAt('qunit-fixture');
sap.ui.getCore().applyChanges();
ObjectPageSectionView.placeAt('qunit-fixture');
sap.ui.getCore().applyChanges();

// get the object page section
// By default title is not centered, CSS:0120061532 0001349139 2014
Expand Down Expand Up @@ -210,4 +210,16 @@
oButton.destroy();
});

QUnit.test("Testing ObjectPageSubSection._getClosestSection", function (assert) {
var ObjectPageSectionView = sap.ui.xmlview("UxAP-13_objectPageSection", {
viewName: "view.UxAP-13_ObjectPageSection"
}),
oSectionWithTwoSubSection = ObjectPageSectionView.byId("SectionWithSubSection"),
oFirstSubSection = oSectionWithTwoSubSection.getSubSections()[0],
fnGetClosestSection = sap.uxap.ObjectPageSection._getClosestSection;

assert.equal(fnGetClosestSection(oFirstSubSection).getId(), oSectionWithTwoSubSection.getId());
assert.equal(fnGetClosestSection(oSectionWithTwoSubSection).getId(), oSectionWithTwoSubSection.getId());
})

}(jQuery, QUnit, sinon, sap.uxap.Importance));

0 comments on commit eb75945

Please sign in to comment.