Skip to content

Commit

Permalink
Basic Setup: Added and adjusted everything needed for Step 1: Overvie…
Browse files Browse the repository at this point in the history
…w and Testing Strategy - to get started with the application
  • Loading branch information
wridgeu committed May 23, 2020
1 parent 8fdb4b3 commit 0ebd475
Show file tree
Hide file tree
Showing 31 changed files with 1,134 additions and 243 deletions.
38 changes: 29 additions & 9 deletions webapp/controller/App.Controller.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
sap.ui.define([
"com/mrb/UI5-Testing/controller/BaseController"
], function(
BaseController
) {
"use strict";
sap.ui.define(
[
"./BaseController",
"sap/ui/model/json/JSONModel",
],
function (BaseController, JSONModel) {
"use strict";

return BaseController.extend("com.mrb.UI5-Testing.controller.App.Controller", {
});
});
return BaseController.extend(
"com.mrb.UI5-Testing.controller.App.Controller",
{
onInit: function () {
var oViewModel = new JSONModel({
busy: true,
delay: 0,
});

this.setModel(oViewModel, "appView");

this.getOwnerComponent()
.getModel()
.metadataLoaded()
.then(function () {
oViewModel.setProperty("/busy", false);
});
},
}
);
}
);
132 changes: 70 additions & 62 deletions webapp/controller/BaseController.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,78 @@
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/routing/History",
"sap/ui/core/UIComponent",
"com/mrb/UI5-Testing/model/formatter"
], function(Controller, History, UIComponent, formatter) {
"use strict";
sap.ui.define(
[
"sap/ui/core/mvc/Controller",
"sap/ui/core/routing/History",
"sap/ui/core/UIComponent",
"com/mrb/UI5-Testing/model/formatter",
],
function (Controller, History, UIComponent, formatter) {
"use strict";

return Controller.extend("com.mrb.UI5-Testing.controller.BaseController", {
return Controller.extend("com.mrb.UI5-Testing.controller.BaseController", {
formatter: formatter,
/**
* Convenience method for accessing the event bus.
* @public
* @returns {sap.ui.core.EventBus} the event bus for this component
*/
getEventBus: function () {
return this.getOwnerComponent().getEventBus();
},

formatter: formatter,
/**
* Convenience method for getting the view model by name in every controller of the application.
* @public
* @param {string} sName the model name
* @returns {sap.ui.model.Model} the model instance
*/
getModel: function (sName) {
return this.getView().getModel(sName);
},

/**
* Convenience method for getting the view model by name in every controller of the application.
* @public
* @param {string} sName the model name
* @returns {sap.ui.model.Model} the model instance
*/
getModel: function(sName) {
return this.getView().getModel(sName);
},
/**
* Convenience method for setting the view model in every controller of the application.
* @public
* @param {sap.ui.model.Model} oModel the model instance
* @param {string} sName the model name
* @returns {sap.ui.mvc.View} the view instance
*/
setModel: function (oModel, sName) {
return this.getView().setModel(oModel, sName);
},

/**
* Convenience method for setting the view model in every controller of the application.
* @public
* @param {sap.ui.model.Model} oModel the model instance
* @param {string} sName the model name
* @returns {sap.ui.mvc.View} the view instance
*/
setModel: function(oModel, sName) {
return this.getView().setModel(oModel, sName);
},
/**
* Convenience method for getting the resource bundle.
* @public
* @returns {sap.ui.model.resource.ResourceModel} the resourceModel of the component
*/
getResourceBundle: function () {
return this.getOwnerComponent().getModel("i18n").getResourceBundle();
},

/**
* Convenience method for getting the resource bundle.
* @public
* @returns {sap.ui.model.resource.ResourceModel} the resourceModel of the component
*/
getResourceBundle: function() {
return this.getOwnerComponent().getModel("i18n").getResourceBundle();
},
/**
* Method for navigation to specific view
* @public
* @param {string} psTarget Parameter containing the string for the target navigation
* @param {mapping} pmParameters? Parameters for navigation
* @param {boolean} pbReplace? Defines if the hash should be replaced (no browser history entry) or set (browser history entry)
*/
navTo: function (psTarget, pmParameters, pbReplace) {
this.getRouter().navTo(psTarget, pmParameters, pbReplace);
},

/**
* Method for navigation to specific view
* @public
* @param {string} psTarget Parameter containing the string for the target navigation
* @param {mapping} pmParameters? Parameters for navigation
* @param {boolean} pbReplace? Defines if the hash should be replaced (no browser history entry) or set (browser history entry)
*/
navTo: function(psTarget, pmParameters, pbReplace) {
this.getRouter().navTo(psTarget, pmParameters, pbReplace);
},
getRouter: function () {
return UIComponent.getRouterFor(this);
},

getRouter: function() {
return UIComponent.getRouterFor(this);
},
onNavBack: function () {
var sPreviousHash = History.getInstance().getPreviousHash();

onNavBack: function() {
var sPreviousHash = History.getInstance().getPreviousHash();

if (sPreviousHash !== undefined) {
window.history.back();
} else {
this.getRouter().navTo("appHome", {}, true /*no history*/ );
}
}

});

});
if (sPreviousHash !== undefined) {
window.history.back();
} else {
this.getRouter().navTo("appHome", {}, true /*no history*/);
}
},
});
}
);
7 changes: 0 additions & 7 deletions webapp/controller/Home.controller.js

