Skip to content

Commit 66a8048

Browse files
committed
Added anything needed for Step 9 of the Navigation Tutorial; Bookmarkable Tabs with Optional Query Parameters
1 parent 4c0f5c2 commit 66a8048

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

webapp/controller/employee/Resume.controller.js

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
sap.ui.define([
2-
"com/mrb/UI5-Navigation-and-Routing/controller/BaseController"
2+
"com/mrb/UI5-Navigation-and-Routing/controller/BaseController",
3+
"sap/ui/model/json/JSONModel"
34
], function (
4-
BaseController
5+
BaseController,
6+
JSONModel
57
) {
68
"use strict";
9+
var _aValidTabKeys = ["Info", "Projects", "Hobbies", "Notes"];
710
return BaseController.extend("com.mrb.UI5-Navigation-and-Routing.controller.employee.Resume", {
811
onInit: function () {
912
var oRouter = this.getRouter();
13+
this.getView().setModel(new JSONModel(), "view");
1014
oRouter.getRoute("employeeResume").attachMatched(this._onRouteMatched, this);
1115
},
1216
_onRouteMatched: function (oEvent) {
13-
var oArgs, oView;
17+
var oArgs, oView, oQuery;
18+
//Read the passed in arguments
1419
oArgs = oEvent.getParameter("arguments");
1520
oView = this.getView();
1621
oView.bindElement({
@@ -25,12 +30,35 @@ sap.ui.define([
2530
}
2631
}
2732
});
33+
oQuery = oArgs["?query"];
34+
if (oQuery && _aValidTabKeys.indexOf(oQuery.tab) > -1) {
35+
oView.getModel("view").setProperty("/selectedTabKey", oQuery.tab);
36+
} else {
37+
// the default query param should be visible at all time
38+
this.getRouter().navTo("employeeResume", {
39+
employeeId: oArgs.employeeId,
40+
"?query": {
41+
tab: _aValidTabKeys[0]
42+
}
43+
}, true /*no history*/ );
44+
}
2845
},
2946
_onBindingChange: function (oEvent) {
3047
// No data for the binding
3148
if (!this.getView().getBindingContext()) {
3249
this.getRouter().getTargets().display("notFound");
3350
}
51+
},
52+
onTabSelect: function (oEvent) {
53+
var oCtx = this.getView().getBindingContext();
54+
//https://sapui5.hana.ondemand.com/#/api/sap.ui.core.routing.Router%23methods/navTo
55+
//:?queryParameter: -> :: -> optional | {someParameter} -> {} -> mandatory
56+
this.getRouter().navTo("employeeResume", {
57+
employeeId: oCtx.getProperty("EmployeeID"),
58+
"?query": {
59+
tab: oEvent.getParameter("selectedKey")
60+
}
61+
}, true /*without history*/ );
3462
}
3563
});
3664
});

webapp/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"target": "employee"
109109
},
110110
{
111-
"pattern": "employees/{employeeId}/resume",
111+
"pattern": "employees/{employeeId}/resume:?query:",
112112
"name": "employeeResume",
113113
"target": "employeeResume"
114114
}

webapp/view/employee/Resume.view.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:mvc="sap.ui.core.mvc">
44
<Page title="{i18n>ResumeOf} {FirstName} {LastName}" id="employeeResumePage" showNavButton="true" navButtonPress=".onNavBack">
55
<content>
6-
<IconTabBar id="iconTabBar" headerBackgroundDesign="Transparent" class="sapUiResponsiveContentPadding" binding="{Resume}">
6+
<IconTabBar id="iconTabBar" headerBackgroundDesign="Transparent" class="sapUiResponsiveContentPadding" binding="{Resume}" select=".onTabSelect" selectedKey="{view>/selectedTabKey}">
77
<items>
88
<IconTabFilter id="infoTab" text="{i18n>tabInfo}" key="Info">
99
<Text text="{Information}"/>

0 commit comments

Comments
 (0)