├── .github
├── in-solidarity.yml
└── workflows
│ ├── deploy.yml
│ └── test.yml
├── .gitignore
├── LICENSE
├── README.md
├── demo
├── .gitignore
├── .npmrc
├── BaseComponent
│ ├── package.json
│ ├── src
│ │ └── my
│ │ │ └── lib
│ │ │ └── sample
│ │ │ └── base
│ │ │ ├── BaseController.js
│ │ │ ├── Component.js
│ │ │ ├── library.js
│ │ │ └── manifest.json
│ └── ui5.yaml
├── CategoriesComponent
│ ├── package.json
│ ├── src
│ │ └── my
│ │ │ └── lib
│ │ │ └── sample
│ │ │ └── categories
│ │ │ ├── Component.js
│ │ │ ├── controller
│ │ │ ├── App.controller.js
│ │ │ ├── Detail.controller.js
│ │ │ └── List.controller.js
│ │ │ ├── css
│ │ │ └── style.css
│ │ │ ├── i18n
│ │ │ └── i18n.properties
│ │ │ ├── localService
│ │ │ ├── metadata.xml
│ │ │ ├── mockdata
│ │ │ │ ├── Categories.json
│ │ │ │ ├── Products.json
│ │ │ │ └── Suppliers.json
│ │ │ └── mockserver.js
│ │ │ ├── manifest.json
│ │ │ ├── test
│ │ │ ├── initMockServer.js
│ │ │ └── mockServer.html
│ │ │ └── view
│ │ │ ├── App.view.xml
│ │ │ ├── Detail.view.xml
│ │ │ ├── List.view.xml
│ │ │ └── NotFound.view.xml
│ └── ui5.yaml
├── ProductsComponent
│ ├── package.json
│ ├── src
│ │ └── my
│ │ │ └── lib
│ │ │ └── sample
│ │ │ └── products
│ │ │ ├── Component.js
│ │ │ ├── controller
│ │ │ ├── App.controller.js
│ │ │ ├── Detail.controller.js
│ │ │ └── List.controller.js
│ │ │ ├── css
│ │ │ └── style.css
│ │ │ ├── i18n
│ │ │ └── i18n.properties
│ │ │ ├── localService
│ │ │ ├── metadata.xml
│ │ │ ├── mockdata
│ │ │ │ ├── Categories.json
│ │ │ │ ├── Products.json
│ │ │ │ └── Suppliers.json
│ │ │ └── mockserver.js
│ │ │ ├── manifest.json
│ │ │ ├── test
│ │ │ ├── initMockServer.js
│ │ │ └── mockServer.html
│ │ │ └── view
│ │ │ ├── App.view.xml
│ │ │ ├── Detail.view.xml
│ │ │ ├── List.view.xml
│ │ │ └── NotFound.view.xml
│ └── ui5.yaml
├── README.md
├── RootComponent
│ ├── karma-ci.conf.js
│ ├── karma.conf.js
│ ├── package.json
│ ├── ui5.yaml
│ └── webapp
│ │ ├── Component.js
│ │ ├── controller
│ │ ├── App.controller.js
│ │ └── Home.controller.js
│ │ ├── css
│ │ └── style.css
│ │ ├── i18n
│ │ ├── i18n.properties
│ │ └── i18n_en.properties
│ │ ├── img
│ │ └── diagram.jpg
│ │ ├── index.html
│ │ ├── localService
│ │ ├── metadata.xml
│ │ ├── mockdata
│ │ │ ├── Categories.json
│ │ │ ├── Products.json
│ │ │ └── Suppliers.json
│ │ └── mockserver.js
│ │ ├── manifest.json
│ │ ├── test
│ │ ├── initMockServer.js
│ │ ├── integration
│ │ │ ├── AllJourneys.js
│ │ │ ├── NavigationJourney.js
│ │ │ ├── arrangements
│ │ │ │ └── Startup.js
│ │ │ ├── opaTests.qunit.html
│ │ │ ├── opaTests.qunit.js
│ │ │ └── pages
│ │ │ │ ├── App.js
│ │ │ │ └── Home.js
│ │ ├── mockServer.html
│ │ ├── testsuite.qunit.html
│ │ ├── testsuite.qunit.js
│ │ └── unit
│ │ │ ├── AllTests.js
│ │ │ ├── base
│ │ │ └── BaseController.js
│ │ │ ├── unitTests.qunit.html
│ │ │ └── unitTests.qunit.js
│ │ └── view
│ │ ├── App.view.xml
│ │ ├── Home.view.xml
│ │ └── NotFound.view.xml
├── SuppliersComponent
│ ├── .gitignore
│ ├── package.json
│ ├── src
│ │ └── my
│ │ │ └── lib
│ │ │ └── sample
│ │ │ └── suppliers
│ │ │ ├── Component.js
│ │ │ ├── controller
│ │ │ ├── App.controller.js
│ │ │ ├── Detail.controller.js
│ │ │ └── List.controller.js
│ │ │ ├── css
│ │ │ └── style.css
│ │ │ ├── i18n
│ │ │ └── i18n.properties
│ │ │ ├── index.html
│ │ │ ├── localService
│ │ │ ├── metadata.xml
│ │ │ ├── mockdata
│ │ │ │ ├── Categories.json
│ │ │ │ ├── Products.json
│ │ │ │ └── Suppliers.json
│ │ │ └── mockserver.js
│ │ │ ├── manifest.json
│ │ │ ├── test
│ │ │ ├── initMockServer.js
│ │ │ └── mockServer.html
│ │ │ └── view
│ │ │ ├── App.view.xml
│ │ │ ├── Detail.view.xml
│ │ │ ├── List.view.xml
│ │ │ └── NotFound.view.xml
│ └── ui5.yaml
├── eslint.config.mjs
├── package-lock.json
└── package.json
├── renovate.json
└── slides
└── UI5con20_Routing_Reusable_Components.pdf
/.github/in-solidarity.yml:
--------------------------------------------------------------------------------
1 | _extends: ietf/terminology
2 |
--------------------------------------------------------------------------------
/.github/workflows/deploy.yml:
--------------------------------------------------------------------------------
1 | # This is a basic workflow to help you get started with Actions
2 |
3 | name: Deploy
4 |
5 | # Controls when the action will run. Triggers the workflow on push or pull request
6 | # events but only for the main branch
7 | on:
8 | push:
9 | branches: [ main ]
10 |
11 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
12 | jobs:
13 | # This workflow contains a single job called "build-and-deploy-application"
14 | build-and-deploy-application:
15 | # The type of runner that the job will run on
16 | runs-on: ubuntu-24.04
17 |
18 | # Steps represent a sequence of tasks that will be executed as part of the job
19 | steps:
20 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
21 | - uses: actions/checkout@v4
22 |
23 | - name: Setup Node.js environment
24 | uses: actions/setup-node@v4
25 | with:
26 | node-version: "22"
27 |
28 | - name: Install the Dependencies
29 | run: npm ci
30 | working-directory: ./demo
31 |
32 | - name: Build the Application
33 | run: npm run build
34 | working-directory: ./demo/RootComponent
35 |
36 | - name: GitHub Pages action
37 | uses: peaceiris/actions-gh-pages@v4
38 | with:
39 | # Set a generated GITHUB_TOKEN for pushing to the remote branch.
40 | github_token: ${{ secrets.GITHUB_TOKEN }}
41 | # Set an input directory for deployment.
42 | publish_dir: ./demo/RootComponent/dist
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Test
2 |
3 | on:
4 | push:
5 | branches: [ main ]
6 | pull_request:
7 | branches: [ main ]
8 |
9 | jobs:
10 | test-application:
11 | runs-on: ubuntu-24.04
12 | steps:
13 | - uses: actions/checkout@v4
14 | - name: Setup Node.js environment
15 | uses: actions/setup-node@v4
16 | with:
17 | node-version: "22"
18 | - name: Install the Dependencies
19 | run: npm ci
20 | working-directory: ./demo
21 | - name: Run ESLint Checks
22 | run: npm run lint
23 | working-directory: ./demo
24 | - name: Test the Application
25 | run: npm run test
26 | working-directory: ./demo/RootComponent
27 | - name: Coveralls
28 | uses: coverallsapp/github-action@master
29 | with:
30 | github-token: ${{ secrets.GITHUB_TOKEN }}
31 | path-to-lcov: "./demo/RootComponent/coverage/lcov/lcov.info"
32 | base-path: "./demo/RootComponent"
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ui5-nested-component-scenario
2 |
3 | This repository provides a nested component scenario powered by UI5 Tooling.
4 |
5 | The folder [demo](/demo) contains the application which is used for the demo.
6 |
7 | The folder [slides](/slides) contains the slides for the session.
8 |
9 | ## Live Demo
10 |
11 | Just visit the [live demo](https://flovogt.github.io/ui5-nested-component-scenario/test/mockServer.html) to play with the application.
12 |
13 | ## UI5con 2020
14 |
15 | The repository was originally created for the UI5con session *UI5 Routing with Reusable Components* in 2020. The original sources can be found in branch [ui5con2020](https://github.com/flovogt/ui5-nested-component-scenario/tree/ui5con2020).
16 |
--------------------------------------------------------------------------------
/demo/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | dist/
3 | .DS_Store
4 | coverage/
--------------------------------------------------------------------------------
/demo/.npmrc:
--------------------------------------------------------------------------------
1 | # Enforce public npm registry
2 | registry=https://registry.npmjs.org/
3 | lockfile-version=3
4 |
--------------------------------------------------------------------------------
/demo/BaseComponent/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "my-lib-sample-base-component",
3 | "private": true,
4 | "version": "0.0.1",
5 | "description": "This is the base component",
6 | "scripts": {
7 | "start": "ui5 serve",
8 | "test": "rimraf coverage && npm run karma-ci",
9 | "lint": "eslint src",
10 | "karma": "karma start",
11 | "karma-ci": "karma start karma-ci.conf.js"
12 | },
13 | "repository": {
14 | "type": "git",
15 | "url": "git@github.com:flovogt/ui5-nested-component-scenario.git"
16 | },
17 | "keywords": [
18 | "openui5",
19 | "sapui5",
20 | "ui5",
21 | "ui5con",
22 | "ui5-routing",
23 | "ui5-component"
24 | ],
25 | "devDependencies": {
26 | "eslint": "^9.25.0",
27 | "@ui5/cli": "^4.0.14",
28 | "local-web-server": "^5.4.0",
29 | "karma": "^6.4.4",
30 | "karma-coverage": "^2.2.1",
31 | "karma-chrome-launcher": "^3.2.0",
32 | "karma-ui5": "^4.1.0",
33 | "rimraf": "^6.0.1"
34 | },
35 | "engines": {
36 | "node": "^16.18.0 || >=18.12.0",
37 | "npm": ">= 8"
38 | },
39 | "author": "Jiawei Cao, Florian Vogt",
40 | "license": "Apache-2.0"
41 | }
42 |
--------------------------------------------------------------------------------
/demo/BaseComponent/src/my/lib/sample/base/BaseController.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "sap/ui/core/mvc/Controller",
3 | "sap/base/Log"
4 | ], (Controller, Log) => {
5 | "use strict";
6 |
7 | return Controller.extend("my.lib.sample.base.BaseController", {
8 | base64StringToImage(picture) {
9 | return picture ? `data:image/bmp;base64,${ picture}` : null;
10 | },
11 | onInit() {
12 | Log.info(this.getView().getControllerName(), "onInit");
13 | }
14 | });
15 | });
16 |
--------------------------------------------------------------------------------
/demo/BaseComponent/src/my/lib/sample/base/Component.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "sap/ui/core/UIComponent",
3 | "sap/base/util/deepClone"
4 | ], (UIComponent, deepClone) => {
5 | "use strict";
6 |
7 | return UIComponent.extend("my.lib.sample.base.Component", {
8 | init(...args) {
9 | UIComponent.prototype.init.apply(this, args);
10 |
11 | const oRouter = this.getRouter();
12 | oRouter.getViews().attachCreated(this._processEventMappingOnTargetCreated, this);
13 | oRouter.initialize();
14 | },
15 | /**
16 | * This function is attached to the 'created' event from the target cache of a router.
17 | *
18 | * Once a component target is created, this function is called. Within this function,
19 | * the 'eventMappings' property which is defined in the subclass component is processed.
20 | * To each of the events defined within a target under 'eventMappings', a handler is
21 | * attached. The handler calls the 'navTo' method on the current router by providing
22 | * the route information and the information for the component targets within this route.
23 | *
24 | * With this mechanism, a nested component can fire specific events to inform the parent
25 | * component that:
26 | *
27 | * A navigation needs to be done with the router in the parent component.
28 | * The event needs to be forwarded along the parent chain with the same parameter
29 | *
30 | *
31 | * @private
32 | * @param {object} oEvent The event object which is provided by the 'created' event from
33 | * router's target cache
34 | */
35 | _processEventMappingOnTargetCreated(oEvent) {
36 | if (!this.eventMappings) {
37 | return;
38 | }
39 |
40 | const sType = oEvent.getParameter("type"),
41 | oObject = oEvent.getParameter("object"),
42 | oOptions = oEvent.getParameter("options"),
43 | that = this,
44 | processComponentTargetInfo = (oComponentTargetInfo, oEv) => {
45 | Object.keys(oComponentTargetInfo).forEach((sTargetName) => {
46 | const oInfo = oComponentTargetInfo[sTargetName];
47 |
48 | if (oInfo.parameters) {
49 | Object.keys(oInfo.parameters).forEach((sName) => {
50 | const sParamName = oInfo.parameters[sName],
51 | sEventValue = oEv.getParameter(sParamName);
52 |
53 | /*
54 | * Expand the parameter mapping with the parameter value from
55 | * the event
56 | */
57 | oInfo.parameters[sName] = sEventValue;
58 | });
59 | }
60 |
61 | if (oInfo.componentTargetInfo) {
62 | processComponentTargetInfo(oInfo.componentTargetInfo, oEv);
63 | }
64 | });
65 | };
66 |
67 | if (sType === "Component") {
68 | const aEvents = this.eventMappings[oOptions.usage];
69 | if (Array.isArray(aEvents)) {
70 | aEvents.forEach((oEventMapping) => {
71 | oObject.attachEvent(oEventMapping.name, (oEv) => {
72 | let oComponentTargetInfo = {};
73 | if (oEventMapping.route) { // Route information defined, call 'navTo'
74 | if (oEventMapping.componentTargetInfo) {
75 | /*
76 | * If there's information for component target defined, replace the
77 | * event parameter mapping with the value from the event object
78 | */
79 | oComponentTargetInfo = deepClone(oEventMapping.componentTargetInfo);
80 | processComponentTargetInfo(oComponentTargetInfo, oEv);
81 | }
82 |
83 | that.getRouter().navTo(oEventMapping.route, {}, oComponentTargetInfo);
84 | } else if (oEventMapping.forward) { // Event should be forwarded with the same parameters
85 | that.fireEvent(oEventMapping.forward, oEv.getParameters());
86 | }
87 | });
88 | });
89 | }
90 | }
91 | }
92 | });
93 | });
94 |
--------------------------------------------------------------------------------
/demo/BaseComponent/src/my/lib/sample/base/library.js:
--------------------------------------------------------------------------------
1 | sap.ui.define(() => {
2 |
3 | "use strict";
4 |
5 | sap.ui.getCore().initLibrary({
6 | name : "my.lib.sample.base",
7 | // eslint-disable-next-line no-template-curly-in-string
8 | version : "${version}",
9 | noLibraryCSS: true,
10 | dependencies : [ "sap.ui.core" ],
11 | controls : [ ],
12 | types : [ ]
13 | });
14 | // eslint-disable-next-line no-undef
15 | return my.lib.sample.base;
16 | });
17 |
--------------------------------------------------------------------------------
/demo/BaseComponent/src/my/lib/sample/base/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "_version": "1.21.0",
3 | "sap.app": {
4 | "id": "my.lib.sample.base",
5 | "type": "library",
6 | "embeds": [],
7 | "applicationVersion": {
8 | "version": "${version}"
9 | },
10 | "title": "The my.lib.sample.base",
11 | "description": "The my.lib.sample.base",
12 | "offline": true
13 | },
14 | "sap.ui": {
15 | "technology": "UI5",
16 | "supportedThemes": [],
17 | "deviceTypes": {
18 | "desktop": true,
19 | "tablet": true,
20 | "phone": true
21 | }
22 | },
23 | "sap.ui5": {
24 | "contentDensities": {
25 | "cozy": true,
26 | "compact": true
27 | },
28 | "dependencies": {
29 | "minUI5Version": "1.75.0",
30 | "libs": {
31 | "sap.ui.core": {
32 | "minVersion": "1.75.0"
33 | }
34 | }
35 | },
36 | "library": {
37 | "i18n": false,
38 | "css": false,
39 | "content": {
40 | "controls": [],
41 | "elements": [],
42 | "types": [],
43 | "interfaces": []
44 | }
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/demo/BaseComponent/ui5.yaml:
--------------------------------------------------------------------------------
1 | specVersion: "2.6"
2 | metadata:
3 | name: my.lib.sample.base
4 | type: library
5 | framework:
6 | name: OpenUI5
7 | version: 1.136.0
8 | libraries:
9 | - name: sap.ui.core
10 | builder:
11 | componentPreload:
12 | namespaces:
13 | - "my/lib/sample/base"
14 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "my-lib-sample-categories-component",
3 | "private": true,
4 | "version": "0.0.1",
5 | "description": "This is the categories component",
6 | "scripts": {
7 | "start": "ui5 serve",
8 | "build": "ui5 build -a --clean-dest",
9 | "serve": "ws --compress -d dist",
10 | "test": "rimraf coverage && npm run karma-ci",
11 | "lint": "eslint src",
12 | "karma": "karma start",
13 | "karma-ci": "karma start karma-ci.conf.js"
14 | },
15 | "repository": {
16 | "type": "git",
17 | "url": "git@github.com:flovogt/ui5-nested-component-scenario.git"
18 | },
19 | "keywords": [
20 | "openui5",
21 | "sapui5",
22 | "ui5",
23 | "ui5con",
24 | "ui5-routing",
25 | "ui5-component"
26 | ],
27 | "dependencies": {
28 | "my-lib-sample-base-component": "^0.0.1",
29 | "my-lib-sample-products-component": "^0.0.1"
30 | },
31 | "devDependencies": {
32 | "eslint": "^9.25.0",
33 | "@ui5/cli": "^4.0.14",
34 | "local-web-server": "^5.4.0",
35 | "karma": "^6.4.4",
36 | "karma-coverage": "^2.2.1",
37 | "karma-chrome-launcher": "^3.2.0",
38 | "karma-ui5": "^4.1.0",
39 | "rimraf": "^6.0.1"
40 | },
41 | "engines": {
42 | "node": "^16.18.0 || >=18.12.0",
43 | "npm": ">= 8"
44 | },
45 | "author": "Jiawei Cao, Florian Vogt",
46 | "license": "Apache-2.0"
47 | }
48 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/Component.js:
--------------------------------------------------------------------------------
1 | sap.ui.define(["my/lib/sample/base/Component"], (Component) => {
2 | "use strict";
3 |
4 | return Component.extend("my.lib.sample.categories.Component", {
5 | metadata: {
6 | manifest: "json",
7 | interfaces: [
8 | "sap.ui.core.IAsyncContentCreation"
9 | ]
10 | },
11 | eventMappings: {
12 | productsComponent: [{
13 | name: "toProduct",
14 | forward: "toProduct"
15 | }]
16 | }
17 | });
18 | });
19 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/controller/App.controller.js:
--------------------------------------------------------------------------------
1 | sap.ui.define(["my/lib/sample/base/BaseController"], (BaseController) => {
2 | "use strict";
3 |
4 | return BaseController.extend("my.lib.sample.categories.controller.App", {
5 | });
6 | });
7 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/controller/Detail.controller.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "my/lib/sample/base/BaseController",
3 | "sap/base/Log"
4 | ], (BaseController, Log) => {
5 | "use strict";
6 | return BaseController.extend("my.lib.sample.categories.controller.Detail", {
7 |
8 | onInit(...args) {
9 | BaseController.prototype.onInit.apply(this, args);
10 | this.getOwnerComponent().getRouter().getRoute("detailRoute").attachMatched(this._onMatched, this);
11 | },
12 |
13 | _onMatched(oEvent) {
14 | Log.info(this.getView().getControllerName(), "_onMatched");
15 | const oArgs = oEvent.getParameter("arguments");
16 | this.getOwnerComponent().getModel().metadataLoaded().then(this._bindData.bind(this, oArgs.id));
17 | },
18 |
19 | _bindData(id) {
20 | Log.info(this.getView().getControllerName(), "_bindData");
21 | const sObjectPath = this.getOwnerComponent().getModel().createKey("Categories", { CategoryID: id }),
22 | that = this;
23 | this.getView().bindElement({
24 | path: "/"+ sObjectPath,
25 | events: {
26 | change() {
27 | Log.info(that.getView().getControllerName(), "_bindData change");
28 | that.getView().setBusy(false);
29 | },
30 | dataRequested() {
31 | Log.info(that.getView().getControllerName(), "_bindData dataRequested");
32 | that.getView().setBusy(true);
33 | },
34 | dataReceived() {
35 | Log.info(that.getView().getControllerName(), "_bindData dataReceived");
36 | that.getView().setBusy(false);
37 | if (that.getView().getBindingContext() === null) {
38 | that.getOwnerComponent().getRouter().getTargets().display("notFound");
39 | }
40 | }
41 | }
42 | });
43 | }
44 | });
45 | });
46 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/controller/List.controller.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "my/lib/sample/base/BaseController",
3 | "sap/base/Log"
4 | ], (Controller, Log) => {
5 | "use strict";
6 |
7 | return Controller.extend("my.lib.sample.categories.controller.List", {
8 | onPressListItem(oEvent) {
9 | Log.info(this.getView().getControllerName(), "onPressListItem");
10 |
11 | const oBindingContext = oEvent.getSource().getBindingContext();
12 |
13 | /*
14 | * Navigate to the detail page. Because the products component is
15 | * integrated in the detail page, it's also needed to provide route
16 | * information for the deeply nested products component
17 | */
18 | this.getOwnerComponent()
19 | .getRouter()
20 | .navTo("detailRoute", {
21 | id: oBindingContext.getProperty("CategoryID")
22 | }, {
23 | productsTarget: {
24 | route: "listRoute",
25 | parameters: {
26 | /*
27 | * Encode the path because it could contain "/" which
28 | * isn't allowed to use as pattern parameter directly
29 | */
30 | basepath: encodeURIComponent(oBindingContext.getPath())
31 | }
32 | }
33 | });
34 | }
35 | });
36 | });
37 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/css/style.css:
--------------------------------------------------------------------------------
1 | .categoriesPage {
2 | background-color: aquamarine;
3 | }
4 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/i18n/i18n.properties:
--------------------------------------------------------------------------------
1 | appTitle=Category Component
2 | appDescription=Category Reusable Component
3 |
4 | listViewTitle=Categories
5 | detailViewTitle=Category Detail
6 | productListTitle=Products in this Category
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/localService/metadata.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/localService/mockdata/Products.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "ProductID": 1,
4 | "ProductName": "UI5 T-Shirt",
5 | "SupplierID": 1,
6 | "CategoryID": 1,
7 | "QuantityPerUnit": "1 shirt x 1 bag",
8 | "UnitPrice": "19.9900",
9 | "UnitsInStock": 10,
10 | "UnitsOnOrder": 12,
11 | "ReorderLevel": 1,
12 | "Discontinued": false
13 | },
14 | {
15 | "ProductID": 2,
16 | "ProductName": "UI5 Snapback Cap",
17 | "SupplierID": 2,
18 | "CategoryID": 4,
19 | "QuantityPerUnit": "1 cap x 1 bag",
20 | "UnitPrice": "9.9900",
21 | "UnitsInStock": 11,
22 | "UnitsOnOrder": 12,
23 | "ReorderLevel": 1,
24 | "Discontinued": false
25 | },
26 | {
27 | "ProductID": 3,
28 | "ProductName": "UI5 Unisex Two-Tone Hoodie",
29 | "SupplierID": 1,
30 | "CategoryID": 2,
31 | "QuantityPerUnit": "1 hoddie x 1 bag",
32 | "UnitPrice": "45.9900",
33 | "UnitsInStock": 20,
34 | "UnitsOnOrder": 12,
35 | "ReorderLevel": 1,
36 | "Discontinued": false
37 | },
38 | {
39 | "ProductID": 4,
40 | "ProductName": "UI5 Men's Pique Polo Shirt",
41 | "SupplierID": 2,
42 | "CategoryID": 1,
43 | "QuantityPerUnit": "1 shirt x 1 bag",
44 | "UnitPrice": "29.9900",
45 | "UnitsInStock": 5,
46 | "UnitsOnOrder": 12,
47 | "ReorderLevel": 1,
48 | "Discontinued": false
49 | },
50 | {
51 | "ProductID": 5,
52 | "ProductName": "UI5 Jersey",
53 | "SupplierID": 1,
54 | "CategoryID": 2,
55 | "QuantityPerUnit": "1 jersey x 1 bag",
56 | "UnitPrice": "26.4900",
57 | "UnitsInStock": 2,
58 | "UnitsOnOrder": 12,
59 | "ReorderLevel": 1,
60 | "Discontinued": false
61 | },
62 | {
63 | "ProductID": 6,
64 | "ProductName": "UI5 Women's Flowy Tank Top",
65 | "SupplierID": 3,
66 | "CategoryID": 1,
67 | "QuantityPerUnit": "1 tank top x 1 bag",
68 | "UnitPrice": "14.9900",
69 | "UnitsInStock": 39,
70 | "UnitsOnOrder": 12,
71 | "ReorderLevel": 1,
72 | "Discontinued": false
73 | },
74 | {
75 | "ProductID": 7,
76 | "ProductName": "UI5 Women's Vintage Sport T-Shirt",
77 | "SupplierID": 1,
78 | "CategoryID": 1,
79 | "QuantityPerUnit": "1 shirt x 1 bag",
80 | "UnitPrice": "11.9900",
81 | "UnitsInStock": 45,
82 | "UnitsOnOrder": 12,
83 | "ReorderLevel": 1,
84 | "Discontinued": false
85 | },
86 | {
87 | "ProductID": 8,
88 | "ProductName": "UI5 Women's Tri-Blend V-Neck T-Shirt",
89 | "SupplierID": 2,
90 | "CategoryID": 1,
91 | "QuantityPerUnit": "1 shirt x 1 bag",
92 | "UnitPrice": "21.9900",
93 | "UnitsInStock": 102,
94 | "UnitsOnOrder": 12,
95 | "ReorderLevel": 1,
96 | "Discontinued": false
97 | },
98 | {
99 | "ProductID": 9,
100 | "ProductName": "UI5 Phone Case",
101 | "SupplierID": 3,
102 | "CategoryID": 4,
103 | "QuantityPerUnit": "1 phone case x 1 bag",
104 | "UnitPrice": "7.9900",
105 | "UnitsInStock": 87,
106 | "UnitsOnOrder": 12,
107 | "ReorderLevel": 1,
108 | "Discontinued": false
109 | },
110 | {
111 | "ProductID": 10,
112 | "ProductName": "UI5 Enamel Mug",
113 | "SupplierID": 2,
114 | "CategoryID": 3,
115 | "QuantityPerUnit": "1 mug x 1 bag",
116 | "UnitPrice": "19.9900",
117 | "UnitsInStock": 8,
118 | "UnitsOnOrder": 12,
119 | "ReorderLevel": 1,
120 | "Discontinued": false
121 | },
122 | {
123 | "ProductID": 11,
124 | "ProductName": "UI5 Cotton Drawstring Bag",
125 | "SupplierID": 3,
126 | "CategoryID": 4,
127 | "QuantityPerUnit": "1 bag x 1 bag",
128 | "UnitPrice": "24.9900",
129 | "UnitsInStock": 3,
130 | "UnitsOnOrder": 12,
131 | "ReorderLevel": 1,
132 | "Discontinued": false
133 | },
134 | {
135 | "ProductID": 11,
136 | "ProductName": "UI5 Sweatshirt Drawstring Bag",
137 | "SupplierID": 2,
138 | "CategoryID": 4,
139 | "QuantityPerUnit": "1 shirt x 1 bag",
140 | "UnitPrice": "15.9900",
141 | "UnitsInStock": 10,
142 | "UnitsOnOrder": 12,
143 | "ReorderLevel": 1,
144 | "Discontinued": false
145 | },
146 | {
147 | "ProductID": 12,
148 | "ProductName": "UI5 Pillow Dark",
149 | "SupplierID": 3,
150 | "CategoryID": 3,
151 | "QuantityPerUnit": "1 pillow x 1 bag",
152 | "UnitPrice": "29.9900",
153 | "UnitsInStock": 43,
154 | "UnitsOnOrder": 12,
155 | "ReorderLevel": 1,
156 | "Discontinued": false
157 | }
158 | ]
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/localService/mockdata/Suppliers.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "SupplierID": 1,
4 | "CompanyName": "UI5 Awesome Manufactor Company Inc.",
5 | "ContactName": "Amanda Miller",
6 | "ContactTitle": "Purchasing Manager",
7 | "Address": "Westminster",
8 | "City": "London",
9 | "Region": "City of London",
10 | "PostalCode": "SW1A 0AA",
11 | "Country": "United Kingdom of Great Britain and Northern Ireland (the)",
12 | "Phone": "(171) 555-2222",
13 | "Fax": null,
14 | "HomePage": null
15 | },
16 | {
17 | "SupplierID": 2,
18 | "CompanyName": "UI5 Amazing Manufactor SE",
19 | "ContactName": "Peter Schmidt",
20 | "ContactTitle": "Purchasing Manager",
21 | "Address": "Unter den Linden 1",
22 | "City": "Berlin",
23 | "Region": "Berlin",
24 | "PostalCode": "10243",
25 | "Country": "Germany",
26 | "Phone": "(171) 555-2222",
27 | "Fax": null,
28 | "HomePage": null
29 | },
30 | {
31 | "SupplierID": 3,
32 | "CompanyName": "UI5 Wonderful Manufactor Limited",
33 | "ContactName": "Jasneet Kumar",
34 | "ContactTitle": "Purchasing Manager",
35 | "Address": "#138, EPIP Zone",
36 | "City": "Bengaluru",
37 | "Region": "Bayaluseemé",
38 | "PostalCode": "560 066 ",
39 | "Country": "India",
40 | "Phone": "(171) 555-2222",
41 | "Fax": null,
42 | "HomePage": null
43 | }
44 | ]
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/localService/mockserver.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "sap/ui/core/util/MockServer",
3 | "sap/ui/model/json/JSONModel",
4 | "sap/base/Log",
5 | "sap/base/util/UriParameters"
6 | ], (MockServer, JSONModel, Log, UriParameters) => {
7 | "use strict";
8 |
9 |
10 | // eslint-disable-next-line init-declarations
11 | let oMockServer;
12 |
13 | const sAppPath = "my/lib/sample/categories/",
14 | sJsonFilesPath = `${sAppPath }localService/mockdata`,
15 | oMockServerInterface = {
16 |
17 | /**
18 | * Initializes the mock server asynchronously.
19 | * You can configure the delay with the URL parameter "serverDelay".
20 | * The local mock data in this folder is returned instead of the real data for testing.
21 | * @protected
22 | * @param {object} [oOptionsParameter] init parameters for the mockserver
23 | * @returns{Promise} a promise that is resolved when the mock server has been started
24 | */
25 | init (oOptionsParameter) {
26 | const oOptions = oOptionsParameter || {};
27 |
28 | return new Promise((fnResolve, fnReject) => {
29 | const sManifestUrl = sap.ui.require.toUrl(`${sAppPath }manifest.json`),
30 | oManifestModel = new JSONModel(sManifestUrl);
31 |
32 | oManifestModel.attachRequestCompleted(() => {
33 | const oUriParameters = new UriParameters(window.location.href),
34 | // Parse manifest for local metadata URI
35 | sJsonFilesUrl = sap.ui.require.toUrl(sJsonFilesPath),
36 | oMainDataSource = oManifestModel.getProperty("/sap.app/dataSources/mainService"),
37 | sMetadataUrl = sap.ui.require.toUrl(sAppPath + oMainDataSource.settings.localUri),
38 | // Ensure there is a trailing slash
39 | sMockServerUrl = /.*\/$/u.test(oMainDataSource.uri) ? oMainDataSource.uri : `${oMainDataSource.uri }/`;
40 |
41 | // Create a mock server instance or stop the existing one to reinitialize
42 | if (!oMockServer) {
43 | oMockServer = new MockServer({
44 | rootUri: sMockServerUrl
45 | });
46 | } else {
47 | oMockServer.stop();
48 | }
49 |
50 | // Configure mock server with the given options or a default delay of 0.5s
51 | MockServer.config({
52 | autoRespond : true,
53 | autoRespondAfter : (oOptions.delay || oUriParameters.get("serverDelay") || 500)
54 | });
55 |
56 | // Simulate all requests using mock data
57 | oMockServer.simulate(sMetadataUrl, {
58 | sMockdataBaseUrl : sJsonFilesUrl,
59 | bGenerateMissingMockData : true
60 | });
61 |
62 | const aRequests = oMockServer.getRequests(),
63 |
64 | // Compose an error response for each request
65 | fnResponse = (iErrCode, sMessage, aRequest) => {
66 | aRequest.response = (oXhr) => {
67 | oXhr.respond(iErrCode, {"Content-Type": "text/plain;charset=utf-8"}, sMessage);
68 | };
69 | };
70 |
71 | // Simulate metadata errors
72 | if (oOptions.metadataError || oUriParameters.get("metadataError")) {
73 | aRequests.forEach((aEntry) => {
74 | if (aEntry.path.toString().indexOf("$metadata") > -1) {
75 | fnResponse(500, "metadata Error", aEntry);
76 | }
77 | });
78 | }
79 |
80 | // Simulate request errors
81 | const sErrorParam = oOptions.errorType || oUriParameters.get("errorType"),
82 | iErrorCode = sErrorParam === "badRequest" ? 400 : 500;
83 | if (sErrorParam) {
84 | aRequests.forEach((aEntry) => {
85 | fnResponse(iErrorCode, sErrorParam, aEntry);
86 | });
87 | }
88 |
89 | // Custom mock behaviour may be added here
90 |
91 | // Set requests and start the server
92 | oMockServer.setRequests(aRequests);
93 | oMockServer.start();
94 |
95 | Log.info("Running the app with mock data");
96 | fnResolve();
97 | });
98 |
99 | oManifestModel.attachRequestFailed(() => {
100 | const sError = "Failed to load application manifest";
101 |
102 | Log.error(sError);
103 | fnReject(new Error(sError));
104 | });
105 | });
106 | },
107 |
108 | /**
109 | * @public returns the mockserver of the app, should be used in integration tests
110 | * @returns {sap.ui.core.util.MockServer} the mockserver instance
111 | */
112 | getMockServer () {
113 | return oMockServer;
114 | }
115 | };
116 |
117 | return oMockServerInterface;
118 | });
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "_version": "1.21.0",
3 | "sap.app": {
4 | "id": "my.lib.sample.categories",
5 | "type": "application",
6 | "i18n": {
7 | "bundleUrl": "i18n/i18n.properties",
8 | "supportedLocales": [
9 | ""
10 | ],
11 | "fallbackLocale": ""
12 | },
13 | "title": "{{appTitle}}",
14 | "description": "{{appDescription}}",
15 | "applicationVersion": {
16 | "version": "1.0.0"
17 | },
18 | "dataSources": {
19 | "mainService": {
20 | "uri": "/myservice/V2/Northwind.svc",
21 | "type": "OData",
22 | "settings": {
23 | "odataVersion": "2.0",
24 | "localUri": "localService/metadata.xml"
25 | }
26 | }
27 | }
28 | },
29 | "sap.ui": {
30 | "technology": "UI5",
31 | "deviceTypes": {
32 | "desktop": true,
33 | "tablet": true,
34 | "phone": true
35 | }
36 | },
37 | "sap.ui5": {
38 | "contentDensities": {
39 | "cozy": true,
40 | "compact": true
41 | },
42 | "rootView": {
43 | "viewName": "my.lib.sample.categories.view.App",
44 | "type": "XML",
45 | "id": "app"
46 | },
47 | "componentUsages": {
48 | "productsComponent": {
49 | "name": "my.lib.sample.products",
50 | "settings": {},
51 | "componentData": {},
52 | "lazy": true
53 | }
54 | },
55 | "dependencies": {
56 | "minUI5Version": "1.75.0",
57 | "libs": {
58 | "sap.ui.core": {},
59 | "sap.ui.layout": {},
60 | "sap.m": {}
61 | },
62 | "components": {
63 | "my.lib.sample.base": {}
64 | }
65 | },
66 | "models": {
67 | "i18n": {
68 | "type": "sap.ui.model.resource.ResourceModel",
69 | "settings": {
70 | "bundleName": "my.lib.sample.categories.i18n.i18n",
71 | "supportedLocales": [
72 | ""
73 | ],
74 | "fallbackLocale": ""
75 | }
76 | },
77 | "": {
78 | "dataSource": "mainService",
79 | "preload": true,
80 | "settings": {
81 | "useBatch": false,
82 | "defaultCountMode": "Inline",
83 | "defaultBindingMode": "TwoWay"
84 | }
85 | }
86 | },
87 | "resources": {
88 | "css": [
89 | {
90 | "uri": "css/style.css"
91 | }
92 | ]
93 | },
94 | "routing": {
95 | "config": {
96 | "routerClass": "sap.m.routing.Router",
97 | "viewType": "XML",
98 | "path": "my.lib.sample.categories.view",
99 | "controlId": "app",
100 | "controlAggregation": "pages",
101 | "transition": "slide",
102 | "bypassed": {
103 | "target": "notFoundTarget"
104 | }
105 | },
106 | "routes": [
107 | {
108 | "name": "listRoute",
109 | "pattern": "",
110 | "target": "listTarget"
111 | },
112 | {
113 | "name": "detailRoute",
114 | "pattern": "detail/{id}",
115 | "target": {
116 | "name": "productsTarget",
117 | "prefix": "p"
118 | }
119 | }
120 | ],
121 | "targets": {
122 | "listTarget": {
123 | "type": "View",
124 | "id": "list",
125 | "name": "List",
126 | "title": "Category List"
127 | },
128 | "detailTarget": {
129 | "type": "View",
130 | "id": "detail",
131 | "name": "Detail",
132 | "title": "{CategoryName}"
133 | },
134 | "productsTarget": {
135 | "type": "Component",
136 | "usage": "productsComponent",
137 | "parent": "detailTarget",
138 | "controlId": "box",
139 | "controlAggregation": "items",
140 | "id": "productInCategory"
141 | },
142 | "notFoundTarget": {
143 | "type": "View",
144 | "id": "notFound",
145 | "name": "NotFound",
146 | "transition": "show"
147 | }
148 | }
149 | }
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/test/initMockServer.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "../localService/mockserver"
3 | ], (mockserver) => {
4 | "use strict";
5 |
6 | const aMockservers = [];
7 |
8 | // Initialize the mock server
9 | aMockservers.push(mockserver.init());
10 |
11 | Promise.all(aMockservers).catch(async (oError) => {
12 | await sap.ui.getCore().loadLibrary("sap.m", { async: true });
13 | sap.ui.require(["sap/m/MessageBox"], (MessageBox) => {
14 | MessageBox.error(oError.message);
15 | });
16 | }).finally(() => {
17 | // Initialize the embedded component on the HTML page
18 | sap.ui.require(["sap/ui/core/ComponentSupport"]);
19 | });
20 | });
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/test/mockServer.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Component Based Navigation
7 |
8 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/view/App.view.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/view/Detail.view.xml:
--------------------------------------------------------------------------------
1 |
9 |
14 |
15 |
17 |
18 |
19 |
20 |
21 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/view/List.view.xml:
--------------------------------------------------------------------------------
1 |
5 |
9 |
12 |
13 |
14 |
15 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/src/my/lib/sample/categories/view/NotFound.view.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/demo/CategoriesComponent/ui5.yaml:
--------------------------------------------------------------------------------
1 | specVersion: "2.6"
2 | metadata:
3 | name: my.lib.sample.categories
4 | type: library
5 | framework:
6 | name: OpenUI5
7 | version: 1.136.0
8 | libraries:
9 | - name: sap.ui.core
10 | - name: sap.m
11 | - name: themelib_sap_horizon
12 | builder:
13 | componentPreload:
14 | namespaces:
15 | - "my/lib/sample/categories"
--------------------------------------------------------------------------------
/demo/ProductsComponent/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "my-lib-sample-products-component",
3 | "private": true,
4 | "version": "0.0.1",
5 | "description": "This is the products component",
6 | "scripts": {
7 | "start": "ui5 serve",
8 | "build": "ui5 build -a --clean-dest",
9 | "serve": "ws --compress -d dist",
10 | "test": "rimraf coverage && npm run karma-ci",
11 | "lint": "eslint src",
12 | "karma": "karma start",
13 | "karma-ci": "karma start karma-ci.conf.js"
14 | },
15 | "repository": {
16 | "type": "git",
17 | "url": "git@github.com:flovogt/ui5-nested-component-scenario.git"
18 | },
19 | "keywords": [
20 | "openui5",
21 | "sapui5",
22 | "ui5",
23 | "ui5con",
24 | "ui5-routing",
25 | "ui5-component"
26 | ],
27 | "dependencies": {
28 | "my-lib-sample-base-component": "^0.0.1"
29 | },
30 | "devDependencies": {
31 | "eslint": "^9.25.0",
32 | "@ui5/cli": "^4.0.14",
33 | "local-web-server": "^5.4.0",
34 | "karma": "^6.4.4",
35 | "karma-coverage": "^2.2.1",
36 | "karma-chrome-launcher": "^3.2.0",
37 | "karma-ui5": "^4.1.0",
38 | "rimraf": "^6.0.1"
39 | },
40 | "engines": {
41 | "node": "^16.18.0 || >=18.12.0",
42 | "npm": ">= 8"
43 | },
44 | "author": "Jiawei Cao, Florian Vogt",
45 | "license": "Apache-2.0"
46 | }
47 |
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/Component.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "my/lib/sample/base/Component",
3 | "sap/ui/core/Component"
4 | ], (BaseComponent, Component) => {
5 | "use strict";
6 | return BaseComponent.extend("my.lib.sample.products.Component", {
7 | metadata: {
8 | manifest: "json",
9 | interfaces: [
10 | "sap.ui.core.IAsyncContentCreation"
11 | ]
12 | },
13 | init(...args) {
14 | BaseComponent.prototype.init.apply(this, args);
15 |
16 | const oParentComponent = Component.getOwnerComponentFor(this);
17 |
18 | /*
19 | * If this component runs standalone instead of embedded to another component,
20 | * it should handle the navigation to detail page by itself. It attaches to
21 | * its own "toProduct" event and navigates to the detail page
22 | */
23 | if (!oParentComponent) {
24 | this.attachEvent("toProduct", (oEvent) => {
25 | const sProductID = oEvent.getParameter("productID");
26 | this.getRouter().navTo("detailRoute", {
27 | id: sProductID
28 | });
29 | }, this);
30 | }
31 | }
32 | });
33 | });
34 |
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/controller/App.controller.js:
--------------------------------------------------------------------------------
1 | sap.ui.define(["sap/ui/core/mvc/Controller"], (Controller) => {
2 | "use strict";
3 | return Controller.extend("my.lib.sample.products.controller.App", {
4 | });
5 | });
6 |
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/controller/Detail.controller.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "my/lib/sample/base/BaseController",
3 | "sap/base/Log"
4 | ], (BaseController, Log) => {
5 | "use strict";
6 | return BaseController.extend("my.lib.sample.products.controller.Detail", {
7 |
8 | onInit(...args) {
9 | BaseController.prototype.onInit.apply(this, args);
10 | this.getOwnerComponent().getRouter().getRoute("detailRoute").attachPatternMatched(this._onMatched, this);
11 | },
12 |
13 | _onMatched(oEvent) {
14 | Log.info(this.getView().getControllerName(), "_onMatched");
15 | const oArgs = oEvent.getParameter("arguments");
16 | this.getOwnerComponent().getModel().metadataLoaded().then(this._bindData.bind(this, oArgs.id));
17 | },
18 |
19 | _bindData(id) {
20 | Log.info(this.getView().getControllerName(), "_bindData");
21 |
22 | const sObjectPath = this.getOwnerComponent().getModel().createKey("Products", { ProductID: id }),
23 | that = this;
24 |
25 | this.getView().bindElement({
26 | path: "/"+ sObjectPath,
27 | parameters: {
28 | expand: "Supplier,Category"
29 | },
30 | events: {
31 | change() {
32 | Log.info(that.getView().getControllerName(), "_bindData change");
33 | that.getView().setBusy(false);
34 | },
35 | dataRequested() {
36 | Log.info(that.getView().getControllerName(), "_bindData dataRequested");
37 | that.getView().setBusy(true);
38 | },
39 | dataReceived() {
40 | Log.info(that.getView().getControllerName(), "_bindData dataReceived");
41 | that.getView().setBusy(false);
42 | if (that.getView().getBindingContext() === null) {
43 | that.getOwnerComponent().getRouter().getTargets().display("notFound");
44 | }
45 | }
46 | }
47 | });
48 | },
49 |
50 | onPressSupplier(oEvent) {
51 | Log.info(this.getView().getControllerName(), `onPressSupplier ${ oEvent.getSource().getBindingContext().getObject().SupplierID}`);
52 |
53 | const oOwnerComponent = this.getOwnerComponent(),
54 | oModel = oOwnerComponent.getModel(),
55 | oBindingContext = oEvent.getSource().getBindingContext(),
56 | sSupplierID = oBindingContext.getProperty("SupplierID");
57 |
58 | oOwnerComponent.fireEvent("toSupplier", {
59 | supplierID: sSupplierID,
60 | supplierKey: encodeURIComponent(`/${ oModel.createKey("Suppliers", {
61 | SupplierID: sSupplierID
62 | })}`)
63 | });
64 | },
65 |
66 | onPressCategory(oEvent) {
67 | Log.info(this.getView().getControllerName(), `onPressCategory ${ oEvent.getSource().getBindingContext().getObject().CategoryID}`);
68 |
69 | const oOwnerComponent = this.getOwnerComponent(),
70 | oModel = oOwnerComponent.getModel(),
71 | oBindingContext = oEvent.getSource().getBindingContext(),
72 | sCategoryID = oBindingContext.getProperty("CategoryID");
73 |
74 | oOwnerComponent.fireEvent("toCategory", {
75 | categoryID: sCategoryID,
76 | categoryKey: encodeURIComponent(`/${ oModel.createKey("Categories", {
77 | CategoryID: sCategoryID
78 | })}`)
79 | });
80 | }
81 | });
82 | });
83 |
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/controller/List.controller.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "my/lib/sample/base/BaseController",
3 | "sap/m/ColumnListItem",
4 | "sap/m/Text",
5 | "sap/base/Log",
6 | "sap/ui/model/type/Currency"
7 | ], (BaseController, ColumnListItem, Text, Log, Currency) => {
8 | "use strict";
9 |
10 | return BaseController.extend("my.lib.sample.products.controller.List", {
11 |
12 | onInit(...args) {
13 | BaseController.prototype.onInit.apply(this, args);
14 | this.getOwnerComponent().getRouter().getRoute("listRoute").attachMatched(this._onMatched, this);
15 | },
16 |
17 | _onMatched(oEvent) {
18 | const oArgs = oEvent.getParameter("arguments"),
19 | sPath = `${decodeURIComponent(oArgs.basepath || "") }/Products`,
20 | oTable = this.getView().byId("table"),
21 | that = this;
22 |
23 | oTable.bindItems({
24 | path: sPath,
25 | parameters: {
26 | expand: "Supplier"
27 | },
28 | template: new ColumnListItem({
29 | type: "Navigation",
30 | press: that.onPressListItem.bind(that),
31 | cells: [
32 | new Text({ text: "{ProductID}" }),
33 | new Text({ text: "{ProductName}" }),
34 | new Text({ text: "{Supplier/CompanyName}" }),
35 | new Text({ text: {
36 | parts: [{
37 | path: "UnitPrice"
38 | }, {
39 | value: "$"
40 | }],
41 | type: new Currency({
42 | currencyCode: false
43 | })
44 | } })
45 | ]
46 | })
47 | });
48 | },
49 |
50 | onPressListItem(oEvent) {
51 | Log.info(this.getView().getControllerName(), "onPressListItem");
52 |
53 | const sProductID = oEvent.getSource().getBindingContext().getProperty("ProductID");
54 |
55 | /*
56 | * Inform the parent component about the navigation to the detail page
57 | *
58 | * the navigation isn't done within this component because when this component is embedded
59 | * in suppliers/categories component, it should trigger the navigation within the root
60 | * component.
61 | *
62 | * simply always inform the parent component that a navigation to the detail page is needed.
63 | * In the deeply nested use case, the direct parent component forwards this event to the root
64 | * component and a navigation is then triggered from the root component
65 | */
66 | this.getOwnerComponent().fireEvent("toProduct", {
67 | productID: sProductID
68 | });
69 | }
70 | });
71 | });
72 |
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/css/style.css:
--------------------------------------------------------------------------------
1 | .productsPage {
2 | background-color: lightblue;
3 | }
4 |
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/i18n/i18n.properties:
--------------------------------------------------------------------------------
1 | appTitle=Product Component
2 | appDescription=Product Reusable Component
3 |
4 | listViewTitle=Product List View
5 | detailViewTitle=Product Detail View
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/localService/metadata.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/localService/mockdata/Products.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "ProductID": 1,
4 | "ProductName": "UI5 T-Shirt",
5 | "SupplierID": 1,
6 | "CategoryID": 1,
7 | "QuantityPerUnit": "1 shirt x 1 bag",
8 | "UnitPrice": "19.9900",
9 | "UnitsInStock": 10,
10 | "UnitsOnOrder": 12,
11 | "ReorderLevel": 1,
12 | "Discontinued": false
13 | },
14 | {
15 | "ProductID": 2,
16 | "ProductName": "UI5 Snapback Cap",
17 | "SupplierID": 2,
18 | "CategoryID": 4,
19 | "QuantityPerUnit": "1 cap x 1 bag",
20 | "UnitPrice": "9.9900",
21 | "UnitsInStock": 11,
22 | "UnitsOnOrder": 12,
23 | "ReorderLevel": 1,
24 | "Discontinued": false
25 | },
26 | {
27 | "ProductID": 3,
28 | "ProductName": "UI5 Unisex Two-Tone Hoodie",
29 | "SupplierID": 1,
30 | "CategoryID": 2,
31 | "QuantityPerUnit": "1 hoddie x 1 bag",
32 | "UnitPrice": "45.9900",
33 | "UnitsInStock": 20,
34 | "UnitsOnOrder": 12,
35 | "ReorderLevel": 1,
36 | "Discontinued": false
37 | },
38 | {
39 | "ProductID": 4,
40 | "ProductName": "UI5 Men's Pique Polo Shirt",
41 | "SupplierID": 2,
42 | "CategoryID": 1,
43 | "QuantityPerUnit": "1 shirt x 1 bag",
44 | "UnitPrice": "29.9900",
45 | "UnitsInStock": 5,
46 | "UnitsOnOrder": 12,
47 | "ReorderLevel": 1,
48 | "Discontinued": false
49 | },
50 | {
51 | "ProductID": 5,
52 | "ProductName": "UI5 Jersey",
53 | "SupplierID": 1,
54 | "CategoryID": 2,
55 | "QuantityPerUnit": "1 jersey x 1 bag",
56 | "UnitPrice": "26.4900",
57 | "UnitsInStock": 2,
58 | "UnitsOnOrder": 12,
59 | "ReorderLevel": 1,
60 | "Discontinued": false
61 | },
62 | {
63 | "ProductID": 6,
64 | "ProductName": "UI5 Women's Flowy Tank Top",
65 | "SupplierID": 3,
66 | "CategoryID": 1,
67 | "QuantityPerUnit": "1 tank top x 1 bag",
68 | "UnitPrice": "14.9900",
69 | "UnitsInStock": 39,
70 | "UnitsOnOrder": 12,
71 | "ReorderLevel": 1,
72 | "Discontinued": false
73 | },
74 | {
75 | "ProductID": 7,
76 | "ProductName": "UI5 Women's Vintage Sport T-Shirt",
77 | "SupplierID": 1,
78 | "CategoryID": 1,
79 | "QuantityPerUnit": "1 shirt x 1 bag",
80 | "UnitPrice": "11.9900",
81 | "UnitsInStock": 45,
82 | "UnitsOnOrder": 12,
83 | "ReorderLevel": 1,
84 | "Discontinued": false
85 | },
86 | {
87 | "ProductID": 8,
88 | "ProductName": "UI5 Women's Tri-Blend V-Neck T-Shirt",
89 | "SupplierID": 2,
90 | "CategoryID": 1,
91 | "QuantityPerUnit": "1 shirt x 1 bag",
92 | "UnitPrice": "21.9900",
93 | "UnitsInStock": 102,
94 | "UnitsOnOrder": 12,
95 | "ReorderLevel": 1,
96 | "Discontinued": false
97 | },
98 | {
99 | "ProductID": 9,
100 | "ProductName": "UI5 Phone Case",
101 | "SupplierID": 3,
102 | "CategoryID": 4,
103 | "QuantityPerUnit": "1 phone case x 1 bag",
104 | "UnitPrice": "7.9900",
105 | "UnitsInStock": 87,
106 | "UnitsOnOrder": 12,
107 | "ReorderLevel": 1,
108 | "Discontinued": false
109 | },
110 | {
111 | "ProductID": 10,
112 | "ProductName": "UI5 Enamel Mug",
113 | "SupplierID": 2,
114 | "CategoryID": 3,
115 | "QuantityPerUnit": "1 mug x 1 bag",
116 | "UnitPrice": "19.9900",
117 | "UnitsInStock": 8,
118 | "UnitsOnOrder": 12,
119 | "ReorderLevel": 1,
120 | "Discontinued": false
121 | },
122 | {
123 | "ProductID": 11,
124 | "ProductName": "UI5 Cotton Drawstring Bag",
125 | "SupplierID": 3,
126 | "CategoryID": 4,
127 | "QuantityPerUnit": "1 bag x 1 bag",
128 | "UnitPrice": "24.9900",
129 | "UnitsInStock": 3,
130 | "UnitsOnOrder": 12,
131 | "ReorderLevel": 1,
132 | "Discontinued": false
133 | },
134 | {
135 | "ProductID": 11,
136 | "ProductName": "UI5 Sweatshirt Drawstring Bag",
137 | "SupplierID": 2,
138 | "CategoryID": 4,
139 | "QuantityPerUnit": "1 shirt x 1 bag",
140 | "UnitPrice": "15.9900",
141 | "UnitsInStock": 10,
142 | "UnitsOnOrder": 12,
143 | "ReorderLevel": 1,
144 | "Discontinued": false
145 | },
146 | {
147 | "ProductID": 12,
148 | "ProductName": "UI5 Pillow Dark",
149 | "SupplierID": 3,
150 | "CategoryID": 3,
151 | "QuantityPerUnit": "1 pillow x 1 bag",
152 | "UnitPrice": "29.9900",
153 | "UnitsInStock": 43,
154 | "UnitsOnOrder": 12,
155 | "ReorderLevel": 1,
156 | "Discontinued": false
157 | }
158 | ]
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/localService/mockdata/Suppliers.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "SupplierID": 1,
4 | "CompanyName": "UI5 Awesome Manufactor Company Inc.",
5 | "ContactName": "Amanda Miller",
6 | "ContactTitle": "Purchasing Manager",
7 | "Address": "Westminster",
8 | "City": "London",
9 | "Region": "City of London",
10 | "PostalCode": "SW1A 0AA",
11 | "Country": "United Kingdom of Great Britain and Northern Ireland (the)",
12 | "Phone": "(171) 555-2222",
13 | "Fax": null,
14 | "HomePage": null
15 | },
16 | {
17 | "SupplierID": 2,
18 | "CompanyName": "UI5 Amazing Manufactor SE",
19 | "ContactName": "Peter Schmidt",
20 | "ContactTitle": "Purchasing Manager",
21 | "Address": "Unter den Linden 1",
22 | "City": "Berlin",
23 | "Region": "Berlin",
24 | "PostalCode": "10243",
25 | "Country": "Germany",
26 | "Phone": "(171) 555-2222",
27 | "Fax": null,
28 | "HomePage": null
29 | },
30 | {
31 | "SupplierID": 3,
32 | "CompanyName": "UI5 Wonderful Manufactor Limited",
33 | "ContactName": "Jasneet Kumar",
34 | "ContactTitle": "Purchasing Manager",
35 | "Address": "#138, EPIP Zone",
36 | "City": "Bengaluru",
37 | "Region": "Bayaluseemé",
38 | "PostalCode": "560 066 ",
39 | "Country": "India",
40 | "Phone": "(171) 555-2222",
41 | "Fax": null,
42 | "HomePage": null
43 | }
44 | ]
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/localService/mockserver.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "sap/ui/core/util/MockServer",
3 | "sap/ui/model/json/JSONModel",
4 | "sap/base/Log",
5 | "sap/base/util/UriParameters"
6 | ], (MockServer, JSONModel, Log, UriParameters) => {
7 | "use strict";
8 |
9 |
10 | // eslint-disable-next-line init-declarations
11 | let oMockServer;
12 |
13 | const sAppPath = "my/lib/sample/products/",
14 | sJsonFilesPath = `${sAppPath }localService/mockdata`,
15 | oMockServerInterface = {
16 |
17 | /**
18 | * Initializes the mock server asynchronously.
19 | * You can configure the delay with the URL parameter "serverDelay".
20 | * The local mock data in this folder is returned instead of the real data for testing.
21 | * @protected
22 | * @param {object} [oOptionsParameter] init parameters for the mockserver
23 | * @returns{Promise} a promise that is resolved when the mock server has been started
24 | */
25 | init (oOptionsParameter) {
26 | const oOptions = oOptionsParameter || {};
27 |
28 | return new Promise((fnResolve, fnReject) => {
29 | const sManifestUrl = sap.ui.require.toUrl(`${sAppPath }manifest.json`),
30 | oManifestModel = new JSONModel(sManifestUrl);
31 |
32 | oManifestModel.attachRequestCompleted(() => {
33 | const oUriParameters = new UriParameters(window.location.href),
34 | // Parse manifest for local metadata URI
35 | sJsonFilesUrl = sap.ui.require.toUrl(sJsonFilesPath),
36 | oMainDataSource = oManifestModel.getProperty("/sap.app/dataSources/mainService"),
37 | sMetadataUrl = sap.ui.require.toUrl(sAppPath + oMainDataSource.settings.localUri),
38 | // Ensure there is a trailing slash
39 | sMockServerUrl = /.*\/$/u.test(oMainDataSource.uri) ? oMainDataSource.uri : `${oMainDataSource.uri }/`;
40 |
41 | // Create a mock server instance or stop the existing one to reinitialize
42 | if (!oMockServer) {
43 | oMockServer = new MockServer({
44 | rootUri: sMockServerUrl
45 | });
46 | } else {
47 | oMockServer.stop();
48 | }
49 |
50 | // Configure mock server with the given options or a default delay of 0.5s
51 | MockServer.config({
52 | autoRespond : true,
53 | autoRespondAfter : (oOptions.delay || oUriParameters.get("serverDelay") || 500)
54 | });
55 |
56 | // Simulate all requests using mock data
57 | oMockServer.simulate(sMetadataUrl, {
58 | sMockdataBaseUrl : sJsonFilesUrl,
59 | bGenerateMissingMockData : true
60 | });
61 |
62 | const aRequests = oMockServer.getRequests(),
63 |
64 | // Compose an error response for each request
65 | fnResponse = (iErrCode, sMessage, aRequest) => {
66 | aRequest.response = (oXhr) => {
67 | oXhr.respond(iErrCode, {"Content-Type": "text/plain;charset=utf-8"}, sMessage);
68 | };
69 | };
70 |
71 | // Simulate metadata errors
72 | if (oOptions.metadataError || oUriParameters.get("metadataError")) {
73 | aRequests.forEach((aEntry) => {
74 | if (aEntry.path.toString().indexOf("$metadata") > -1) {
75 | fnResponse(500, "metadata Error", aEntry);
76 | }
77 | });
78 | }
79 |
80 | // Simulate request errors
81 | const sErrorParam = oOptions.errorType || oUriParameters.get("errorType"),
82 | iErrorCode = sErrorParam === "badRequest" ? 400 : 500;
83 | if (sErrorParam) {
84 | aRequests.forEach((aEntry) => {
85 | fnResponse(iErrorCode, sErrorParam, aEntry);
86 | });
87 | }
88 |
89 | // Custom mock behaviour may be added here
90 |
91 | // Set requests and start the server
92 | oMockServer.setRequests(aRequests);
93 | oMockServer.start();
94 |
95 | Log.info("Running the app with mock data");
96 | fnResolve();
97 | });
98 |
99 | oManifestModel.attachRequestFailed(() => {
100 | const sError = "Failed to load application manifest";
101 |
102 | Log.error(sError);
103 | fnReject(new Error(sError));
104 | });
105 | });
106 | },
107 |
108 | /**
109 | * @public returns the mockserver of the app, should be used in integration tests
110 | * @returns {sap.ui.core.util.MockServer} the mockserver instance
111 | */
112 | getMockServer () {
113 | return oMockServer;
114 | }
115 | };
116 |
117 | return oMockServerInterface;
118 | });
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "_version": "1.21.0",
3 | "sap.app": {
4 | "id": "my.lib.sample.products",
5 | "type": "application",
6 | "i18n": {
7 | "bundleUrl": "i18n/i18n.properties",
8 | "supportedLocales": [
9 | ""
10 | ],
11 | "fallbackLocale": ""
12 | },
13 | "title": "{{appTitle}}",
14 | "description": "{{appDescription}}",
15 | "applicationVersion": {
16 | "version": "1.0.0"
17 | },
18 | "dataSources": {
19 | "mainService": {
20 | "uri": "/myservice/V2/Northwind.svc",
21 | "type": "OData",
22 | "settings": {
23 | "odataVersion": "2.0",
24 | "localUri": "localService/metadata.xml"
25 | }
26 | }
27 | }
28 | },
29 | "sap.ui": {
30 | "technology": "UI5",
31 | "deviceTypes": {
32 | "desktop": true,
33 | "tablet": true,
34 | "phone": true
35 | }
36 | },
37 | "sap.ui5": {
38 | "contentDensities": {
39 | "cozy": true,
40 | "compact": true
41 | },
42 | "rootView": {
43 | "viewName": "my.lib.sample.products.view.App",
44 | "type": "XML",
45 | "id": "app"
46 | },
47 | "dependencies": {
48 | "minUI5Version": "1.75.0",
49 | "libs": {
50 | "sap.ui.core": {},
51 | "sap.ui.layout": {},
52 | "sap.m": {}
53 | },
54 | "components": {
55 | "my.lib.sample.base": {}
56 | }
57 | },
58 | "models": {
59 | "i18n": {
60 | "type": "sap.ui.model.resource.ResourceModel",
61 | "settings": {
62 | "bundleName": "my.lib.sample.products.i18n.i18n",
63 | "supportedLocales": [
64 | ""
65 | ],
66 | "fallbackLocale": ""
67 | }
68 | },
69 | "": {
70 | "dataSource": "mainService",
71 | "preload": true,
72 | "settings": {
73 | "useBatch": false,
74 | "defaultCountMode": "Inline",
75 | "defaultBindingMode": "TwoWay"
76 | }
77 | }
78 | },
79 | "resources": {
80 | "css": [
81 | {
82 | "uri": "css/style.css"
83 | }
84 | ]
85 | },
86 | "routing": {
87 | "config": {
88 | "routerClass": "sap.m.routing.Router",
89 | "viewType": "XML",
90 | "path": "my.lib.sample.products.view",
91 | "controlId": "app",
92 | "controlAggregation": "pages",
93 | "transition": "slide",
94 | "bypassed": {
95 | "target": "notFoundTarget"
96 | }
97 | },
98 | "routes": [
99 | {
100 | "name": "listRoute",
101 | "pattern": ":basepath:",
102 | "target": "listTarget"
103 | },
104 | {
105 | "name": "detailRoute",
106 | "pattern": "detail/{id}",
107 | "target": "detailTarget"
108 | }
109 | ],
110 | "targets": {
111 | "listTarget": {
112 | "type": "View",
113 | "id": "list",
114 | "name": "List",
115 | "title": "Products List"
116 | },
117 | "detailTarget": {
118 | "type": "View",
119 | "id": "detail",
120 | "name": "Detail",
121 | "title": "{ProductName}"
122 | },
123 | "notFoundTarget": {
124 | "type": "View",
125 | "id": "notFound",
126 | "name": "NotFound",
127 | "transition": "show"
128 | }
129 | }
130 | }
131 | }
132 | }
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/test/initMockServer.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "../localService/mockserver"
3 | ], (mockserver) => {
4 | "use strict";
5 |
6 | const aMockservers = [];
7 |
8 | // Initialize the mock server
9 | aMockservers.push(mockserver.init());
10 |
11 | Promise.all(aMockservers).catch(async (oError) => {
12 | await sap.ui.getCore().loadLibrary("sap.m", { async: true });
13 | sap.ui.require(["sap/m/MessageBox"], (MessageBox) => {
14 | MessageBox.error(oError.message);
15 | });
16 | }).finally(() => {
17 | // Initialize the embedded component on the HTML page
18 | sap.ui.require(["sap/ui/core/ComponentSupport"]);
19 | });
20 | });
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/test/mockServer.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Component Based Navigation
7 |
8 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/view/App.view.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/view/Detail.view.xml:
--------------------------------------------------------------------------------
1 |
10 |
15 |
16 |
18 |
19 |
20 |
21 |
22 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/view/List.view.xml:
--------------------------------------------------------------------------------
1 |
5 |
9 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/demo/ProductsComponent/src/my/lib/sample/products/view/NotFound.view.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/demo/ProductsComponent/ui5.yaml:
--------------------------------------------------------------------------------
1 | specVersion: "2.6"
2 | metadata:
3 | name: my.lib.sample.products
4 | type: library
5 | framework:
6 | name: OpenUI5
7 | version: 1.136.0
8 | libraries:
9 | - name: sap.ui.core
10 | - name: sap.m
11 | - name: themelib_sap_horizon
12 | builder:
13 | componentPreload:
14 | namespaces:
15 | - "my/lib/sample/products"
--------------------------------------------------------------------------------
/demo/README.md:
--------------------------------------------------------------------------------
1 | 
2 | 
3 | [](https://coveralls.io/github/flovogt/ui5-nested-component-scenario?branch=main)
4 |
5 |
6 | # ui5-nested-component-scenario - Demo
7 | This is the mono-repository setup of [UI5con 2020 UI5 Routing with Reusable Components](https://github.com/flovogt/ui5-nested-component-scenario/).
8 | If you wanna use a multi-repository setup, follow the instructions of [UI5 Root Component](https://github.com/flovogt/ui5-root-component).
9 |
10 | # Live Demo
11 | Just visit the [live demo](https://flovogt.github.io/ui5-nested-component-scenario/test/mockServer.html) to play with the application.
12 |
13 | # Local Deployment
14 | You wanna run the demo application on your machine? Here we go. The following steps will guide you through your local deployment.
15 |
16 | ## Getting started
17 | 1. Run `npm i` in the shell
18 |
19 | ## Development
20 | 1. Go to folder [RootComponent](RootComponent)
21 | 2. Run `npm start` to serve the application
22 |
23 | ## Testing
24 | Run `npm run test` to execute the test suite
25 |
26 | ## Building
27 | Run `npm run build` to build a bundle
28 |
29 | ## Deployment
30 | Run `npm run serve` to host a local webserver with the built application
31 |
--------------------------------------------------------------------------------
/demo/RootComponent/karma-ci.conf.js:
--------------------------------------------------------------------------------
1 | module.exports = function(config) {
2 | "use strict";
3 |
4 | require("./karma.conf")(config);
5 | config.set({
6 |
7 | preprocessors: {
8 | "{webapp,webapp/!(test|localService)}/*.js": ["coverage"]
9 | },
10 |
11 | coverageReporter: {
12 | includeAllSources: true,
13 | reporters: [
14 | {
15 | type: "html",
16 | subdir: "html",
17 | dir: "coverage"
18 | },
19 | {
20 | type: "text"
21 | },
22 | {
23 | type: "lcovonly",
24 | subdir: "lcov",
25 | file: "lcov.info"
26 | }
27 | ],
28 | check: {
29 | each: {
30 | statements: 100,
31 | branches: 100,
32 | functions: 100,
33 | lines: 100
34 | }
35 | }
36 | },
37 |
38 | reporters: ["progress", "coverage"],
39 |
40 | browsers: ["CustomChromeHeadless"],
41 |
42 | singleRun: true
43 |
44 | });
45 | };
--------------------------------------------------------------------------------
/demo/RootComponent/karma.conf.js:
--------------------------------------------------------------------------------
1 | module.exports = function(config) {
2 | "use strict";
3 |
4 | var chromeFlags = [
5 | "--window-size=1280,1024"
6 | ];
7 |
8 | config.set({
9 |
10 | frameworks: ["ui5"],
11 |
12 | browsers: ["CustomChrome"],
13 |
14 | browserConsoleLogOptions: {
15 | level: "info"
16 | },
17 |
18 | customLaunchers: {
19 | CustomChrome: {
20 | base: "Chrome",
21 | flags: chromeFlags
22 | },
23 | CustomChromeHeadless: {
24 | base: "ChromeHeadless",
25 | flags: chromeFlags
26 | }
27 | },
28 |
29 | });
30 | };
--------------------------------------------------------------------------------
/demo/RootComponent/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "my-lib-sample-root-component",
3 | "private": true,
4 | "version": "0.0.1",
5 | "description": "This is the root component including components",
6 | "scripts": {
7 | "start": "ui5 serve",
8 | "build": "ui5 build -a --clean-dest",
9 | "serve": "ws --compress -d dist",
10 | "test": "rimraf coverage && npm run karma-ci",
11 | "lint": "eslint webapp",
12 | "karma": "karma start",
13 | "karma-ci": "karma start karma-ci.conf.js"
14 | },
15 | "repository": {
16 | "type": "git",
17 | "url": "git@github.com:flovogt/ui5-nested-component-scenario.git"
18 | },
19 | "keywords": [
20 | "openui5",
21 | "sapui5",
22 | "ui5",
23 | "ui5con",
24 | "ui5-routing",
25 | "ui5-component"
26 | ],
27 | "dependencies": {
28 | "my-lib-sample-base-component": "^0.0.1",
29 | "my-lib-sample-suppliers-component": "^0.0.1",
30 | "my-lib-sample-categories-component": "^0.0.1",
31 | "my-lib-sample-products-component": "^0.0.1"
32 | },
33 | "devDependencies": {
34 | "eslint": "^9.25.0",
35 | "@ui5/cli": "^4.0.14",
36 | "local-web-server": "^5.4.0",
37 | "karma": "^6.4.4",
38 | "karma-coverage": "^2.2.1",
39 | "karma-chrome-launcher": "^3.2.0",
40 | "karma-ui5": "^4.1.0",
41 | "rimraf": "^6.0.1"
42 | },
43 | "engines": {
44 | "node": "^16.18.0 || >=18.12.0",
45 | "npm": ">= 8"
46 | },
47 | "author": "Jiawei Cao, Florian Vogt",
48 | "license": "Apache-2.0"
49 | }
50 |
--------------------------------------------------------------------------------
/demo/RootComponent/ui5.yaml:
--------------------------------------------------------------------------------
1 | specVersion: "2.6"
2 | metadata:
3 | name: RootComponent
4 | type: application
5 | framework:
6 | name: OpenUI5
7 | version: 1.136.0
8 | libraries:
9 | - name: sap.ui.core
10 | - name: sap.m
11 | - name: sap.tnt
12 | - name: themelib_sap_horizon
13 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/Component.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "my/lib/sample/base/Component"
3 | ], (Component) => {
4 | "use strict";
5 |
6 | return Component.extend("my.lib.sample.root.Component", {
7 | metadata: {
8 | manifest: "json",
9 | interfaces: [
10 | "sap.ui.core.IAsyncContentCreation"
11 | ]
12 | },
13 | /*
14 | * Define the events which are fired from the reuse components
15 | *
16 | * this component registers handler to those events and navigates
17 | * to the other reuse components
18 | *
19 | * see the implementation in Component for processing the event
20 | * mapping
21 | */
22 | eventMappings: {
23 | suppliersComponent: [{
24 | name: "toProduct",
25 | route: "productsRoute",
26 | componentTargetInfo: {
27 | productsTarget: {
28 | route: "detailRoute",
29 | parameters: {
30 | id: "productID"
31 | }
32 | }
33 | }
34 | }],
35 | productsComponent: [{
36 | name: "toSupplier",
37 | route: "suppliersRoute",
38 | componentTargetInfo: {
39 | suppliersTarget: {
40 | route: "detailRoute",
41 | parameters: {
42 | id: "supplierID"
43 | },
44 | componentTargetInfo: {
45 | productsTarget: {
46 | route: "listRoute",
47 | parameters: {
48 | basepath: "supplierKey"
49 | }
50 | }
51 | }
52 | }
53 | }
54 | }, {
55 | name: "toCategory",
56 | route: "categoriesRoute",
57 | componentTargetInfo: {
58 | categoriesTarget: {
59 | route: "detailRoute",
60 | parameters: {
61 | id: "categoryID"
62 | },
63 | componentTargetInfo: {
64 | productsTarget: {
65 | route: "listRoute",
66 | parameters: {
67 | basepath: "categoryKey"
68 | }
69 | }
70 | }
71 | }
72 | }
73 | }, {
74 | name: "toProduct",
75 | route: "productsRoute",
76 | componentTargetInfo: {
77 | productsTarget: {
78 | route: "detailRoute",
79 | parameters: {
80 | id: "productID"
81 | }
82 | }
83 | }
84 | }],
85 | categoriesComponent: [{
86 | name: "toProduct",
87 | route: "productsRoute",
88 | componentTargetInfo: {
89 | productsTarget: {
90 | route: "detailRoute",
91 | parameters: {
92 | id: "productID"
93 | }
94 | }
95 | }
96 | }]
97 | },
98 | init(...args) {
99 | // Call the init function of the parent
100 | Component.prototype.init.apply(this, args);
101 | },
102 | });
103 | }
104 | );
105 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/controller/App.controller.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "my/lib/sample/base/BaseController",
3 | "sap/base/Log",
4 | "sap/ui/model/json/JSONModel"
5 | ], (Controller, Log, JSONModel) =>{
6 | "use strict";
7 | return Controller.extend("my.lib.sample.root.controller.App", {
8 | onInit(){
9 | Log.info(this.getView().getControllerName(), "onInit");
10 |
11 | this.getOwnerComponent().getRouter().attachRouteMatched(this._onRouteMatched, this);
12 | this.getOwnerComponent().getRouter().attachBypassed(this._onBypassed, this);
13 |
14 | const oTitlesModel = new JSONModel();
15 | this.getView().setModel(oTitlesModel, "titleModel");
16 | this.getOwnerComponent().getRouter().attachTitleChanged((oEvent) => {
17 | oTitlesModel.setData(oEvent.getParameters());
18 | });
19 | },
20 |
21 | _onRouteMatched(oEvent) {
22 | Log.info(this.getView().getControllerName(), "_onRouteMatched");
23 | const oConfig = oEvent.getParameter("config");
24 |
25 | // Select the corresponding item in the left menu
26 | this.setSelectedMenuItem(oConfig.name);
27 | },
28 |
29 | setSelectedMenuItem(sKey) {
30 | this.byId("navigationList").setSelectedKey(sKey);
31 | },
32 |
33 | _onBypassed(oEvent) {
34 | const sHash = oEvent.getParameter("hash");
35 | Log.info(
36 | this.getView().getControllerName(),
37 | `_onBypassed Hash=${ sHash}`
38 | );
39 | },
40 |
41 | onItemSelect(oEvent) {
42 | const sKey = oEvent.getParameter("item").getKey();
43 | Log.info(this.getView().getControllerName(), `onItemSelect Key=${ sKey}`);
44 |
45 | this.getOwnerComponent().getRouter().navTo(sKey);
46 | }
47 | });
48 | });
49 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/controller/Home.controller.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "sap/ui/core/mvc/Controller",
3 | "sap/base/Log",
4 | "sap/ui/model/json/JSONModel"
5 | ], (Controller, Log, JSONModel) => {
6 | "use strict";
7 | return Controller.extend("my.lib.sample.root.controller.Home", {
8 | onInit() {
9 | Log.info(this.getView().getControllerName(), "onInit");
10 |
11 | // HTML string bound to the formatted text control
12 | const oModel = new JSONModel({
13 | HTML: "We are now in the Home View of the Root component. By clicking on the other three items (Suppliers, Categories and Products) in the left menu, further components will be loaded and nested into the Root component.
" +
14 | "Each nested component is consisted with 2 Views: List and Detail Views. In the Detail View of the nested component Products, there are controls which lead to a navigation into one of the other nested components. For example, the category or the supplier link in the Detail View of the Products component navigates to the Detail View of the Categories component or the Suppliers component.
" +
15 | "Furthermore, the Detail View of the Categories or Suppliers component integrates the Products component to show a list of products under a certain category or supplier. Clicking on an item in the product list, a navigation is done to the Detail View of the Products component.
" +
16 | "You can find in the following diagram information about the relationships between the components and how the components are integrated into the component hierarchy. The navigation which is done across different components are also shown in the diagram below.
"
17 | });
18 |
19 | this.getView().setModel(oModel);
20 | }
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/css/style.css:
--------------------------------------------------------------------------------
1 | li.sapTntNavLIItemSelected[id$="suppliersItem"] > div.sapTntNavLIItem {
2 | background-color: antiquewhite;
3 | }
4 |
5 | li.sapTntNavLIItemSelected[id$="categoriesItem"] > div.sapTntNavLIItem {
6 | background-color: aquamarine;
7 | }
8 |
9 | li.sapTntNavLIItemSelected[id$="productsItem"] > div.sapTntNavLIItem {
10 | background-color: lightblue;
11 | }
12 |
13 | .maxWidth100 {
14 | max-width: 100%;
15 | }
16 |
17 | nav.sapMBreadcrumbs {
18 | margin: 0 !important;
19 | padding: 5px;
20 | }
21 |
22 | /* Change position to 'static', if not tnt.Toolpage forces 'absolute' with that no OPA5 output is visible*/
23 | .myToolPage{
24 | position: static !important;
25 | }
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/i18n/i18n.properties:
--------------------------------------------------------------------------------
1 | appTitle=Component Based Navigation Demo
2 | appDescription=Component Based Navigation Demo
3 |
4 | homePageTitle=Home Page
5 | view1Title=Home Page View1 Title
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/i18n/i18n_en.properties:
--------------------------------------------------------------------------------
1 | appTitle=Component Based Navigation Demo
2 | appDescription=Component Based Navigation Demo
3 |
4 | homePageTitle=Home Page
5 | view1Title=Home Page View1 Title
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/img/diagram.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flovogt/ui5-nested-component-scenario/b87635d5b69ffbdb24b8eec4852747e18d5ee0dc/demo/RootComponent/webapp/img/diagram.jpg
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Component Based Navigation
7 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/localService/metadata.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/localService/mockdata/Products.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "ProductID": 1,
4 | "ProductName": "UI5 T-Shirt",
5 | "SupplierID": 1,
6 | "CategoryID": 1,
7 | "QuantityPerUnit": "1 shirt x 1 bag",
8 | "UnitPrice": "19.9900",
9 | "UnitsInStock": 10,
10 | "UnitsOnOrder": 12,
11 | "ReorderLevel": 1,
12 | "Discontinued": false
13 | },
14 | {
15 | "ProductID": 2,
16 | "ProductName": "UI5 Snapback Cap",
17 | "SupplierID": 2,
18 | "CategoryID": 4,
19 | "QuantityPerUnit": "1 cap x 1 bag",
20 | "UnitPrice": "9.9900",
21 | "UnitsInStock": 11,
22 | "UnitsOnOrder": 12,
23 | "ReorderLevel": 1,
24 | "Discontinued": false
25 | },
26 | {
27 | "ProductID": 3,
28 | "ProductName": "UI5 Unisex Two-Tone Hoodie",
29 | "SupplierID": 1,
30 | "CategoryID": 2,
31 | "QuantityPerUnit": "1 hoddie x 1 bag",
32 | "UnitPrice": "45.9900",
33 | "UnitsInStock": 20,
34 | "UnitsOnOrder": 12,
35 | "ReorderLevel": 1,
36 | "Discontinued": false
37 | },
38 | {
39 | "ProductID": 4,
40 | "ProductName": "UI5 Men's Pique Polo Shirt",
41 | "SupplierID": 2,
42 | "CategoryID": 1,
43 | "QuantityPerUnit": "1 shirt x 1 bag",
44 | "UnitPrice": "29.9900",
45 | "UnitsInStock": 5,
46 | "UnitsOnOrder": 12,
47 | "ReorderLevel": 1,
48 | "Discontinued": false
49 | },
50 | {
51 | "ProductID": 5,
52 | "ProductName": "UI5 Jersey",
53 | "SupplierID": 1,
54 | "CategoryID": 2,
55 | "QuantityPerUnit": "1 jersey x 1 bag",
56 | "UnitPrice": "26.4900",
57 | "UnitsInStock": 2,
58 | "UnitsOnOrder": 12,
59 | "ReorderLevel": 1,
60 | "Discontinued": false
61 | },
62 | {
63 | "ProductID": 6,
64 | "ProductName": "UI5 Women's Flowy Tank Top",
65 | "SupplierID": 3,
66 | "CategoryID": 1,
67 | "QuantityPerUnit": "1 tank top x 1 bag",
68 | "UnitPrice": "14.9900",
69 | "UnitsInStock": 39,
70 | "UnitsOnOrder": 12,
71 | "ReorderLevel": 1,
72 | "Discontinued": false
73 | },
74 | {
75 | "ProductID": 7,
76 | "ProductName": "UI5 Women's Vintage Sport T-Shirt",
77 | "SupplierID": 1,
78 | "CategoryID": 1,
79 | "QuantityPerUnit": "1 shirt x 1 bag",
80 | "UnitPrice": "11.9900",
81 | "UnitsInStock": 45,
82 | "UnitsOnOrder": 12,
83 | "ReorderLevel": 1,
84 | "Discontinued": false
85 | },
86 | {
87 | "ProductID": 8,
88 | "ProductName": "UI5 Women's Tri-Blend V-Neck T-Shirt",
89 | "SupplierID": 2,
90 | "CategoryID": 1,
91 | "QuantityPerUnit": "1 shirt x 1 bag",
92 | "UnitPrice": "21.9900",
93 | "UnitsInStock": 102,
94 | "UnitsOnOrder": 12,
95 | "ReorderLevel": 1,
96 | "Discontinued": false
97 | },
98 | {
99 | "ProductID": 9,
100 | "ProductName": "UI5 Phone Case",
101 | "SupplierID": 3,
102 | "CategoryID": 4,
103 | "QuantityPerUnit": "1 phone case x 1 bag",
104 | "UnitPrice": "7.9900",
105 | "UnitsInStock": 87,
106 | "UnitsOnOrder": 12,
107 | "ReorderLevel": 1,
108 | "Discontinued": false
109 | },
110 | {
111 | "ProductID": 10,
112 | "ProductName": "UI5 Enamel Mug",
113 | "SupplierID": 2,
114 | "CategoryID": 3,
115 | "QuantityPerUnit": "1 mug x 1 bag",
116 | "UnitPrice": "19.9900",
117 | "UnitsInStock": 8,
118 | "UnitsOnOrder": 12,
119 | "ReorderLevel": 1,
120 | "Discontinued": false
121 | },
122 | {
123 | "ProductID": 11,
124 | "ProductName": "UI5 Cotton Drawstring Bag",
125 | "SupplierID": 3,
126 | "CategoryID": 4,
127 | "QuantityPerUnit": "1 bag x 1 bag",
128 | "UnitPrice": "24.9900",
129 | "UnitsInStock": 3,
130 | "UnitsOnOrder": 12,
131 | "ReorderLevel": 1,
132 | "Discontinued": false
133 | },
134 | {
135 | "ProductID": 11,
136 | "ProductName": "UI5 Sweatshirt Drawstring Bag",
137 | "SupplierID": 2,
138 | "CategoryID": 4,
139 | "QuantityPerUnit": "1 shirt x 1 bag",
140 | "UnitPrice": "15.9900",
141 | "UnitsInStock": 10,
142 | "UnitsOnOrder": 12,
143 | "ReorderLevel": 1,
144 | "Discontinued": false
145 | },
146 | {
147 | "ProductID": 12,
148 | "ProductName": "UI5 Pillow Dark",
149 | "SupplierID": 3,
150 | "CategoryID": 3,
151 | "QuantityPerUnit": "1 pillow x 1 bag",
152 | "UnitPrice": "29.9900",
153 | "UnitsInStock": 43,
154 | "UnitsOnOrder": 12,
155 | "ReorderLevel": 1,
156 | "Discontinued": false
157 | }
158 | ]
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/localService/mockdata/Suppliers.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "SupplierID": 1,
4 | "CompanyName": "UI5 Awesome Manufactor Company Inc.",
5 | "ContactName": "Amanda Miller",
6 | "ContactTitle": "Purchasing Manager",
7 | "Address": "Westminster",
8 | "City": "London",
9 | "Region": "City of London",
10 | "PostalCode": "SW1A 0AA",
11 | "Country": "United Kingdom of Great Britain and Northern Ireland (the)",
12 | "Phone": "(171) 555-2222",
13 | "Fax": null,
14 | "HomePage": null
15 | },
16 | {
17 | "SupplierID": 2,
18 | "CompanyName": "UI5 Amazing Manufactor SE",
19 | "ContactName": "Peter Schmidt",
20 | "ContactTitle": "Purchasing Manager",
21 | "Address": "Unter den Linden 1",
22 | "City": "Berlin",
23 | "Region": "Berlin",
24 | "PostalCode": "10243",
25 | "Country": "Germany",
26 | "Phone": "(171) 555-2222",
27 | "Fax": null,
28 | "HomePage": null
29 | },
30 | {
31 | "SupplierID": 3,
32 | "CompanyName": "UI5 Wonderful Manufactor Limited",
33 | "ContactName": "Jasneet Kumar",
34 | "ContactTitle": "Purchasing Manager",
35 | "Address": "#138, EPIP Zone",
36 | "City": "Bengaluru",
37 | "Region": "Bayaluseemé",
38 | "PostalCode": "560 066 ",
39 | "Country": "India",
40 | "Phone": "(171) 555-2222",
41 | "Fax": null,
42 | "HomePage": null
43 | }
44 | ]
45 |
46 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/localService/mockserver.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "sap/ui/core/util/MockServer",
3 | "sap/ui/model/json/JSONModel",
4 | "sap/base/Log",
5 | "sap/base/util/UriParameters"
6 | ], (MockServer, JSONModel, Log, UriParameters) => {
7 | "use strict";
8 |
9 |
10 | // eslint-disable-next-line init-declarations
11 | let oMockServer;
12 |
13 | const sAppPath = "my/lib/sample/root/",
14 | sJsonFilesPath = `${sAppPath }localService/mockdata`,
15 | oMockServerInterface = {
16 |
17 | /**
18 | * Initializes the mock server asynchronously.
19 | * You can configure the delay with the URL parameter "serverDelay".
20 | * The local mock data in this folder is returned instead of the real data for testing.
21 | * @protected
22 | * @param {object} [oOptionsParameter] init parameters for the mockserver
23 | * @returns{Promise} a promise that is resolved when the mock server has been started
24 | */
25 | init (oOptionsParameter) {
26 | const oOptions = oOptionsParameter || {};
27 |
28 | return new Promise((fnResolve, fnReject) => {
29 | const sManifestUrl = sap.ui.require.toUrl(`${sAppPath }manifest.json`),
30 | oManifestModel = new JSONModel(sManifestUrl);
31 |
32 | oManifestModel.attachRequestCompleted(() => {
33 | const oUriParameters = new UriParameters(window.location.href),
34 | // Parse manifest for local metadata URI
35 | sJsonFilesUrl = sap.ui.require.toUrl(sJsonFilesPath),
36 | oMainDataSource = oManifestModel.getProperty("/sap.app/dataSources/mainService"),
37 | sMetadataUrl = sap.ui.require.toUrl(sAppPath + oMainDataSource.settings.localUri),
38 | // Ensure there is a trailing slash
39 | sMockServerUrl = /.*\/$/u.test(oMainDataSource.uri) ? oMainDataSource.uri : `${oMainDataSource.uri }/`;
40 |
41 | // Create a mock server instance or stop the existing one to reinitialize
42 | if (!oMockServer) {
43 | oMockServer = new MockServer({
44 | rootUri: sMockServerUrl
45 | });
46 | } else {
47 | oMockServer.stop();
48 | }
49 |
50 | // Configure mock server with the given options or a default delay of 0.5s
51 | MockServer.config({
52 | autoRespond : true,
53 | autoRespondAfter : (oOptions.delay || oUriParameters.get("serverDelay") || 500)
54 | });
55 |
56 | // Simulate all requests using mock data
57 | oMockServer.simulate(sMetadataUrl, {
58 | sMockdataBaseUrl : sJsonFilesUrl,
59 | bGenerateMissingMockData : true
60 | });
61 |
62 | const aRequests = oMockServer.getRequests(),
63 |
64 | // Compose an error response for each request
65 | fnResponse = (iErrCode, sMessage, aRequest) => {
66 | aRequest.response = (oXhr) => {
67 | oXhr.respond(iErrCode, {"Content-Type": "text/plain;charset=utf-8"}, sMessage);
68 | };
69 | };
70 |
71 | // Simulate metadata errors
72 | if (oOptions.metadataError || oUriParameters.get("metadataError")) {
73 | aRequests.forEach((aEntry) => {
74 | if (aEntry.path.toString().indexOf("$metadata") > -1) {
75 | fnResponse(500, "metadata Error", aEntry);
76 | }
77 | });
78 | }
79 |
80 | // Simulate request errors
81 | const sErrorParam = oOptions.errorType || oUriParameters.get("errorType"),
82 | iErrorCode = sErrorParam === "badRequest" ? 400 : 500;
83 | if (sErrorParam) {
84 | aRequests.forEach((aEntry) => {
85 | fnResponse(iErrorCode, sErrorParam, aEntry);
86 | });
87 | }
88 |
89 | // Custom mock behaviour may be added here
90 |
91 | // Set requests and start the server
92 | oMockServer.setRequests(aRequests);
93 | oMockServer.start();
94 |
95 | Log.info("Running the app with mock data");
96 | fnResolve();
97 | });
98 |
99 | oManifestModel.attachRequestFailed(() => {
100 | const sError = "Failed to load application manifest";
101 |
102 | Log.error(sError);
103 | fnReject(new Error(sError));
104 | });
105 | });
106 | },
107 |
108 | /**
109 | * @public returns the mockserver of the app, should be used in integration tests
110 | * @returns {sap.ui.core.util.MockServer} the mockserver instance
111 | */
112 | getMockServer () {
113 | return oMockServer;
114 | }
115 | };
116 |
117 | return oMockServerInterface;
118 | });
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "_version": "1.21.0",
3 | "sap.app": {
4 | "id": "my.lib.sample.root",
5 | "type": "application",
6 | "i18n": {
7 | "bundleUrl": "i18n/i18n.properties",
8 | "supportedLocales": [
9 | "en"
10 | ],
11 | "fallbackLocale": "en"
12 | },
13 | "title": "{{appTitle}}",
14 | "description": "{{appDescription}}",
15 | "applicationVersion": {
16 | "version": "1.0.0"
17 | },
18 | "dataSources": {
19 | "mainService": {
20 | "uri": "/myservice/V2/Northwind.svc",
21 | "type": "OData",
22 | "settings": {
23 | "odataVersion": "2.0",
24 | "localUri": "localService/metadata.xml"
25 | }
26 | }
27 | }
28 | },
29 | "sap.ui": {
30 | "technology": "UI5",
31 | "deviceTypes": {
32 | "desktop": true,
33 | "tablet": true,
34 | "phone": true
35 | }
36 | },
37 | "sap.ui5": {
38 | "contentDensities": {
39 | "cozy": true,
40 | "compact": true
41 | },
42 | "rootView": {
43 | "viewName": "my.lib.sample.root.view.App",
44 | "type": "XML",
45 | "id": "app"
46 | },
47 | "componentUsages": {
48 | "suppliersComponent": {
49 | "name": "my.lib.sample.suppliers",
50 | "settings": {},
51 | "componentData": {},
52 | "lazy": true
53 | },
54 | "categoriesComponent": {
55 | "name": "my.lib.sample.categories",
56 | "settings": {},
57 | "componentData": {},
58 | "lazy": true
59 | },
60 | "productsComponent": {
61 | "name": "my.lib.sample.products",
62 | "settings": {},
63 | "componentData": {},
64 | "lazy": true
65 | }
66 | },
67 | "dependencies": {
68 | "minUI5Version": "1.75.0",
69 | "libs": {
70 | "sap.ui.core": {},
71 | "sap.m": {},
72 | "sap.tnt": {}
73 | },
74 | "components": {
75 | "my.lib.sample.base": {}
76 | }
77 | },
78 | "models": {
79 | "i18n": {
80 | "type": "sap.ui.model.resource.ResourceModel",
81 | "settings": {
82 | "bundleName": "my.lib.sample.root.i18n.i18n",
83 | "supportedLocales": [
84 | "en"
85 | ],
86 | "fallbackLocale": "en"
87 | }
88 | }
89 | },
90 | "resources": {
91 | "css": [
92 | {
93 | "uri": "css/style.css"
94 | }
95 | ]
96 | },
97 | "routing": {
98 | "config": {
99 | "routerClass": "sap.m.routing.Router",
100 | "viewType": "XML",
101 | "path": "my.lib.sample.root.view",
102 | "controlId": "app",
103 | "controlAggregation": "pages",
104 | "transition": "slide",
105 | "bypassed": {
106 | "target": "notFoundTarget"
107 | },
108 | "propagateTitle": true
109 | },
110 | "routes": [
111 | {
112 | "name": "homeRoute",
113 | "pattern": "",
114 | "target": "homeTarget"
115 | },
116 | {
117 | "name": "suppliersRoute",
118 | "pattern": "suppliers",
119 | "target": {
120 | "name": "suppliersTarget",
121 | "prefix": "s"
122 | }
123 | },
124 | {
125 | "name": "categoriesRoute",
126 | "pattern": "categories",
127 | "target": {
128 | "name": "categoriesTarget",
129 | "prefix": "c"
130 | }
131 | },
132 | {
133 | "name": "productsRoute",
134 | "pattern": "products",
135 | "target": {
136 | "name": "productsTarget",
137 | "prefix": "p"
138 | }
139 | }
140 | ],
141 | "targets": {
142 | "homeTarget": {
143 | "type": "View",
144 | "id": "home",
145 | "name": "Home",
146 | "title": "Home"
147 | },
148 | "suppliersTarget": {
149 | "type": "Component",
150 | "usage": "suppliersComponent",
151 | "title": "Suppliers"
152 | },
153 | "categoriesTarget": {
154 | "type": "Component",
155 | "usage": "categoriesComponent",
156 | "title": "Categories"
157 | },
158 | "productsTarget": {
159 | "type": "Component",
160 | "usage": "productsComponent",
161 | "title": "Products",
162 | "id": "productRoot"
163 | },
164 | "notFoundTarget": {
165 | "type": "View",
166 | "id": "notFound",
167 | "name": "NotFound",
168 | "transition": "show"
169 | }
170 | }
171 | }
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/initMockServer.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "../localService/mockserver"
3 | ], (mockserver) => {
4 | "use strict";
5 |
6 | const aMockservers = [];
7 |
8 | // Initialize the mock server
9 | aMockservers.push(mockserver.init());
10 |
11 | Promise.all(aMockservers).catch(async (oError) => {
12 | await sap.ui.getCore().loadLibrary("sap.m", { async: true });
13 | sap.ui.require(["sap/m/MessageBox"], (MessageBox) => {
14 | MessageBox.error(oError.message);
15 | });
16 | }).finally(() => {
17 | // Initialize the embedded component on the HTML page
18 | sap.ui.require(["sap/ui/core/ComponentSupport"]);
19 | });
20 | });
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/integration/AllJourneys.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "sap/ui/test/Opa5",
3 | "./arrangements/Startup",
4 | "./NavigationJourney"
5 | ], (Opa5, Startup) => {
6 | "use strict";
7 | Opa5.extendConfig({
8 | arrangements: new Startup(),
9 | viewNamespace: "my.lib.sample.root.view.",
10 | pollingInterval: 10,
11 | autoWait: true
12 | });
13 | });
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/integration/NavigationJourney.js:
--------------------------------------------------------------------------------
1 | /*global QUnit*/
2 |
3 | sap.ui.define([
4 | "sap/ui/test/opaQunit",
5 | "./pages/App",
6 | "./pages/Home"
7 | ], (opaTest) => {
8 | "use strict";
9 |
10 | QUnit.module("Navigation Journey");
11 |
12 | opaTest("Should navigate to the different pages", (Given, When, Then) => {
13 |
14 | // Arrangements
15 | Given.iStartMyApp();
16 |
17 | // Assertions
18 | Then.onTheHomePage.iShouldSeeTheScreen();
19 |
20 | // Actions
21 | When.onTheAppPage.iClickOnItem("suppliersItem");
22 |
23 | // Assertions
24 | Then.onTheAppPage.iShouldSeeToolPageContentDisplayed("Supplier List");
25 |
26 | // Actions
27 | When.onTheAppPage.iClickOnItem("homeItem");
28 |
29 | // Assertions
30 | Then.onTheAppPage.iShouldSeeToolPageContentDisplayed("Home");
31 |
32 | // Cleanup
33 | Then.iTeardownMyApp();
34 | });
35 |
36 | opaTest("Should navigate to unknown site", (Given, When, Then) => {
37 |
38 | // Arrangements
39 | Given.iStartMyApp({hash: "coool"});
40 |
41 | // Assertions
42 | Then.onTheAppPage.iShouldSeeToolPageContentDisplayed("Component Based Navigation Demo");
43 |
44 | // Cleanup
45 | Then.iTeardownMyApp();
46 | });
47 |
48 | });
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/integration/arrangements/Startup.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "sap/ui/test/Opa5",
3 | "my/lib/sample/root/localService/mockserver",
4 | "sap/ui/model/odata/v2/ODataModel"
5 | ], (Opa5, mockserver, ODataModel) => {
6 | "use strict";
7 |
8 | return Opa5.extend("my.lib.sample.root.test.integration.arrangements.Startup", {
9 |
10 | /**
11 | * Initializes mock server, then starts the app component
12 | * @param {object} oOptionsParameter An object that contains the configuration for starting up the app
13 | * @param {integer} oOptionsParameter.delay A custom delay to start the app with
14 | * @param {string} [oOptionsParameter.hash] The in-app hash can also be passed separately for better readability in tests
15 | * @param {boolean} [oOptionsParameter.autoWait=true] Automatically wait for pending requests while the application is starting up
16 | */
17 | iStartMyApp (oOptionsParameter) {
18 | const oOptions = oOptionsParameter || {};
19 |
20 | this._clearSharedData();
21 |
22 | // Start the app with a minimal delay to make tests fast but still async to discover basic timing issues
23 | oOptions.delay ||= 1;
24 |
25 | // Configure mock server with the current options
26 | const oMockServerInitialized = mockserver.init(oOptions);
27 |
28 | this.iWaitForPromise(oMockServerInitialized);
29 |
30 | // Start the app UI component
31 | this.iStartMyUIComponent({
32 | componentConfig: {
33 | name: "my.lib.sample.root",
34 | async: true
35 | },
36 | hash: oOptions.hash,
37 | autoWait: oOptions.autoWait
38 | });
39 | },
40 | _clearSharedData () {
41 | // Clear shared metadata in ODataModel to allow tests for loading the metadata
42 | ODataModel.mSharedData = { server: {}, service: {}, meta: {} };
43 | }
44 | });
45 | });
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/integration/opaTests.qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Integration tests for Routing With Nested Component
5 |
6 |
7 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/integration/opaTests.qunit.js:
--------------------------------------------------------------------------------
1 |
2 | /* global QUnit */
3 |
4 | QUnit.config.autostart = false;
5 |
6 | sap.ui.getCore().attachInit(() => {
7 | "use strict";
8 |
9 | sap.ui.require([
10 | "my/lib/sample/root/test/integration/AllJourneys"
11 | ], () => {
12 | QUnit.start();
13 | });
14 | });
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/integration/pages/App.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "sap/ui/test/Opa5",
3 | "sap/ui/test/actions/Press"
4 | ], (Opa5, Press) => {
5 | "use strict";
6 |
7 | const sViewName = "App";
8 |
9 | Opa5.createPageObjects({
10 | onTheAppPage : {
11 | viewName: sViewName,
12 | actions : {
13 |
14 | iClickOnItem (sId) {
15 | return this.waitFor({
16 | id: sId,
17 | actions: new Press({}),
18 | success () {
19 | Opa5.assert.ok(true, `The control with id '${ sId }' was pressed.`);
20 | }
21 | });
22 | }
23 | },
24 |
25 | assertions : {
26 | iShouldSeeToolPageContentDisplayed(sTitle){
27 | return this.waitFor({
28 | id : "toolPage",
29 | check(oToolPage){
30 | return sTitle === oToolPage.getHeader().getContent()[1].getText();
31 | },
32 | success () {
33 | Opa5.assert.ok(true, `The toolpage with title '${ sTitle }' is displayed.`);
34 | },
35 | errorMessage : `The toolpage with title '${ sTitle }' is not displayed.`
36 | });
37 | }
38 | }
39 |
40 | }
41 |
42 | });
43 |
44 | });
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/integration/pages/Home.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "sap/ui/test/Opa5"
3 | ], (Opa5) => {
4 | "use strict";
5 |
6 | const sPageId = "homePage",
7 | sViewName = "Home";
8 |
9 | Opa5.createPageObjects({
10 | onTheHomePage : {
11 | viewName: sViewName,
12 |
13 | actions : {},
14 |
15 | assertions : {
16 |
17 | iShouldSeeTheScreen () {
18 | return this.waitFor({
19 | id : sPageId,
20 | success () {
21 | Opa5.assert.ok(true, `The page with id '${ sPageId }' is displayed.`);
22 | },
23 | errorMessage : `The page with id '${ sPageId }' can not be found.`
24 | });
25 | }
26 |
27 | }
28 |
29 | }
30 |
31 | });
32 |
33 | });
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/mockServer.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Component Based Navigation
7 |
8 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/testsuite.qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | QUnit test suite for Routing With Nested Component
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/testsuite.qunit.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-undef, new-cap */
2 | window.suite = () => {
3 | "use strict";
4 |
5 | const oSuite = new parent.jsUnitTestSuite(),
6 | sContextPath = location.pathname.substring(0, location.pathname.lastIndexOf("/") + 1);
7 |
8 | oSuite.addTestPage(`${sContextPath }unit/unitTests.qunit.html`);
9 | oSuite.addTestPage(`${sContextPath }integration/opaTests.qunit.html`);
10 |
11 | return oSuite;
12 | };
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/unit/AllTests.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "./base/BaseController",
3 | ], () => {
4 | "use strict";
5 | });
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/unit/base/BaseController.js:
--------------------------------------------------------------------------------
1 | /*global QUnit*/
2 | /* eslint-disable no-undefined */
3 |
4 | sap.ui.define([
5 | "my/lib/sample/base/BaseController"
6 | ], (BaseController) => {
7 | "use strict";
8 |
9 | QUnit.module("Base Controller");
10 |
11 | QUnit.test("I should test the image formatter", (assert) => {
12 | const oBaseController = new BaseController();
13 | assert.strictEqual(oBaseController.base64StringToImage("335463536"), "data:image/bmp;base64,335463536" , "The base64 string is formatted to a valid HTML image string");
14 | assert.strictEqual(oBaseController.base64StringToImage(null), null, "The base64 string is formatted to 'null' because given value is 'null'");
15 | assert.strictEqual(oBaseController.base64StringToImage(undefined), null, "The base64 string is formatted to 'undefined' because given value is 'null'");
16 | });
17 |
18 | });
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/unit/unitTests.qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Unit tests for Routing With Nested Component
7 |
8 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/test/unit/unitTests.qunit.js:
--------------------------------------------------------------------------------
1 | /* global QUnit */
2 | QUnit.config.autostart = false;
3 |
4 | sap.ui.getCore().attachInit(() => {
5 | "use strict";
6 |
7 | sap.ui.require([
8 | "my/lib/sample/root/test/unit/AllTests"
9 | ], () => {
10 | QUnit.start();
11 | });
12 | });
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/view/App.view.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
20 |
24 |
28 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/view/Home.view.xml:
--------------------------------------------------------------------------------
1 |
5 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/demo/RootComponent/webapp/view/NotFound.view.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
7 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | dist/
3 | .DS_Store
4 | coverage/
--------------------------------------------------------------------------------
/demo/SuppliersComponent/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "my-lib-sample-suppliers-component",
3 | "private": true,
4 | "version": "0.0.1",
5 | "description": "This is the suppliers component including components",
6 | "scripts": {
7 | "start": "ui5 serve",
8 | "build": "ui5 build -a --clean-dest",
9 | "serve": "ws --compress -d dist",
10 | "test": "rimraf coverage && npm run karma-ci",
11 | "lint": "eslint src",
12 | "karma": "karma start",
13 | "karma-ci": "karma start karma-ci.conf.js"
14 | },
15 | "repository": {
16 | "type": "git",
17 | "url": "git@github.com:flovogt/ui5-nested-component-scenario.git"
18 | },
19 | "keywords": [
20 | "openui5",
21 | "sapui5",
22 | "ui5",
23 | "ui5con",
24 | "ui5-routing",
25 | "ui5-component"
26 | ],
27 | "dependencies": {
28 | "my-lib-sample-base-component": "^0.0.1",
29 | "my-lib-sample-products-component": "^0.0.1"
30 | },
31 | "devDependencies": {
32 | "eslint": "^9.25.0",
33 | "@ui5/cli": "^4.0.14",
34 | "local-web-server": "^5.4.0",
35 | "karma": "^6.4.4",
36 | "karma-coverage": "^2.2.1",
37 | "karma-chrome-launcher": "^3.2.0",
38 | "karma-ui5": "^4.1.0",
39 | "rimraf": "^6.0.1"
40 | },
41 | "engines": {
42 | "node": "^16.18.0 || >=18.12.0",
43 | "npm": ">= 8"
44 | },
45 | "author": "Jiawei Cao, Florian Vogt",
46 | "license": "Apache-2.0"
47 | }
48 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/Component.js:
--------------------------------------------------------------------------------
1 | sap.ui.define(["my/lib/sample/base/Component"], (Component) => {
2 | "use strict";
3 |
4 | return Component.extend("my.lib.sample.suppliers.Component", {
5 | metadata: {
6 | manifest: "json",
7 | interfaces: [
8 | "sap.ui.core.IAsyncContentCreation"
9 | ]
10 | },
11 | eventMappings: {
12 | productsComponent: [{
13 | name: "toProduct",
14 | forward: "toProduct"
15 | }]
16 | }
17 | });
18 | });
19 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/controller/App.controller.js:
--------------------------------------------------------------------------------
1 | sap.ui.define(["my/lib/sample/base/BaseController"], (Controller) => {
2 | "use strict";
3 | return Controller.extend("my.lib.sample.suppliers.controller.App", {
4 | });
5 | });
6 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/controller/Detail.controller.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "sap/ui/core/mvc/Controller",
3 | "sap/base/Log"
4 | ], (Controller, Log) => {
5 | "use strict";
6 |
7 | return Controller.extend("my.lib.sample.suppliers.controller.Detail", {
8 |
9 | onInit() {
10 | this.getOwnerComponent().getRouter().getRoute("detailRoute").attachMatched(this._onMatched, this);
11 | },
12 |
13 | _onMatched(oEvent) {
14 | Log.info(this.getView().getControllerName(), "_onMatched");
15 | const oArgs = oEvent.getParameter("arguments");
16 |
17 | this.getOwnerComponent().getModel().metadataLoaded().then(this._bindData.bind(this, oArgs.id));
18 | },
19 |
20 | _bindData(id) {
21 | Log.info(this.getView().getControllerName(), "_bindData");
22 |
23 | const sObjectPath = this.getOwnerComponent().getModel().createKey("Suppliers", { SupplierID: id }),
24 | that = this;
25 |
26 | this.getView().bindElement({
27 | path: "/"+ sObjectPath,
28 | events: {
29 | change() {
30 | Log.info(that.getView().getControllerName(), "_bindData change");
31 | that.getView().setBusy(false);
32 | },
33 | dataRequested() {
34 | Log.info(that.getView().getControllerName(), "_bindData dataRequested");
35 | that.getView().setBusy(true);
36 | },
37 | dataReceived() {
38 | Log.info(that.getView().getControllerName(), "_bindData dataReceived");
39 | that.getView().setBusy(false);
40 | if (that.getView().getBindingContext() === null) {
41 | that.getOwnerComponent().getRouter().getTargets().display("notFound");
42 | }
43 | }
44 | }
45 | });
46 | }
47 | });
48 | });
49 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/controller/List.controller.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "my/lib/sample/base/BaseController",
3 | "sap/base/Log"
4 | ], (Controller, Log) => {
5 | "use strict";
6 | return Controller.extend("my.lib.sample.suppliers.controller.List", {
7 | onPressListItem(oEvent) {
8 | Log.info(this.getView().getControllerName(), "onPressListItem");
9 |
10 | const oBindingContext = oEvent.getSource().getBindingContext();
11 |
12 | this.getOwnerComponent()
13 | .getRouter()
14 | .navTo("detailRoute", {
15 | id: oBindingContext.getProperty("SupplierID")
16 | }, {
17 | productsTarget: {
18 | route: "listRoute",
19 | parameters: {
20 | /*
21 | * Encode the path because it could contain "/" which
22 | * isn't allowed to use as pattern parameter directly
23 | */
24 | basepath: encodeURIComponent(oBindingContext.getPath())
25 | }
26 | }
27 | });
28 | }
29 | });
30 | });
31 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/css/style.css:
--------------------------------------------------------------------------------
1 | .suppliersPage {
2 | background-color: antiquewhite;
3 | }
4 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/i18n/i18n.properties:
--------------------------------------------------------------------------------
1 | appTitle=Supplier Component
2 | appDescription=Supplier Reusable Component
3 |
4 | listViewTitle=Suppliers
5 | detailViewTitle=Supplier Details
6 | productListTitle=Products
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Component Based Navigation
7 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/localService/metadata.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/localService/mockdata/Products.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "ProductID": 1,
4 | "ProductName": "UI5 T-Shirt",
5 | "SupplierID": 1,
6 | "CategoryID": 1,
7 | "QuantityPerUnit": "1 shirt x 1 bag",
8 | "UnitPrice": "19.9900",
9 | "UnitsInStock": 10,
10 | "UnitsOnOrder": 12,
11 | "ReorderLevel": 1,
12 | "Discontinued": false
13 | },
14 | {
15 | "ProductID": 2,
16 | "ProductName": "UI5 Snapback Cap",
17 | "SupplierID": 2,
18 | "CategoryID": 4,
19 | "QuantityPerUnit": "1 cap x 1 bag",
20 | "UnitPrice": "9.9900",
21 | "UnitsInStock": 11,
22 | "UnitsOnOrder": 12,
23 | "ReorderLevel": 1,
24 | "Discontinued": false
25 | },
26 | {
27 | "ProductID": 3,
28 | "ProductName": "UI5 Unisex Two-Tone Hoodie",
29 | "SupplierID": 1,
30 | "CategoryID": 2,
31 | "QuantityPerUnit": "1 hoddie x 1 bag",
32 | "UnitPrice": "45.9900",
33 | "UnitsInStock": 20,
34 | "UnitsOnOrder": 12,
35 | "ReorderLevel": 1,
36 | "Discontinued": false
37 | },
38 | {
39 | "ProductID": 4,
40 | "ProductName": "UI5 Men's Pique Polo Shirt",
41 | "SupplierID": 2,
42 | "CategoryID": 1,
43 | "QuantityPerUnit": "1 shirt x 1 bag",
44 | "UnitPrice": "29.9900",
45 | "UnitsInStock": 5,
46 | "UnitsOnOrder": 12,
47 | "ReorderLevel": 1,
48 | "Discontinued": false
49 | },
50 | {
51 | "ProductID": 5,
52 | "ProductName": "UI5 Jersey",
53 | "SupplierID": 1,
54 | "CategoryID": 2,
55 | "QuantityPerUnit": "1 jersey x 1 bag",
56 | "UnitPrice": "26.4900",
57 | "UnitsInStock": 2,
58 | "UnitsOnOrder": 12,
59 | "ReorderLevel": 1,
60 | "Discontinued": false
61 | },
62 | {
63 | "ProductID": 6,
64 | "ProductName": "UI5 Women's Flowy Tank Top",
65 | "SupplierID": 3,
66 | "CategoryID": 1,
67 | "QuantityPerUnit": "1 tank top x 1 bag",
68 | "UnitPrice": "14.9900",
69 | "UnitsInStock": 39,
70 | "UnitsOnOrder": 12,
71 | "ReorderLevel": 1,
72 | "Discontinued": false
73 | },
74 | {
75 | "ProductID": 7,
76 | "ProductName": "UI5 Women's Vintage Sport T-Shirt",
77 | "SupplierID": 1,
78 | "CategoryID": 1,
79 | "QuantityPerUnit": "1 shirt x 1 bag",
80 | "UnitPrice": "11.9900",
81 | "UnitsInStock": 45,
82 | "UnitsOnOrder": 12,
83 | "ReorderLevel": 1,
84 | "Discontinued": false
85 | },
86 | {
87 | "ProductID": 8,
88 | "ProductName": "UI5 Women's Tri-Blend V-Neck T-Shirt",
89 | "SupplierID": 2,
90 | "CategoryID": 1,
91 | "QuantityPerUnit": "1 shirt x 1 bag",
92 | "UnitPrice": "21.9900",
93 | "UnitsInStock": 102,
94 | "UnitsOnOrder": 12,
95 | "ReorderLevel": 1,
96 | "Discontinued": false
97 | },
98 | {
99 | "ProductID": 9,
100 | "ProductName": "UI5 Phone Case",
101 | "SupplierID": 3,
102 | "CategoryID": 4,
103 | "QuantityPerUnit": "1 phone case x 1 bag",
104 | "UnitPrice": "7.9900",
105 | "UnitsInStock": 87,
106 | "UnitsOnOrder": 12,
107 | "ReorderLevel": 1,
108 | "Discontinued": false
109 | },
110 | {
111 | "ProductID": 10,
112 | "ProductName": "UI5 Enamel Mug",
113 | "SupplierID": 2,
114 | "CategoryID": 3,
115 | "QuantityPerUnit": "1 mug x 1 bag",
116 | "UnitPrice": "19.9900",
117 | "UnitsInStock": 8,
118 | "UnitsOnOrder": 12,
119 | "ReorderLevel": 1,
120 | "Discontinued": false
121 | },
122 | {
123 | "ProductID": 11,
124 | "ProductName": "UI5 Cotton Drawstring Bag",
125 | "SupplierID": 3,
126 | "CategoryID": 4,
127 | "QuantityPerUnit": "1 bag x 1 bag",
128 | "UnitPrice": "24.9900",
129 | "UnitsInStock": 3,
130 | "UnitsOnOrder": 12,
131 | "ReorderLevel": 1,
132 | "Discontinued": false
133 | },
134 | {
135 | "ProductID": 11,
136 | "ProductName": "UI5 Sweatshirt Drawstring Bag",
137 | "SupplierID": 2,
138 | "CategoryID": 4,
139 | "QuantityPerUnit": "1 shirt x 1 bag",
140 | "UnitPrice": "15.9900",
141 | "UnitsInStock": 10,
142 | "UnitsOnOrder": 12,
143 | "ReorderLevel": 1,
144 | "Discontinued": false
145 | },
146 | {
147 | "ProductID": 12,
148 | "ProductName": "UI5 Pillow Dark",
149 | "SupplierID": 3,
150 | "CategoryID": 3,
151 | "QuantityPerUnit": "1 pillow x 1 bag",
152 | "UnitPrice": "29.9900",
153 | "UnitsInStock": 43,
154 | "UnitsOnOrder": 12,
155 | "ReorderLevel": 1,
156 | "Discontinued": false
157 | }
158 | ]
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/localService/mockdata/Suppliers.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "SupplierID": 1,
4 | "CompanyName": "UI5 Awesome Manufactor Company Inc.",
5 | "ContactName": "Amanda Miller",
6 | "ContactTitle": "Purchasing Manager",
7 | "Address": "Westminster",
8 | "City": "London",
9 | "Region": "City of London",
10 | "PostalCode": "SW1A 0AA",
11 | "Country": "United Kingdom of Great Britain and Northern Ireland (the)",
12 | "Phone": "(171) 555-2222",
13 | "Fax": null,
14 | "HomePage": null
15 | },
16 | {
17 | "SupplierID": 2,
18 | "CompanyName": "UI5 Amazing Manufactor SE",
19 | "ContactName": "Peter Schmidt",
20 | "ContactTitle": "Purchasing Manager",
21 | "Address": "Unter den Linden 1",
22 | "City": "Berlin",
23 | "Region": "Berlin",
24 | "PostalCode": "10243",
25 | "Country": "Germany",
26 | "Phone": "(171) 555-2222",
27 | "Fax": null,
28 | "HomePage": null
29 | },
30 | {
31 | "SupplierID": 3,
32 | "CompanyName": "UI5 Wonderful Manufactor Limited",
33 | "ContactName": "Jasneet Kumar",
34 | "ContactTitle": "Purchasing Manager",
35 | "Address": "#138, EPIP Zone",
36 | "City": "Bengaluru",
37 | "Region": "Bayaluseemé",
38 | "PostalCode": "560 066 ",
39 | "Country": "India",
40 | "Phone": "(171) 555-2222",
41 | "Fax": null,
42 | "HomePage": null
43 | }
44 | ]
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/localService/mockserver.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "sap/ui/core/util/MockServer",
3 | "sap/ui/model/json/JSONModel",
4 | "sap/base/Log",
5 | "sap/base/util/UriParameters"
6 | ], (MockServer, JSONModel, Log, UriParameters) => {
7 | "use strict";
8 |
9 |
10 | // eslint-disable-next-line init-declarations
11 | let oMockServer;
12 |
13 | const sAppPath = "my/lib/sample/suppliers/",
14 | sJsonFilesPath = `${sAppPath }localService/mockdata`,
15 | oMockServerInterface = {
16 |
17 | /**
18 | * Initializes the mock server asynchronously.
19 | * You can configure the delay with the URL parameter "serverDelay".
20 | * The local mock data in this folder is returned instead of the real data for testing.
21 | * @protected
22 | * @param {object} [oOptionsParameter] init parameters for the mockserver
23 | * @returns{Promise} a promise that is resolved when the mock server has been started
24 | */
25 | init (oOptionsParameter) {
26 | const oOptions = oOptionsParameter || {};
27 |
28 | return new Promise((fnResolve, fnReject) => {
29 | const sManifestUrl = sap.ui.require.toUrl(`${sAppPath }manifest.json`),
30 | oManifestModel = new JSONModel(sManifestUrl);
31 |
32 | oManifestModel.attachRequestCompleted(() => {
33 | const oUriParameters = new UriParameters(window.location.href),
34 | // Parse manifest for local metadata URI
35 | sJsonFilesUrl = sap.ui.require.toUrl(sJsonFilesPath),
36 | oMainDataSource = oManifestModel.getProperty("/sap.app/dataSources/mainService"),
37 | sMetadataUrl = sap.ui.require.toUrl(sAppPath + oMainDataSource.settings.localUri),
38 | // Ensure there is a trailing slash
39 | sMockServerUrl = /.*\/$/u.test(oMainDataSource.uri) ? oMainDataSource.uri : `${oMainDataSource.uri }/`;
40 |
41 | // Create a mock server instance or stop the existing one to reinitialize
42 | if (!oMockServer) {
43 | oMockServer = new MockServer({
44 | rootUri: sMockServerUrl
45 | });
46 | } else {
47 | oMockServer.stop();
48 | }
49 |
50 | // Configure mock server with the given options or a default delay of 0.5s
51 | MockServer.config({
52 | autoRespond : true,
53 | autoRespondAfter : (oOptions.delay || oUriParameters.get("serverDelay") || 500)
54 | });
55 |
56 | // Simulate all requests using mock data
57 | oMockServer.simulate(sMetadataUrl, {
58 | sMockdataBaseUrl : sJsonFilesUrl,
59 | bGenerateMissingMockData : true
60 | });
61 |
62 | const aRequests = oMockServer.getRequests(),
63 |
64 | // Compose an error response for each request
65 | fnResponse = (iErrCode, sMessage, aRequest) => {
66 | aRequest.response = (oXhr) => {
67 | oXhr.respond(iErrCode, {"Content-Type": "text/plain;charset=utf-8"}, sMessage);
68 | };
69 | };
70 |
71 | // Simulate metadata errors
72 | if (oOptions.metadataError || oUriParameters.get("metadataError")) {
73 | aRequests.forEach((aEntry) => {
74 | if (aEntry.path.toString().indexOf("$metadata") > -1) {
75 | fnResponse(500, "metadata Error", aEntry);
76 | }
77 | });
78 | }
79 |
80 | // Simulate request errors
81 | const sErrorParam = oOptions.errorType || oUriParameters.get("errorType"),
82 | iErrorCode = sErrorParam === "badRequest" ? 400 : 500;
83 | if (sErrorParam) {
84 | aRequests.forEach((aEntry) => {
85 | fnResponse(iErrorCode, sErrorParam, aEntry);
86 | });
87 | }
88 |
89 | // Custom mock behaviour may be added here
90 |
91 | // Set requests and start the server
92 | oMockServer.setRequests(aRequests);
93 | oMockServer.start();
94 |
95 | Log.info("Running the app with mock data");
96 | fnResolve();
97 | });
98 |
99 | oManifestModel.attachRequestFailed(() => {
100 | const sError = "Failed to load application manifest";
101 |
102 | Log.error(sError);
103 | fnReject(new Error(sError));
104 | });
105 | });
106 | },
107 |
108 | /**
109 | * @public returns the mockserver of the app, should be used in integration tests
110 | * @returns {sap.ui.core.util.MockServer} the mockserver instance
111 | */
112 | getMockServer () {
113 | return oMockServer;
114 | }
115 | };
116 |
117 | return oMockServerInterface;
118 | });
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "_version": "1.21.0",
3 | "sap.app": {
4 | "id": "my.lib.sample.suppliers",
5 | "type": "application",
6 | "i18n": {
7 | "bundleUrl": "i18n/i18n.properties",
8 | "supportedLocales": [
9 | ""
10 | ],
11 | "fallbackLocale": ""
12 | },
13 | "title": "{{appTitle}}",
14 | "description": "{{appDescription}}",
15 | "applicationVersion": {
16 | "version": "1.0.0"
17 | },
18 | "dataSources": {
19 | "mainService": {
20 | "uri": "/myservice/V2/Northwind.svc",
21 | "type": "OData",
22 | "settings": {
23 | "odataVersion": "2.0",
24 | "localUri": "localService/metadata.xml"
25 | }
26 | }
27 | }
28 | },
29 | "sap.ui": {
30 | "technology": "UI5",
31 | "deviceTypes": {
32 | "desktop": true,
33 | "tablet": true,
34 | "phone": true
35 | }
36 | },
37 | "sap.ui5": {
38 | "contentDensities": {
39 | "cozy": true,
40 | "compact": true
41 | },
42 | "rootView": {
43 | "viewName": "my.lib.sample.suppliers.view.App",
44 | "type": "XML",
45 | "id": "app"
46 | },
47 | "componentUsages": {
48 | "productsComponent": {
49 | "name": "my.lib.sample.products",
50 | "settings": {},
51 | "componentData": {},
52 | "lazy": true
53 | }
54 | },
55 | "dependencies": {
56 | "minUI5Version": "1.75.0",
57 | "libs": {
58 | "sap.ui.core": {},
59 | "sap.ui.layout": {},
60 | "sap.m": {}
61 | },
62 | "components": {
63 | "my.lib.sample.base": {}
64 | }
65 | },
66 | "models": {
67 | "i18n": {
68 | "type": "sap.ui.model.resource.ResourceModel",
69 | "settings": {
70 | "bundleName": "my.lib.sample.suppliers.i18n.i18n",
71 | "supportedLocales": [
72 | ""
73 | ],
74 | "fallbackLocale": ""
75 | }
76 | },
77 | "": {
78 | "dataSource": "mainService",
79 | "preload": true,
80 | "settings": {
81 | "useBatch": false,
82 | "defaultCountMode": "Inline",
83 | "defaultBindingMode": "TwoWay"
84 | }
85 | }
86 | },
87 | "resources": {
88 | "css": [
89 | {
90 | "uri": "css/style.css"
91 | }
92 | ]
93 | },
94 | "routing": {
95 | "config": {
96 | "routerClass": "sap.m.routing.Router",
97 | "viewType": "XML",
98 | "path": "my.lib.sample.suppliers.view",
99 | "controlId": "app",
100 | "controlAggregation": "pages",
101 | "transition": "slide",
102 | "bypassed": {
103 | "target": "notFoundTarget"
104 | }
105 | },
106 | "routes": [
107 | {
108 | "name": "listRoute",
109 | "pattern": "",
110 | "target": "listTarget"
111 | },
112 | {
113 | "name": "detailRoute",
114 | "pattern": "detail/{id}",
115 | "target": {
116 | "name": "productsTarget",
117 | "prefix": "p"
118 | }
119 | }
120 | ],
121 | "targets": {
122 | "listTarget": {
123 | "type": "View",
124 | "id": "list",
125 | "name": "List",
126 | "title": "Supplier List"
127 | },
128 | "detailTarget": {
129 | "type": "View",
130 | "id": "detail",
131 | "name": "Detail",
132 | "title": "{CompanyName}"
133 | },
134 | "productsTarget": {
135 | "type": "Component",
136 | "usage": "productsComponent",
137 | "parent": "detailTarget",
138 | "controlId": "box",
139 | "controlAggregation": "items",
140 | "id": "productInSupplier"
141 | },
142 | "notFoundTarget": {
143 | "type": "View",
144 | "id": "notFound",
145 | "name": "NotFound",
146 | "transition": "show"
147 | }
148 | }
149 | }
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/test/initMockServer.js:
--------------------------------------------------------------------------------
1 | sap.ui.define([
2 | "../localService/mockserver"
3 | ], (mockserver) => {
4 | "use strict";
5 |
6 | const aMockservers = [];
7 |
8 | // Initialize the mock server
9 | aMockservers.push(mockserver.init());
10 |
11 | Promise.all(aMockservers).catch(async (oError) => {
12 | await sap.ui.getCore().loadLibrary("sap.m", { async: true });
13 | sap.ui.require(["sap/m/MessageBox"], (MessageBox) => {
14 | MessageBox.error(oError.message);
15 | });
16 | }).finally(() => {
17 | // Initialize the embedded component on the HTML page
18 | sap.ui.require(["sap/ui/core/ComponentSupport"]);
19 | });
20 | });
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/test/mockServer.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Component Based Navigation
7 |
8 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/view/App.view.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/view/Detail.view.xml:
--------------------------------------------------------------------------------
1 |
10 |
15 |
16 |
18 |
19 |
20 |
21 |
22 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/view/List.view.xml:
--------------------------------------------------------------------------------
1 |
5 |
9 |
12 |
13 |
14 |
15 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/src/my/lib/sample/suppliers/view/NotFound.view.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/demo/SuppliersComponent/ui5.yaml:
--------------------------------------------------------------------------------
1 | specVersion: "2.6"
2 | metadata:
3 | name: my.lib.sample.suppliers
4 | type: library
5 | framework:
6 | name: OpenUI5
7 | version: 1.136.0
8 | libraries:
9 | - name: sap.ui.core
10 | - name: sap.m
11 | - name: themelib_sap_horizon
12 | builder:
13 | componentPreload:
14 | namespaces:
15 | - "my/lib/sample/suppliers"
16 |
--------------------------------------------------------------------------------
/demo/eslint.config.mjs:
--------------------------------------------------------------------------------
1 | import js from "@eslint/js";
2 |
3 | export default [
4 | js.configs.recommended,
5 | js.configs.all,
6 | {
7 | languageOptions: {
8 | globals: {
9 | jQuery: true,
10 | sap: true,
11 | window: true
12 | },
13 | sourceType: "script"
14 | },
15 | rules: {
16 | "no-negated-condition": "off",
17 | "no-magic-numbers": "off",
18 | "no-ternary": "off",
19 | "no-underscore-dangle": ["error", { "allowAfterThis": true }],
20 | "one-var": ["off"],
21 | "max-lines-per-function": ["error", 300],
22 | "max-params": ["error", 5],
23 | "max-statements": ["error", 16],
24 | "prefer-template": ["off"],
25 | "sort-keys": "off",
26 | "sort-vars": "off",
27 | "line-comment-position": "off",
28 | "no-inline-comments": "off"
29 | }
30 | }
31 | ]
32 |
--------------------------------------------------------------------------------
/demo/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ui5-nested-component-scenario-demo",
3 | "private": true,
4 | "version": "1.0.0",
5 | "description": "ui5-nested-component-scenario demo",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1",
8 | "lint": "npm run lint --workspaces --if-present"
9 | },
10 | "workspaces": [
11 | "BaseComponent",
12 | "ProductsComponent",
13 | "CategoriesComponent",
14 | "SuppliersComponent",
15 | "RootComponent"
16 | ],
17 | "author": "Jiawei Cao, Florian Vogt",
18 | "license": "Apache-2.0"
19 | }
20 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3 | "extends": [
4 | "config:recommended",
5 | "github>ui5/renovate-config:lts#v1.1.1"
6 | ],
7 | "lockFileMaintenance": {
8 | "enabled": true,
9 | "automerge": true,
10 | "commitMessagePrefix": "build:",
11 | "commitMessageAction": "In-range update of npm dependencies",
12 | "schedule": [
13 | "* 0-8 * * 1"
14 | ]
15 | },
16 | "packageRules": [
17 | {
18 | "matchDepNames": [
19 | "*"
20 | ],
21 | "automerge": true,
22 | "commitMessagePrefix": "build(deps-dev):",
23 | "commitMessageAction": "Bump",
24 | "schedule": [
25 | "* 8-16 * * 1"
26 | ]
27 | },
28 | {
29 | "matchManagers": [
30 | "github-actions"
31 | ],
32 | "automerge": true,
33 | "commitMessagePrefix": "build(github-actions):",
34 | "commitMessageAction": "Bump",
35 | "schedule": [
36 | "* 8-16 * * 1"
37 | ]
38 | },
39 | {
40 | "matchPackageNames": [
41 | "node",
42 | "npm"
43 | ],
44 | "enabled": false
45 | },
46 | {
47 | "matchDepNames": [
48 | "openui5_lts"
49 | ],
50 | "automerge": true,
51 | "commitMessagePrefix": "deps:",
52 | "commitMessageAction": "Update",
53 | "schedule": [
54 | "* 8-16 * * 1"
55 | ]
56 | }
57 | ]
58 | }
59 |
--------------------------------------------------------------------------------
/slides/UI5con20_Routing_Reusable_Components.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flovogt/ui5-nested-component-scenario/b87635d5b69ffbdb24b8eec4852747e18d5ee0dc/slides/UI5con20_Routing_Reusable_Components.pdf
--------------------------------------------------------------------------------