This file was deleted.

114 changes: 114 additions & 0 deletions webapp/controller/Worklist.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
sap.ui.define(
[
"./BaseController",
"sap/ui/model/json/JSONModel",
"../model/formatter",
"sap/m/library",
],
function (BaseController, JSONModel, formatter, mobileLibrary) {
"use strict";

return BaseController.extend("com.mrb.UI5-Testing.controller.Worklist", {
/**
* Called when the worklist controller is instantiated.
* @public
*/
onInit: function () {
var oViewModel,
iOriginalBusyDelay,
oTable = this.byId("table");

// Put down worklist table's original value for busy indicator delay,
// so it can be restored later on. Busy handling on the table is
// taken care of by the table itself.
iOriginalBusyDelay = oTable.getBusyIndicatorDelay();

// Model used to manipulate control states
oViewModel = new JSONModel({
worklistTableTitle: this.getResourceBundle().getText(
"worklistTableTitle"
),
shareSendEmailSubject: this.getResourceBundle().getText(
"shareSendEmailWorklistSubject"
),
shareSendEmailMessage: this.getResourceBundle().getText(
"shareSendEmailWorklistMessage",
[window.location.href]
),
tableBusyDelay: 0,
});
this.setModel(oViewModel, "worklistView");

// Make sure, busy indication is showing immediately so there is no
// break after the busy indication for loading the view's meta data is
// ended (see promise 'oWhenMetadataIsLoaded' in AppController)
oTable.attachEventOnce("updateFinished", function () {
// Restore original busy indicator delay for worklist's table
oViewModel.setProperty("/tableBusyDelay", iOriginalBusyDelay);
});
},

/* =========================================================== */
/* event handlers */
/* =========================================================== */

/**
* Triggered by the table's 'updateFinished' event: after new table
* data is available, this handler method updates the table counter.
* This should only happen if the update was successful, which is
* why this handler is attached to 'updateFinished' and not to the
* table's list binding's 'dataReceived' method.
*
* @param {sap.ui.base.Event} oEvent the update finished event
* @public
*/
onUpdateFinished: function (oEvent) {
// update the worklist's object counter after the table update
var sTitle,
oTable = oEvent.getSource(),
iTotalItems = oEvent.getParameter("total");
// only update the counter if the length is final and
// the table is not empty
if (iTotalItems && oTable.getBinding("items").isLengthFinal()) {
sTitle = this.getResourceBundle().getText("worklistTableTitleCount", [
iTotalItems,
]);
} else {
sTitle = this.getResourceBundle().getText("worklistTableTitle");
}
this.getModel("worklistView").setProperty(
"/worklistTableTitle",
sTitle
);
},
/**
* Sets the item count on the worklist view header
* @param {int} iTotalItems the total number of items in the table
* @private
*/
_updateListItemCount: function (iTotalItems) {
var sTitle;
// only update the counter if the length is final
if (this._oTable.getBinding("items").isLengthFinal()) {
sTitle = this.getResourceBundle().getText("worklistTableTitleCount", [
iTotalItems,
]);
this.oViewModel.setProperty("/worklistTableTitle", sTitle);
}
},

/**
* Event handler when the share by E-Mail button has been clicked
* @public
*/
onShareEmailPress: function () {
var oViewModel = this.getModel("worklistView");
mobileLibrary.URLHelper.triggerEmail(
null,
oViewModel.getProperty("/shareSendEmailSubject"),
oViewModel.getProperty("/shareSendEmailMessage")
);
},
});
}
);
34 changes: 34 additions & 0 deletions webapp/i18n/i18n.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
title=UI5-Testing
appTitle=UI5-Testing
appDescription=UI5 Testing Walkthrough

