Skip to content

Commit

Permalink
[INTERNAL] routing: support loading component as target
Browse files Browse the repository at this point in the history
Change-Id: I3ab33de3b6cfa8e93f131c4a62992f64b9f1791a
  • Loading branch information
stopcoder committed Jul 26, 2018
1 parent e87e76c commit 87e8d59
Show file tree
Hide file tree
Showing 34 changed files with 1,090 additions and 369 deletions.
2 changes: 1 addition & 1 deletion src/sap.f/src/sap/f/routing/Targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ sap.ui.define(['sap/ui/core/routing/Targets', './TargetHandler', './Target', './
},

_constructTarget : function (oOptions, oParent) {
return new Target(oOptions, this._oViews, oParent, this._oTargetHandler);
return new Target(oOptions, this.getViews(), oParent, this._oTargetHandler);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/sap.f/src/sap/f/routing/async/Target.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sap.ui.define([], function() {
return this._oTargetHandler._chainNavigation(function() {
return oPromise.then(function(oViewInfo) {
that._oTargetHandler.addNavigation({
navigationIdentifier : that._oOptions.name,
navigationIdentifier : that._oOptions._name,
transition: that._oOptions.transition,
transitionParameters: that._oOptions.transitionParameters,
eventData: vData,
Expand Down
2 changes: 1 addition & 1 deletion src/sap.f/src/sap/f/routing/async/Targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sap.ui.define([], function() {
// maybe a wrong name was provided then there is no last displayed target
if (this._oLastDisplayedTarget) {
iViewLevel = this._getViewLevel(this._oLastDisplayedTarget);
sName = this._oLastDisplayedTarget._oOptions.name;
sName = this._oLastDisplayedTarget._oOptions._name;
}

this._oTargetHandler.navigate({
Expand Down
2 changes: 1 addition & 1 deletion src/sap.m/src/sap/m/routing/Targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ sap.ui.define(['sap/ui/core/routing/Targets', './TargetHandler', './Target', './
},

_constructTarget : function (oOptions, oParent) {
return new Target(oOptions, this._oViews, oParent, this._oTargetHandler);
return new Target(oOptions, this.getViews(), oParent, this._oTargetHandler);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/sap.m/src/sap/m/routing/async/Target.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sap.ui.define([], function() {
return this._oTargetHandler._chainNavigation(function() {
return oPromise.then(function(oViewInfo) {
that._oTargetHandler.addNavigation({
navigationIdentifier : that._oOptions.name,
navigationIdentifier : that._oOptions._name,
transition: that._oOptions.transition,
transitionParameters: that._oOptions.transitionParameters,
eventData: vData,
Expand Down
2 changes: 1 addition & 1 deletion src/sap.m/src/sap/m/routing/async/Targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sap.ui.define([], function() {
// maybe a wrong name was provided then there is no last displayed target
if (this._oLastDisplayedTarget) {
iViewLevel = this._getViewLevel(this._oLastDisplayedTarget);
sName = this._oLastDisplayedTarget._oOptions.name;
sName = this._oLastDisplayedTarget._oOptions._name;
}

this._oTargetHandler.navigate({
Expand Down
2 changes: 1 addition & 1 deletion src/sap.m/src/sap/m/routing/sync/Target.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ sap.ui.define([], function() {

this._oTargetHandler.addNavigation({

navigationIdentifier : this._oOptions.name,
navigationIdentifier : this._oOptions._name,
transition: this._oOptions.transition,
transitionParameters: this._oOptions.transitionParameters,
eventData: vData,
Expand Down
2 changes: 1 addition & 1 deletion src/sap.m/src/sap/m/routing/sync/Targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sap.ui.define([], function() {
// maybe a wrong name was provided then there is no last displayed target
if (this._oLastDisplayedTarget) {
iViewLevel = this._getViewLevel(this._oLastDisplayedTarget);
sName = this._oLastDisplayedTarget._oOptions.name;
sName = this._oLastDisplayedTarget._oOptions._name;
}

this._oTargetHandler.navigate({
Expand Down
3 changes: 3 additions & 0 deletions src/sap.m/test/sap/m/qunit/routing/async/Router.qunit.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
this.oViewMock = {
loaded: function() {
return Promise.resolve(that.oToPage);
},
isA: function(sClass) {
return sClass === "sap.ui.core.mvc.View";
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions src/sap.m/test/sap/m/qunit/routing/async/Targets.qunit.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
this.oViewMock = {
loaded: function() {
return Promise.resolve(that.oToPage);
},
isA: function(sClass) {
return sClass === "sap.ui.core.mvc.View";
}
}
},
Expand Down
11 changes: 7 additions & 4 deletions src/sap.m/test/sap/m/qunit/routing/async/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,26 @@ sap.ui.define(
}

function createViewAndControllerAsync(sName) {
return createViewMock({viewName: sName});
return createViewMock({name: sName});
}

function createViewMock(oViewOptions) {
var oView;
createViewAndController(oViewOptions.viewName);
createViewAndController(oViewOptions.name);
return {
loaded: function() {
oView = sap.ui.jsview(oViewOptions.viewName, oViewOptions.viewName);
oView = sap.ui.jsview(oViewOptions.name, oViewOptions.name);
return new Promise(function(resolve) {
setTimeout(function() {
resolve(oView);
}, _mViewDelays[oViewOptions.viewName]);
}, _mViewDelays[oViewOptions.name]);
});
},
destroy: function() {
oView.destroy();
},
isA: function(sClass) {
return sClass === "sap.ui.core.mvc.View";
}
};
}
Expand Down
6 changes: 4 additions & 2 deletions src/sap.ui.core/src/sap/ui/core/routing/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ sap.ui.define([
vRoute = oConfig.pattern,
aSubRoutes,
RouteStub,
async = oRouter._isAsync();
async = oRouter._isAsync(),
oMergedConfig;

RouteStub = async ? asyncRoute : syncRoute;
for (var fn in RouteStub) {
Expand Down Expand Up @@ -123,7 +124,8 @@ sap.ui.define([
if (!oConfig.target) {
oConfig._async = async;
// create a new target for this route
this._oTarget = new Target(oConfig, oRouter._oViews, oParent && oParent._oTarget);
oMergedConfig = jQuery.extend({}, oRouter._oConfig, oConfig);
this._oTarget = new Target(this._convertToTargetOptions(oMergedConfig), oRouter._oViews, oParent && oParent._oTarget);
this._oTarget._bUseRawViewId = true;
}

Expand Down
55 changes: 42 additions & 13 deletions src/sap.ui.core/src/sap/ui/core/routing/Target.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sap.ui.define([
*
* @class
* @param {object} oOptions all of the parameters defined in {@link sap.m.routing.Targets#constructor} are accepted here, except for children you need to specify the parent.
* @param {sap.ui.core.routing.Views} oViews All views required by this target will get created by the views instance using {@link sap.ui.core.routing.Views#getView}
* @param {sap.ui.core.routing.TargetCache} oCache All views required by this target will get created by the views instance using {@link sap.ui.core.routing.Views#getView}
* @param {sap.ui.core.routing.Target} [oParent] the parent of this target. Will also get displayed, if you display this target. In the config you have the fill the children property {@link sap.m.routing.Targets#constructor}
* @public
* @since 1.28.1
Expand All @@ -40,7 +40,8 @@ sap.ui.define([
*/
var Target = EventProvider.extend("sap.ui.core.routing.Target", /** @lends sap.ui.core.routing.Target.prototype */ {

constructor : function(oOptions, oViews) {
constructor : function(oOptions, oCache) {
var sErrorMessage;
// temporarily: for checking the url param
function checkUrl() {
if (new UriParameters(window.location.href).get("sap-ui-xx-asyncRouting") === "true") {
Expand All @@ -55,8 +56,36 @@ sap.ui.define([
oOptions._async = checkUrl();
}

if (oOptions.type === "Component" && !oOptions._async) {
sErrorMessage = "sap.ui.core.routing.Target doesn't support loading component in synchronous mode, please switch routing to async";
jQuery.sap.log.error(sErrorMessage);
throw new Error(sErrorMessage);
}

// convert the legacy syntax to the new one
// if "viewName" is set, it's converted to "type" and "name"
// meanwhile, the "viewPath" is also set to "path" and the
// "viewId" is also set to "id"
if (oOptions.viewName) {
// if the target's name is given under the "name" property,
// copy it to "_name" before overwritting it with the "viewName"
if (oOptions.name) {
oOptions._name = oOptions.name;
}
oOptions.type = "View";
oOptions.name = oOptions.viewName;

if (oOptions.viewPath) {
oOptions.path = oOptions.viewPath;
}

if (oOptions.viewId) {
oOptions.id = oOptions.viewId;
}
}

this._oOptions = oOptions;
this._oViews = oViews;
this._oCache = oCache;
EventProvider.apply(this, arguments);

if (this._oOptions.title) {
Expand All @@ -83,7 +112,7 @@ sap.ui.define([
destroy : function () {
this._oParent = null;
this._oOptions = null;
this._oViews = null;
this._oCache = null;
if (this._oTitleProvider) {
this._oTitleProvider.destroy();
}
Expand Down Expand Up @@ -160,7 +189,7 @@ sap.ui.define([
var sTitle = this._oTitleProvider && this._oTitleProvider.getTitle();
if (sTitle) {
this.fireTitleChanged({
name: this._oOptions.name,
name: this._oOptions._name,
title: sTitle
});
}
Expand Down Expand Up @@ -206,7 +235,7 @@ sap.ui.define([
// in case the title is changed before the first event listener is attached, we need to notify, too
if (!bHasListener && sTitle && this._bIsDisplayed) {
this.fireTitleChanged({
name: this._oOptions.name,
name: this._oOptions._name,
title: sTitle
});
}
Expand All @@ -232,14 +261,14 @@ sap.ui.define([
return this.fireEvent(this.M_EVENTS.TITLE_CHANGED, mArguments);
},

_getEffectiveViewName : function (sViewName) {
var sViewPath = this._oOptions.viewPath;
_getEffectiveObjectName : function (sName) {
var sPath = this._oOptions.path;

if (sViewPath) {
sViewName = sViewPath + "." + sViewName;
if (sPath) {
sName = sPath + "." + sName;
}

return sViewName;
return sName;
},

_bindTitleInTitleProvider : function(oView) {
Expand Down Expand Up @@ -340,7 +369,7 @@ sap.ui.define([

if (this._oTarget._bIsDisplayed) {
this._oTarget.fireTitleChanged({
name: this._oTarget._oOptions.name,
name: this._oTarget._oOptions._name,
title: sTitle
});
}
Expand All @@ -349,4 +378,4 @@ sap.ui.define([

return Target;

});
});

0 comments on commit 87e8d59

Please sign in to comment.