Skip to content

Commit

Permalink
Added anything needed for Step 9 of the Navigation Tutorial; Bookmark…
Browse files Browse the repository at this point in the history
…able Tabs with Optional Query Parameters
  • Loading branch information
wridgeu committed Mar 30, 2020
1 parent 4c0f5c2 commit 66a8048
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
34 changes: 31 additions & 3 deletions webapp/controller/employee/Resume.controller.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
sap.ui.define([
"com/mrb/UI5-Navigation-and-Routing/controller/BaseController"
"com/mrb/UI5-Navigation-and-Routing/controller/BaseController",
"sap/ui/model/json/JSONModel"
], function (
BaseController
BaseController,
JSONModel
) {
"use strict";
var _aValidTabKeys = ["Info", "Projects", "Hobbies", "Notes"];
return BaseController.extend("com.mrb.UI5-Navigation-and-Routing.controller.employee.Resume", {
onInit: function () {
var oRouter = this.getRouter();
this.getView().setModel(new JSONModel(), "view");
oRouter.getRoute("employeeResume").attachMatched(this._onRouteMatched, this);
},
_onRouteMatched: function (oEvent) {
var oArgs, oView;
var oArgs, oView, oQuery;
//Read the passed in arguments
oArgs = oEvent.getParameter("arguments");
oView = this.getView();
oView.bindElement({
Expand All @@ -25,12 +30,35 @@ sap.ui.define([
}
}
});
oQuery = oArgs["?query"];
if (oQuery && _aValidTabKeys.indexOf(oQuery.tab) > -1) {
oView.getModel("view").setProperty("/selectedTabKey", oQuery.tab);
} else {
// the default query param should be visible at all time
this.getRouter().navTo("employeeResume", {
employeeId: oArgs.employeeId,
"?query": {
tab: _aValidTabKeys[0]
}
}, true /*no history*/ );
}
},
_onBindingChange: function (oEvent) {
// No data for the binding
if (!this.getView().getBindingContext()) {
this.getRouter().getTargets().display("notFound");
}
},
onTabSelect: function (oEvent) {
var oCtx = this.getView().getBindingContext();
//https://sapui5.hana.ondemand.com/#/api/sap.ui.core.routing.Router%23methods/navTo
//:?queryParameter: -> :: -> optional | {someParameter} -> {} -> mandatory
this.getRouter().navTo("employeeResume", {
employeeId: oCtx.getProperty("EmployeeID"),
"?query": {
tab: oEvent.getParameter("selectedKey")
}
}, true /*without history*/ );
}
});
});
2 changes: 1 addition & 1 deletion webapp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"target": "employee"
},
{
"pattern": "employees/{employeeId}/resume",
"pattern": "employees/{employeeId}/resume:?query:",
"name": "employeeResume",
"target": "employeeResume"
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/view/employee/Resume.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:mvc="sap.ui.core.mvc">
<Page title="{i18n>ResumeOf} {FirstName} {LastName}" id="employeeResumePage" showNavButton="true" navButtonPress=".onNavBack">
<content>
<IconTabBar id="iconTabBar" headerBackgroundDesign="Transparent" class="sapUiResponsiveContentPadding" binding="{Resume}">
<IconTabBar id="iconTabBar" headerBackgroundDesign="Transparent" class="sapUiResponsiveContentPadding" binding="{Resume}" select=".onTabSelect" selectedKey="{view>/selectedTabKey}">
<items>
<IconTabFilter id="infoTab" text="{i18n>tabInfo}" key="Info">
<Text text="{Information}"/>
Expand Down

0 comments on commit 66a8048

Please sign in to comment.