# This is the resource bundle for the worklist app

#~~~ Worklist View ~~~~~~~~~~~~~~~~~~~~~~~~~~
#XTIT: Table view title - Not used as we're using the Repository 'UI5-Testing' title
worklistViewTitle=Bulletin Board

#XTIT: Table view title
worklistTableTitle=Posts

#XTIT: Table view title with placeholder for the number of items
worklistTableTitleCount=Posts ({0})

#XTIT: The title of the column containing the Names of objects
TableNameColumnTitle=Name

#XTIT: The title of the column containing the Category of objects
TableCategoryColumnTitle=Category

#XTIT: The title of the column containing the unit number and the unit of measure
TableUnitNumberColumnTitle=Price

#~~~ Object View ~~~~~~~~~~~~~~~~~~~~~~~~~~

#XTIT: Object view title
objectTitle=Post

#~~~ Footer Options ~~~~~~~~~~~~~~~~~~~~~~~

#XTIT: Send E-Mail subject
shareSendEmailWorklistSubject=<Email subject PLEASE REPLACE ACCORDING TO YOUR USE CASE>

#YMSG: Send E-Mail message
shareSendEmailWorklistMessage=<Email body PLEASE REPLACE ACCORDING TO YOUR USE CASE>\r\n{0}
43 changes: 21 additions & 22 deletions webapp/index.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
<!DOCTYPE HTML>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/resources/img/ui5.png" rel="shortcut icon" type="image/x-icon" />
<title>Bulletin Board</title>

<!-- try to load the basic UI5 styles for standalone and demokit usecase -->
<link rel="stylesheet" href="/resources/sap/ui/core/themes/sap_fiori_3/library.css">
<link rel="stylesheet" href="/resources/sap/ui/core/themes/sap_fiori_3/library.css">
</head>

<title>UI5-Testing</title>
<body class="sapUiBody sapUiForceWidthAuto">
<div style="display: flex; flex-direction: column; align-items: center; margin-top: 15vh;">
<h1>Bulletin Board</h1>
<p>This sample app for the testing will test application functionality <br> with QUnit, OPA5, and the mock
server</p>

<script id="sap-ui-bootstrap"
src="resources/sap-ui-core.js"
data-sap-ui-theme="sap_fiori_3"
data-sap-ui-resourceroots='{
"com.mrb.UI5-Testing": "./"
}'
data-sap-ui-oninit="module:sap/ui/core/ComponentSupport"
data-sap-ui-compatVersion="edge"
data-sap-ui-async="true"
data-sap-ui-frameOptions="trusted"
data-sap-ui-logLevel="NONE">
</script>
</head>
<h2>Entry points</h2>
<p>Can be used to run the app or the automated tests as needed:</p>

<body class="sapUiBody">
<div data-sap-ui-component data-name="com.mrb.UI5-Testing" data-id="container"
data-settings='{"id" : "UI5-Testing"}'>
</div>
<ul>
<li><a href="test/mockServer.html">mockServer.html</a> - start the app with mock data</li>
<li><a href="test/unit/unitTests.qunit.html">unit/unitTests.qunit.html</a> - run all unit tests</li>
<li><a href="test/integration/opaTests.qunit.html">integration/opaTests.qunit.html</a> - run all integration
tests</li>
</ul>
<p>For more documentation please read the <a href="https://openui5.hana.ondemand.com">UI5 Developer Guide</a>.
</p>
</div>
</body>

</html>
Loading

0 comments on commit 0ebd475

Please sign in to comment.