├── .gitignore ├── LICENSE ├── LICENSES └── Apache-2.0.txt ├── README.md ├── REUSE.toml ├── app.png ├── bookshop ├── db │ ├── data │ │ ├── codejam-Authors.csv │ │ ├── codejam-Books.csv │ │ ├── codejam-Books_texts.csv │ │ ├── codejam-Genres.csv │ │ ├── codejam-Sales.csv │ │ └── sap.common-Currencies.csv │ └── schema.cds ├── package.json └── srv │ ├── cat-service.cds │ └── cat-service.js └── chapters ├── 00-prep-dev-environment └── readme.md ├── 01-run-cap-app ├── data.png ├── readme.md └── server.png ├── 02-create-fe-app ├── app.png ├── command-palette.png ├── readme.md └── server.png ├── 03-custom-section-via-extension-point ├── command-palette.png ├── custom-section.png ├── object-page.png ├── page-map1.png ├── page-map2.png └── readme.md ├── 04-handler ├── object-page.png └── readme.md ├── 05-controller-extension ├── object-page.png └── readme.md ├── 06-building-block ├── chart.png └── readme.md ├── 07-formatting-via-cds-annotations ├── app.png ├── guided-development.png ├── readme.md ├── step1.png └── step2.png ├── 08-value-help-via-cds-annotations ├── app.png ├── list-report-page.png ├── object-page.png └── readme.md └── 09-header-section-via-cds-annotations ├── app.png ├── command-palette.png ├── header-section.png ├── page-map1.png ├── page-map2.png └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | package-lock.json 3 | .DS_Store 4 | .vscode/ 5 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /LICENSES/Apache-2.0.txt: -------------------------------------------------------------------------------- 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 | # SAP CodeJam - SAP Fiori elements flexible programming model 2 | 3 | [![REUSE status](https://api.reuse.software/badge/github.com/SAP-samples/fiori-elements-fpm-exercises-codejam)](https://api.reuse.software/info/github.com/SAP-samples/fiori-elements-fpm-exercises-codejam) 4 | 5 | This repository contains material for SAP CodeJam events on the SAP Fiori elements flexible programming model. 6 | 7 | Please check the [prerequisites](/chapters/00-prep-dev-environment/readme.md#1-prerequisites) before the event an make sure you meet them. 8 | 9 | ## Overview 10 | 11 | The material in this repository introduces you to the [SAP Fiori elements](https://ui5.sap.com/#/topic/03265b0408e2432c9571d6b3feb6b1fd), more specifically its [flexible programming model](https://ui5.sap.com/test-resources/sap/fe/core/fpmExplorer/index.html#/overview/introduction). With SAP Fiori elements developers can create metadata-driven frontend applications that require little to no custom coding. This greatly improves the maintainability and UX consistency of these application, which are enterprise-ready out of the box. By selecting one of the available [floorplans](https://ui5.sap.com/#/topic/797c3239b2a9491fa137e4998fd76aa7.html) (think "application layouts"), developers can solely focus on the business logic. In addition to that, the SAP Fiori elements flexible programming model provides extension points to inject custom layouts and logic into the predefined floorplans. Therefore, the SAP Fiori elements flexible programming model bridges the gap between SAP Fiori elements and [freestyle UI5 development](https://github.com/SAP-Samples/ui5-exercises-codejam). 12 | 13 | This repository is a step-by-step guide explaining how to build a bookshop application using the SAP Fiori elements flexible programming model. The finished application is a bookshop, where users can browse and order books. The OData backend service for this application was built using the Node.js flavour of SAP Cloud Application Programming Model (SAP CAP). It is a slighlty modified version of the well-know [bookshop example](https://github.com/SAP-samples/cloud-cap-samples/tree/main/bookshop). You can inspect it in the `bookshop/` directory. 14 | 15 | After working through all the chapters, following the instruction, and reading the explanations, you will be able to develop your own applications using the SAP Fiori elements as well as its flexible programming model. 16 | 17 | ![app](app.png) 18 | 19 | ## Previous Knowledge 20 | 21 | The material in this repository aims to be beginner friendly. While it certainly helps to have prior (web) development or even UI5 experience, beginners will still be able to follow along - even with no prior knowledge. In any case, make sure you read the instructions and explanations thoroughly to have the best learning experience possible. 22 | 23 | ## Material Organization 24 | 25 | The material consists of a series of chapters, each in their own directory. The chapters build on top of each other and are meant to be completed in the given order. Each of the [chapters](#chapters) has its own 'readme' file with instructions, explanations, code samples, and screen shots. From a session flow perspective, we are taking a "coordinated" approach: 26 | 27 | The instructor will set you off on the first chapter. Do not proceed to the next chapter until the instructor tells you to do so. If you finish a chapter before others, there are some questions at the end of each chapter for you to ponder. 28 | 29 | > The exercises are written in a conversational way - this is so that they have enough context and information to be completed outside the hands-on session itself. To help you navigate and find what you have to actually do next, there are pointers like this ➡️ throughout that indicate the things you have to actually do (as opposed to just read for background information). 30 | 31 | ## Chapters 32 | 33 | - [00 - Preparing the development environment](/chapters/00-prep-dev-environment/) 34 | - [01 - Running the SAP CAP application](/chapters/01-run-cap-app/) 35 | - [02 - Creating the SAP Fiori elements application](/chapters/02-create-fe-app/) 36 | - [03 - Creating a custom section via an extension point](/chapters/03-custom-section-via-extension-point/) 37 | - [04 - Using the JavaScript handler](/chapters/04-handler/) 38 | - [05 - Adding a controller extension](/chapters/05-controller-extension/) 39 | - [06 - Adding a building block](/chapters/06-building-block/) 40 | - [07 - Adding formatting via CDS annotations](/chapters/07-formatting-via-cds-annotations/) 41 | - [08 - Adding value help via CDS annotations](/chapters/08-value-help-via-cds-annotations/) 42 | - [09 - Adding a header section via CDS annotations](/chapters/09-header-section-via-cds-annotations/) 43 | 44 | ## Support 45 | 46 | Support for the content in this repository is available during SAP CodeJam events, for which this content has been designed. Otherwise, this content is provided "as-is" with no other support. 47 | 48 | ## Contributing 49 | If you wish to contribute code, offer fixes or improvements, please send a pull request. Due to legal reasons, contributors will be asked to accept a DCO when they create the first pull request to this project. This happens in an automated fashion during the submission process. SAP uses [the standard DCO text of the Linux Foundation](https://developercertificate.org/). 50 | 51 | ## License 52 | Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](/LICENSE) file. 53 | -------------------------------------------------------------------------------- /REUSE.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | SPDX-PackageName = "fiori-elements-fpm-exercises-codejam" 3 | SPDX-PackageSupplier = "ospo@sap.com" 4 | SPDX-PackageDownloadLocation = "" 5 | SPDX-PackageComment = "The code in this project may include calls to APIs (\"API Calls\") of\n SAP or third-party products or services developed outside of this project\n (\"External Products\").\n \"APIs\" means application programming interfaces, as well as their respective\n specifications and implementing code that allows software to communicate with\n other software.\n API Calls to External Products are not licensed under the open source license\n that governs this project. The use of such API Calls and related External\n Products are subject to applicable additional agreements with the relevant\n provider of the External Products. In no event shall the open source license\n that governs this project grant any rights in or to any External Products,or\n alter, expand or supersede any terms of the applicable additional agreements.\n If you have a valid license agreement with SAP for the use of a particular SAP\n External Product, then you may make use of any API Calls included in this\n project's code for that SAP External Product, subject to the terms of such\n license agreement. If you do not have a valid license agreement for the use of\n a particular SAP External Product, then you may only make use of any API Calls\n in this project for that SAP External Product for your internal, non-productive\n and non-commercial test and evaluation of such API Calls. Nothing herein grants\n you any rights to use or access any SAP External Product, or provide any third\n parties the right to use of access any SAP External Product, through API Calls." 6 | 7 | [[annotations]] 8 | path = "**" 9 | precedence = "aggregate" 10 | SPDX-FileCopyrightText = "2024 SAP SE or an SAP affiliate company and fiori-elements-fpm-exercises-codejam contributors" 11 | SPDX-License-Identifier = "Apache-2.0" 12 | -------------------------------------------------------------------------------- /app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP-samples/fiori-elements-fpm-exercises-codejam/9207b7fc262add0babb02c85b467279335977255/app.png -------------------------------------------------------------------------------- /bookshop/db/data/codejam-Authors.csv: -------------------------------------------------------------------------------- 1 | ID;name;dateOfBirth;placeOfBirth;dateOfDeath;placeOfDeath 2 | 101;Emily Brontë;1818-07-30;Thornton, Yorkshire;1848-12-19;Haworth, Yorkshire 3 | 107;Charlotte Brontë;1818-04-21;Thornton, Yorkshire;1855-03-31;Haworth, Yorkshire 4 | 150;Edgar Allen Poe;1809-01-19;Boston, Massachusetts;1849-10-07;Baltimore, Maryland 5 | 170;Richard Carpenter;1929-08-14;King’s Lynn, Norfolk;2012-02-26;Hertfordshire, England 6 | -------------------------------------------------------------------------------- /bookshop/db/data/codejam-Books.csv: -------------------------------------------------------------------------------- 1 | ID;title;descr;author_ID;stock;price;currency_code;genre_ID 2 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;Wuthering Heights;"Wuthering Heights, Emily Brontë's only novel, was published in 1847 under the pseudonym ""Ellis Bell"". It was written between October 1845 and June 1846. Wuthering Heights and Anne Brontë's Agnes Grey were accepted by publisher Thomas Newby before the success of their sister Charlotte's novel Jane Eyre. After Emily's death, Charlotte edited the manuscript of Wuthering Heights and arranged for the edited version to be published as a posthumous second edition in 1850.";101;10;11.11;GBP;11 3 | fda402ba-7083-4d42-a0c7-ecd565b26eec;Jane Eyre;"Jane Eyre /ɛər/ (originally published as Jane Eyre: An Autobiography) is a novel by English writer Charlotte Brontë, published under the pen name ""Currer Bell"", on 16 October 1847, by Smith, Elder & Co. of London. The first American edition was published the following year by Harper & Brothers of New York. Primarily a bildungsroman, Jane Eyre follows the experiences of its eponymous heroine, including her growth to adulthood and her love for Mr. Rochester, the brooding master of Thornfield Hall. The novel revolutionised prose fiction in that the focus on Jane's moral and spiritual development is told through an intimate, first-person narrative, where actions and events are coloured by a psychological intensity. The book contains elements of social criticism, with a strong sense of Christian morality at its core and is considered by many to be ahead of its time because of Jane's individualistic character and how the novel approaches the topics of class, sexuality, religion and feminism.";107;0;12.34;GBP;11 4 | 1a556b11-867d-46c7-ab8d-85cf65b5562f;The Raven;"""The Raven"" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word ""Nevermore"". The poem makes use of folk, mythological, religious, and classical references.";150;57;13.13;USD;16 5 | 33bf8277-a95c-4192-8b5a-ebb5ba3b2334;Eleonora;"""Eleonora"" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively ""happy"" ending.";150;100;14;USD;16 6 | 5d885fd3-7b6a-48d5-b8a6-074bcc3b2c32;Catweazle;Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.;170;22;150;JPY;13 7 | -------------------------------------------------------------------------------- /bookshop/db/data/codejam-Books_texts.csv: -------------------------------------------------------------------------------- 1 | ID;locale;title;descr 2 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;de;Sturmhöhe;Sturmhöhe (Originaltitel: Wuthering Heights) ist der einzige Roman der englischen Schriftstellerin Emily Brontë (1818–1848). Der 1847 unter dem Pseudonym Ellis Bell veröffentlichte Roman wurde vom viktorianischen Publikum weitgehend abgelehnt, heute gilt er als ein Klassiker der britischen Romanliteratur des 19. Jahrhunderts. 3 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;fr;Les Hauts de Hurlevent;Les Hauts de Hurlevent (titre original : Wuthering Heights), parfois orthographié Les Hauts de Hurle-Vent, est l'unique roman d'Emily Brontë, publié pour la première fois en 1847 sous le pseudonyme d’Ellis Bell. Loin d'être un récit moralisateur, Emily Brontë achève néanmoins le roman dans une atmosphère sereine, suggérant le triomphe de la paix et du Bien sur la vengeance et le Mal. 4 | fda402ba-7083-4d42-a0c7-ecd565b26eec;de;Jane Eyre;Jane Eyre. Eine Autobiographie (Originaltitel: Jane Eyre. An Autobiography), erstmals erschienen im Jahr 1847 unter dem Pseudonym Currer Bell, ist der erste veröffentlichte Roman der britischen Autorin Charlotte Brontë und ein Klassiker der viktorianischen Romanliteratur des 19. Jahrhunderts. Der Roman erzählt in Form einer Ich-Erzählung die Lebensgeschichte von Jane Eyre (ausgesprochen /ˌdʒeɪn ˈɛə/), die nach einer schweren Kindheit eine Stelle als Gouvernante annimmt und sich in ihren Arbeitgeber verliebt, jedoch immer wieder um ihre Freiheit und Selbstbestimmung kämpfen muss. Als klein, dünn, blass, stets schlicht dunkel gekleidet und mit strengem Mittelscheitel beschrieben, gilt die Heldin des Romans Jane Eyre nicht zuletzt aufgrund der Kino- und Fernsehversionen der melodramatischen Romanvorlage als die bekannteste englische Gouvernante der Literaturgeschichte 5 | 33bf8277-a95c-4192-8b5a-ebb5ba3b2334;de;Eleonora;“Eleonora” ist eine Erzählung von Edgar Allan Poe. Sie wurde 1841 erstveröffentlicht. In ihr geht es um das Paradox der Treue in der Treulosigkeit. 6 | -------------------------------------------------------------------------------- /bookshop/db/data/codejam-Genres.csv: -------------------------------------------------------------------------------- 1 | ID;parent_ID;name 2 | 10;;Fiction 3 | 11;10;Drama 4 | 12;10;Poetry 5 | 13;10;Fantasy 6 | 14;10;Science Fiction 7 | 15;10;Romance 8 | 16;10;Mystery 9 | 17;10;Thriller 10 | 18;10;Dystopia 11 | 19;10;Fairy Tale 12 | 20;;Non-Fiction 13 | 21;20;Biography 14 | 22;21;Autobiography 15 | 23;20;Essay 16 | 24;20;Speech 17 | -------------------------------------------------------------------------------- /bookshop/db/data/codejam-Sales.csv: -------------------------------------------------------------------------------- 1 | book_ID;dateTime;price;currency_code 2 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;2024-07-01T06:49:45.420Z;11.11;GBP 3 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;2024-07-02T06:49:45.420Z;11.11;GBP 4 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;2024-07-02T08:49:45.420Z;11.11;GBP 5 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;2024-07-02T10:15:30.123Z;11.11;GBP 6 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;2024-07-02T12:15:30.123Z;11.11;GBP 7 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;2024-07-04T14:25:50.987Z;11.11;GBP 8 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;2024-07-04T16:25:50.987Z;11.11;GBP 9 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;2024-07-05T18:35:40.456Z;11.11;GBP 10 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;2024-07-05T20:35:40.456Z;11.11;GBP 11 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;2024-07-05T22:45:55.789Z;11.11;GBP 12 | fc48cd34-ef71-4e6f-bc31-ccbea3eae2e2;2024-07-05T23:45:55.789Z;11.11;GBP 13 | fda402ba-7083-4d42-a0c7-ecd565b26eec;2024-07-01T06:49:45.420Z;12.34;GBP 14 | fda402ba-7083-4d42-a0c7-ecd565b26eec;2024-07-03T06:49:45.420Z;12.34;GBP 15 | fda402ba-7083-4d42-a0c7-ecd565b26eec;2024-07-03T08:49:45.420Z;12.34;GBP 16 | fda402ba-7083-4d42-a0c7-ecd565b26eec;2024-07-03T10:15:30.123Z;12.34;GBP 17 | fda402ba-7083-4d42-a0c7-ecd565b26eec;2024-07-03T12:15:30.123Z;12.34;GBP 18 | fda402ba-7083-4d42-a0c7-ecd565b26eec;2024-07-04T14:25:50.987Z;12.34;GBP 19 | fda402ba-7083-4d42-a0c7-ecd565b26eec;2024-07-04T16:25:50.987Z;12.34;GBP 20 | fda402ba-7083-4d42-a0c7-ecd565b26eec;2024-07-05T18:35:40.456Z;12.34;GBP 21 | fda402ba-7083-4d42-a0c7-ecd565b26eec;2024-07-05T20:35:40.456Z;12.34;GBP 22 | fda402ba-7083-4d42-a0c7-ecd565b26eec;2024-07-05T22:45:55.789Z;12.34;GBP 23 | fda402ba-7083-4d42-a0c7-ecd565b26eec;2024-07-05T23:45:55.789Z;12.34;GBP 24 | 1a556b11-867d-46c7-ab8d-85cf65b5562f;2024-07-01T06:49:45.420Z;13.13;USD 25 | 1a556b11-867d-46c7-ab8d-85cf65b5562f;2024-07-01T06:49:45.420Z;13.13;USD 26 | 1a556b11-867d-46c7-ab8d-85cf65b5562f;2024-07-01T08:49:45.420Z;13.13;USD 27 | 1a556b11-867d-46c7-ab8d-85cf65b5562f;2024-07-01T10:15:30.123Z;13.13;USD 28 | 1a556b11-867d-46c7-ab8d-85cf65b5562f;2024-07-01T12:15:30.123Z;13.13;USD 29 | 1a556b11-867d-46c7-ab8d-85cf65b5562f;2024-07-04T14:25:50.987Z;13.13;USD 30 | 1a556b11-867d-46c7-ab8d-85cf65b5562f;2024-07-04T16:25:50.987Z;13.13;USD 31 | 1a556b11-867d-46c7-ab8d-85cf65b5562f;2024-07-05T18:35:40.456Z;13.13;USD 32 | 1a556b11-867d-46c7-ab8d-85cf65b5562f;2024-07-05T20:35:40.456Z;13.13;USD 33 | 1a556b11-867d-46c7-ab8d-85cf65b5562f;2024-07-05T22:45:55.789Z;13.13;USD 34 | 1a556b11-867d-46c7-ab8d-85cf65b5562f;2024-07-05T23:45:55.789Z;13.13;USD 35 | 33bf8277-a95c-4192-8b5a-ebb5ba3b2334;2024-07-01T06:49:45.420Z;14.00;USD 36 | 33bf8277-a95c-4192-8b5a-ebb5ba3b2334;2024-07-02T06:49:45.420Z;14.00;USD 37 | 33bf8277-a95c-4192-8b5a-ebb5ba3b2334;2024-07-02T08:49:45.420Z;14.00;USD 38 | 33bf8277-a95c-4192-8b5a-ebb5ba3b2334;2024-07-03T10:15:30.123Z;14.00;USD 39 | 33bf8277-a95c-4192-8b5a-ebb5ba3b2334;2024-07-03T12:15:30.123Z;14.00;USD 40 | 33bf8277-a95c-4192-8b5a-ebb5ba3b2334;2024-07-04T14:25:50.987Z;14.00;USD 41 | 33bf8277-a95c-4192-8b5a-ebb5ba3b2334;2024-07-04T16:25:50.987Z;14.00;USD 42 | 33bf8277-a95c-4192-8b5a-ebb5ba3b2334;2024-07-05T18:35:40.456Z;14.00;USD 43 | 33bf8277-a95c-4192-8b5a-ebb5ba3b2334;2024-07-05T20:35:40.456Z;14.00;USD 44 | 33bf8277-a95c-4192-8b5a-ebb5ba3b2334;2024-07-05T22:45:55.789Z;14.00;USD 45 | 33bf8277-a95c-4192-8b5a-ebb5ba3b2334;2024-07-05T23:45:55.789Z;14.00;USD 46 | 5d885fd3-7b6a-48d5-b8a6-074bcc3b2c32;2024-07-01T06:49:45.420Z;150;JPY 47 | 5d885fd3-7b6a-48d5-b8a6-074bcc3b2c32;2024-07-01T06:49:45.420Z;150;JPY 48 | 5d885fd3-7b6a-48d5-b8a6-074bcc3b2c32;2024-07-02T08:49:45.420Z;150;JPY 49 | 5d885fd3-7b6a-48d5-b8a6-074bcc3b2c32;2024-07-03T10:15:30.123Z;150;JPY 50 | 5d885fd3-7b6a-48d5-b8a6-074bcc3b2c32;2024-07-03T12:15:30.123Z;150;JPY 51 | 5d885fd3-7b6a-48d5-b8a6-074bcc3b2c32;2024-07-02T14:25:50.987Z;150;JPY 52 | 5d885fd3-7b6a-48d5-b8a6-074bcc3b2c32;2024-07-05T16:25:50.987Z;150;JPY 53 | 5d885fd3-7b6a-48d5-b8a6-074bcc3b2c32;2024-07-05T18:35:40.456Z;150;JPY 54 | 5d885fd3-7b6a-48d5-b8a6-074bcc3b2c32;2024-07-05T20:35:40.456Z;150;JPY 55 | 5d885fd3-7b6a-48d5-b8a6-074bcc3b2c32;2024-07-05T22:45:55.789Z;150;JPY 56 | 5d885fd3-7b6a-48d5-b8a6-074bcc3b2c32;2024-07-05T23:45:55.789Z;150;JPY 57 | -------------------------------------------------------------------------------- /bookshop/db/data/sap.common-Currencies.csv: -------------------------------------------------------------------------------- 1 | code;symbol;name;descr;minorUnit 2 | EUR;€;Euro;European Euro;Cent 3 | USD;$;US Dollar;United States Dollar;Cent 4 | CAD;$;Canadian Dollar;Canadian Dollar;Cent 5 | AUD;$;Australian Dollar;Australian Dollar;Cent 6 | GBP;£;British Pound;Great Britain Pound;Penny 7 | ILS;₪;Shekel;Israeli New Shekel;Agorat 8 | INR;₹;Rupee;Indian Rupee;Paise 9 | QAR;﷼;Riyal;Katar Riyal;Dirham 10 | SAR;﷼;Riyal;Saudi Riyal;Halala 11 | JPY;¥;Yen;Japanese Yen;Sen 12 | CNY;¥;Yuan;Chinese Yuan Renminbi;Jiao 13 | SGD;S$;Singapore Dollar;Singapore Dollar;Cent 14 | TND;د.ت;Tunisian Dinar;Tunisian Dinar;Milim -------------------------------------------------------------------------------- /bookshop/db/schema.cds: -------------------------------------------------------------------------------- 1 | using { 2 | Currency, 3 | managed, 4 | cuid, 5 | sap 6 | } from '@sap/cds/common'; 7 | 8 | namespace codejam; 9 | 10 | entity Books : managed, cuid { 11 | title : localized String(111) @mandatory; 12 | descr : localized String(1111); 13 | author : Association to one Authors; 14 | genre : Association to one Genres; 15 | stock : Integer @mandatory; 16 | criticality : Integer; 17 | price : Decimal @(Measures.ISOCurrency: currency_code) @mandatory; 18 | currency : Currency; 19 | image : LargeBinary @Core.MediaType: 'image/png'; 20 | sales : Association to many Sales 21 | on sales.book = $self; 22 | } 23 | 24 | entity Authors : managed { 25 | key ID : Integer; 26 | name : String(111); 27 | dateOfBirth : Date; 28 | dateOfDeath : Date; 29 | placeOfBirth : String; 30 | placeOfDeath : String; 31 | books : Association to many Books 32 | on books.author = $self; 33 | } 34 | 35 | entity Sales : managed, cuid { 36 | book : Association to one Books; 37 | dateTime : DateTime; 38 | date : Date @title: 'Date'; 39 | price : Decimal @(Measures.ISOCurrency: currency_code) @mandatory; 40 | currency : Currency; 41 | } 42 | 43 | entity Genres : sap.common.CodeList { 44 | key ID : Integer; 45 | parent : Association to Genres; 46 | children : Composition of many Genres 47 | on children.parent = $self; 48 | } 49 | -------------------------------------------------------------------------------- /bookshop/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bookshop", 3 | "version": "1.0.0", 4 | "description": "A simple self-contained bookshop service.", 5 | "dependencies": { 6 | "@sap/cds": "^7.8.1" 7 | }, 8 | "devDependencies": { 9 | "@sap/cds-dk": "^7.8.1", 10 | "@cap-js/sqlite": "^1", 11 | "@sap/ux-specification": "^1.120.8", 12 | "cds-plugin-ui5": "^0.8.3" 13 | }, 14 | "scripts": { 15 | "start": "cds run", 16 | "dev": "cds watch" 17 | }, 18 | "cds": { 19 | "db": { 20 | "kind": "sql" 21 | } 22 | }, 23 | "sapux": [ 24 | "app/bookshop-ui" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /bookshop/srv/cat-service.cds: -------------------------------------------------------------------------------- 1 | using {codejam} from '../db/schema'; 2 | 3 | service CatalogService { 4 | entity Books as projection on codejam.Books actions { 5 | action submitOrder(quantity : Integer) returns { 6 | stock : Integer 7 | }; 8 | }; 9 | entity Sales as projection on codejam.Sales; 10 | entity Authors as projection on codejam.Authors; 11 | } 12 | -------------------------------------------------------------------------------- /bookshop/srv/cat-service.js: -------------------------------------------------------------------------------- 1 | const cds = require("@sap/cds") 2 | 3 | module.exports = function() { 4 | const { Books, Sales } = cds.entities("codejam") 5 | 6 | // reduce stock of ordered books if available stock suffices 7 | this.on("submitOrder", "Books", async (req) => { 8 | const { quantity } = req.data 9 | const book = req.params[0].ID || req.params[0] 10 | if (quantity < 1) return req.reject(400, `quantity has to be 1 or more`) 11 | let b = await SELECT.from(Books, book) 12 | if (!b) return req.error(404, `Book #${book} doesn't exist`) 13 | let { stock, price, currency_code } = b 14 | if (quantity > stock) return req.reject(409, `${quantity} exceeds stock for book #${book}`) 15 | await UPDATE(Books, book).with({ stock: stock -= quantity }) 16 | await INSERT.into(Sales).entries({ 17 | book_ID: book, 18 | dateTime: new Date().toISOString(), 19 | price: price * quantity, 20 | currency_code: currency_code 21 | }) 22 | return { stock } 23 | }) 24 | 25 | this.after("each", "Books", book => { 26 | if (book.stock >= 20) { 27 | book.criticality = 3 // Positive 28 | } else if (book.stock > 0) { 29 | book.criticality = 2 // Critical 30 | } else { 31 | book.criticality = 1 // Negative 32 | } 33 | }) 34 | 35 | // before handler to ensure aggregations can be calculated on db level 36 | this.before("READ", "Sales", async () => { 37 | const sales = await SELECT(Sales) 38 | for (const s of sales) { 39 | await UPDATE(Sales, s.ID).with({ 40 | date: s.dateTime.split("T")[0] 41 | }) 42 | } 43 | }) 44 | 45 | } 46 | -------------------------------------------------------------------------------- /chapters/00-prep-dev-environment/readme.md: -------------------------------------------------------------------------------- 1 | # Chapter 00 - Preparing the development environment 2 | 3 | By the end of this chapter we will have prepared our development environment so that we can start developing our application. 4 | 5 | ## Steps 6 | 7 | [1. Prerequisites](#1-prerequisites)
8 | [2. Navigate into your preferred directory](#2-navigate-into-your-preferred-directory)
9 | [3. Clone this repository](#3-clone-this-repository)
10 | [4. Navigate into the newly created directory](#4-navigate-into-the-newly-created-directory)
11 | [5. Open the directory](#5-open-the-directory)
12 | 13 | ## 1. Prerequisites 14 | 15 | To be able to follow the instructions in this repository you need to fulfill ***one*** of the following requirements: 16 | 17 | - **Option 1:** You have access to the SAP Business Application Studio with the role collection `Business_Application_Studio_Developer` assigned to you in the SAP Business Technology Platform Cockpit. Create a new dev space of type `Full Stack Cloud Application` to get started. 18 | 19 | > If you don't have access to the SAP Business Application Studio yet, check this tutorial on [how to get a free account on SAP BTP trial](https://developers.sap.com/tutorials/hcp-create-trial-account.html), from where you can [subscribe to the SAP Business Application Studio](https://developers.sap.com/tutorials/appstudio-onboarding.html). 20 | 21 | - **Option 2:** You can use Visual Studio Code on your local machine. This is the complete list of tools you will need: 22 | - [Visual Studio Code](https://code.visualstudio.com/download) 23 | - [SAP Fiori Tools - Extension Pack](https://marketplace.visualstudio.com/items?itemName=SAPSE.sap-ux-fiori-tools-extension-pack) (Visual Studio Code extension) 24 | - [Node.js](https://nodejs.org/en/) (version 18 or higher) including `npm` 25 | - [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) 26 | - You need privileges to install `npm` packages from the [npm registry](https://www.npmjs.com/) 27 | 28 | ## 2. Navigate into your preferred directory 29 | 30 | ➡️ In your development environment (see [step 1](#1-prerequisites)), open a new terminal session and navigate to where you want to store this repository. 31 | 32 | In case you are not familiar with navigation via the terminal, check out this [article](https://help.dreamhost.com/hc/en-us/articles/215465297-UNIX-commands-Working-with-directories). 33 | 34 | ## 3. Clone this repository 35 | 36 | ➡️ Execute the following command to clone this repository: 37 | 38 | ```bash 39 | git clone https://github.com/SAP-samples/fiori-elements-fpm-exercises-codejam 40 | ``` 41 | 42 | We succesfully cloned this repository, for which a new directory has been created. 43 | 44 | ## 4. Navigate into the newly created directory 45 | 46 | We want to navigate into the `bookshop/` directory inside newly created directory, as this is where we will build our application. 47 | 48 | ➡️ Execute the following command in the same terminal session: 49 | 50 | ```bash 51 | cd fiori-elements-fpm-exercises-codejam/bookshop 52 | ``` 53 | 54 | ## 5. Open the directory 55 | 56 | ➡️ Open the directory in the code editor of your choice, depending on the option you chose in [step 1](#1-prerequisites). 57 | 58 | Continue to [Chapter 01 - Running the SAP CAP application](/chapters/01-run-cap-app/) 59 | -------------------------------------------------------------------------------- /chapters/01-run-cap-app/data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP-samples/fiori-elements-fpm-exercises-codejam/9207b7fc262add0babb02c85b467279335977255/chapters/01-run-cap-app/data.png -------------------------------------------------------------------------------- /chapters/01-run-cap-app/readme.md: -------------------------------------------------------------------------------- 1 | # Chapter 01 - Running the SAP CAP application 2 | 3 | By the end of this chapter we will have inspected and ran our existing SAP CAP backend application. 4 | 5 | ## Steps 6 | 7 | [0. Make sure you are in the project root (`bookshop/`)](#0-make-sure-you-are-in-the-project-root-bookshop)
8 | [1. Inspect the existing SAP CAP application](#1-inspect-the-existing-sap-cap-application)
9 | [2. Install the project dependencies](#2-install-the-project-dependencies)
10 | 11 | ## 0. Make sure you are in the project root (`bookshop/`) 12 | 13 | ➡️ Make sure you are in the `bookshop/` directory, which is our project root. 14 | 15 | The material in this repository will always reference directories and files in relation to this project root. 16 | 17 | ## 1. Inspect the existing SAP CAP application 18 | 19 | Our project already contains quite a few directories and files, which give us a head start for developing our Fiori elements application. Our existing project contains an [SAP Cloud Application Programming Model](cap.cloud.sap) (SAP CAP) application that implements a bookshop backend service. It was built with the Node.js flavour of SAP CAP. 20 | 21 | A little bit about the structure of our bookshop service (and SAP CAP applications in general): 22 | 23 | - The [package.json](/bookshop/package.json) declares the Node.js application's dependencies and other metadata. This file is not specific to SAP CAP - all Node.js based applications need a `package.json`. 24 | - The [db/](/bookshop/db/) directory represents the database layer of the backend, defining all entities (think "tables") as well as the association between them. 25 | - The [srv/](/bookshop/srv/) directory represents the service layer of the backend, which is the API our frontend application will be interacting with. 26 | - The [app/](/bookshop/app/) directory is empty (or non-existing) as of now. This is typically where frontend applications reside. We will create our SAP Fiori elements application in this directory as well. 27 | 28 | ## 2. Install the project dependencies 29 | 30 | ➡️ Run the following command from the `bookshop/` directory: 31 | 32 | ```bash 33 | npm install 34 | ``` 35 | 36 | We installed the project dependencies declared in the `package.json` file, which generated a new `package-lock.json` file as well as a `node_modules/` directory, where the actual dependencies reside. 37 | 38 | ## 3. Run the SAP CAP application 39 | 40 | ➡️ Run the following command from the `bookshop/` directory: 41 | 42 | ```bash 43 | npm run dev 44 | ``` 45 | 46 | By running the above command we executed the `dev` script defined in the `package.json` file. This script is `cds watch` - meaning that `npm run dev` works like an alias for `cds watch` in this case. `cds watch` is a command of the [`@sap/cds-dk`](https://www.npmjs.com/package/@sap/cds-dk) ("cds development kit") and starts our SAP CAP application in watch mode - meaning that it tracks file changes and restarts the server upon changes, which is very helpful during development. 47 | 48 | The SAP CAP server is now running and accessible via a URL: 49 | 50 | ![http://localhost:4004](server.png) 51 | 52 | ## 4. Test the bookshop service 53 | 54 | ➡️ Test the bookshop service by visiting the URL of the SAP CAP server. Click on any entity to view the raw data (pretty printed in this screen shot): 55 | 56 | ![Raw data](data.png) 57 | 58 | Continue to [Chapter 02 - Creating the SAP Fiori elements application](/chapters/02-create-fe-app/) 59 | -------------------------------------------------------------------------------- /chapters/01-run-cap-app/server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP-samples/fiori-elements-fpm-exercises-codejam/9207b7fc262add0babb02c85b467279335977255/chapters/01-run-cap-app/server.png -------------------------------------------------------------------------------- /chapters/02-create-fe-app/app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP-samples/fiori-elements-fpm-exercises-codejam/9207b7fc262add0babb02c85b467279335977255/chapters/02-create-fe-app/app.png -------------------------------------------------------------------------------- /chapters/02-create-fe-app/command-palette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP-samples/fiori-elements-fpm-exercises-codejam/9207b7fc262add0babb02c85b467279335977255/chapters/02-create-fe-app/command-palette.png -------------------------------------------------------------------------------- /chapters/02-create-fe-app/readme.md: -------------------------------------------------------------------------------- 1 | # Chapter 02 - Creating the SAP Fiori elements application 2 | 3 | By the end of this chapter we will have created an SAP Fiori elements application that consumes our bookshop backend service. 4 | 5 | ## Steps 6 | 7 | [1. Launch the SAP Fiori Tools Application Generator](#1-launch-the-sap-fiori-tools-application-generator)
8 | [2. Create an SAP Fiori elements application](#2-create-an-sap-fiori-elements-application)
9 | [3. Inspect the newly created application](#3-inspect-the-newly-created-application)
10 | [4. Start the SAP CAP server](#4-start-the-sap-cap-server)
11 | [5. Test the SAP Fiori elements application](#5-test-the-sap-fiori-elements-application)
12 | [6. Further questions to discuss](#6-further-questions-to-discuss)
13 | 14 | ## 1. Launch the SAP Fiori Tools Application Generator 15 | 16 | The [SAP Fiori Tools](https://marketplace.visualstudio.com/items?itemName=SAPSE.sap-ux-fiori-tools-extension-pack) is an extension pack for Visual Studio Code that bundles extensions that help with SAP Fiori development. We will use it extensively during this SAP CodeJam - starting with the creation of an SAP Fiori elements application. If you have not installed the SAP Fiori Tools yet, go back and work through [chapter 0](/chapters/00-prep-dev-environment/). 17 | 18 | ➡️ Open the command palette (Command/Ctrl + Shift + P), search for "Application Generator", and launch the SAP Fiori Tools Application Generator: 19 | 20 | ![command palette](command-palette.png) 21 | 22 | ## 2. Create an SAP Fiori elements application 23 | 24 | ➡️ Create an application using the following settings and properties for the template wizard: 25 | 26 | ||| 27 | | - | - | 28 | | Template Type | SAP Fiori | 29 | | Which template do you want to use? | List Report Page | 30 | | Data source | Use a Local CAP Project | 31 | | Choose your CAP project | bookshop | 32 | | OData service | CatalogService (Node.js) | 33 | | Main entity | Books | 34 | | Navigation entity | None | 35 | | Automatically add table columns to the list page and a section to the object page if none already exists? | Yes | 36 | | Module name | bookshop-ui | 37 | | Application title | Bookshop | 38 | | Application namespace | *leave empty* | 39 | | Description | A simple bookshop application. | 40 | | Minimum SAPUI5 version | *choose latest patch of version **1.120*** | 41 | | Add deployment configuration to MTA project | No | 42 | | Add FLP configuration | No | 43 | | Configure advanced options | No 44 | 45 | We created a new SAP Fiori elements application that consumes the bookshop backend service from our local SAP CAP application. We selected `Books` as the main entity. Let's now inspect this new application. 46 | 47 | ## 3. Inspect the newly created application 48 | 49 | ➡️ Open the `app/bookshop-ui/` directory and inspect its contents. 50 | 51 | If you are familiar with UI5, you will recognize this project structure immediately (if you are not, check out this repository: [ui5-exercise-codejam](https://github.com/SAP-Samples/ui5-exercises-codejam)): 52 | - The `webapp/` directory contains the actual web application - most importantly the `Component.js`, `index.html`, and `manifest.json`. 53 | - The `app/bookshop-ui/` directory also contains its own `package.json`, which means it is a Node.js based application. It's a common practice to have nested Node.js applications during design time. 54 | - The `app/bookshop-ui/` directory also contains a `ui5.yaml`, which allows us to configure the [UI5 Tooling](https://www.npmjs.com/package/@ui5/cli). 55 | 56 | This project structure begs the question: What is the difference between a (freestyle) UI5 application and an SAP Fiori elements application? 57 | 58 | > An SAP Fiori elements application is a certain kind of UI5 application that uses a predefined [floorplan](https://ui5.sap.com/#/topic/797c3239b2a9491fa137e4998fd76aa7.html) (think "application layout") - following a metadata-driven approach. Technically speaking, an SAP Fiori elements application uses the `sap/fe/core/AppComponent` from the SAPUI5 library. This means every SAP Fiori elements application is a UI5 application, but not vice versa. The opposite of an SAP Fiori elements application is a freestyle UI5 application, which implements its own custom layout (views) and application logic (controllers). The situation is not exactly black and white, however, as the [SAP Fiori elements flexible programming model](https://sapui5.hana.ondemand.com/test-resources/sap/fe/core/fpmExplorer/index.html#/overview/introduction) provides metadata-driven building blocks that can be used alongside freestyle UI5 coding. This set of exercises is dedicated to this powerful feature that combines the best of both worlds. 59 | 60 | ## 4. Start the SAP CAP server 61 | 62 | ➡️ (Re)start the SAP CAP server by running the following command from the `bookshop/` directory: 63 | 64 | ```bash 65 | npm run dev 66 | ``` 67 | 68 | We (re)started the SAP CAP server - just like in the previous chapter. There is one small difference to note though: The logs now include the following:f 69 | message, which indicates the SAP CAP server now also serves our frontend application with the help of the [`cds-plugin-ui5`](https://www.npmjs.com/package/cds-plugin-ui5): 70 | 71 | ```text 72 | [cds-plugin-ui5] [info] Mounting /bookshopui to UI5 app ... 73 | ``` 74 | 75 | ## 5. Test the SAP Fiori elements application 76 | 77 | ➡️ (Re)visit the URL of the SAP CAP server, refresh the page, and click on the link for the `/bookshopui/index.html` application: 78 | 79 | ![http://localhost:4004](server.png) 80 | ![SAP Fiori elements application](app.png) 81 | 82 | We created a fully functional SAP Fiori elements application. Feel free to play around with the application - click "Go", then click one of the books in the table to navigate to its object page. 83 | 84 | ## 6. Further questions to discuss 85 | 86 | ➡️ If you happen to finish this chapter early, think about the following questions (that we will discuss later): 87 | 88 | - Why was there no option in the template wizard to use OpenUI5 instead of SAPUI5? 89 | - How does the SAP CAP server know it should serve the newly created SAP Fiori elements application? 90 | - What is the benefit of using the [`cds-plugin-ui5`](https://www.npmjs.com/package/cds-plugin-ui5)? 91 | 92 | Continue to [Chapter 03 - Creating a custom section via an extension point](/chapters/03-custom-section-via-extension-point/) 93 | -------------------------------------------------------------------------------- /chapters/02-create-fe-app/server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP-samples/fiori-elements-fpm-exercises-codejam/9207b7fc262add0babb02c85b467279335977255/chapters/02-create-fe-app/server.png -------------------------------------------------------------------------------- /chapters/03-custom-section-via-extension-point/command-palette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP-samples/fiori-elements-fpm-exercises-codejam/9207b7fc262add0babb02c85b467279335977255/chapters/03-custom-section-via-extension-point/command-palette.png -------------------------------------------------------------------------------- /chapters/03-custom-section-via-extension-point/custom-section.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP-samples/fiori-elements-fpm-exercises-codejam/9207b7fc262add0babb02c85b467279335977255/chapters/03-custom-section-via-extension-point/custom-section.png -------------------------------------------------------------------------------- /chapters/03-custom-section-via-extension-point/object-page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP-samples/fiori-elements-fpm-exercises-codejam/9207b7fc262add0babb02c85b467279335977255/chapters/03-custom-section-via-extension-point/object-page.png -------------------------------------------------------------------------------- /chapters/03-custom-section-via-extension-point/page-map1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP-samples/fiori-elements-fpm-exercises-codejam/9207b7fc262add0babb02c85b467279335977255/chapters/03-custom-section-via-extension-point/page-map1.png -------------------------------------------------------------------------------- /chapters/03-custom-section-via-extension-point/page-map2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP-samples/fiori-elements-fpm-exercises-codejam/9207b7fc262add0babb02c85b467279335977255/chapters/03-custom-section-via-extension-point/page-map2.png -------------------------------------------------------------------------------- /chapters/03-custom-section-via-extension-point/readme.md: -------------------------------------------------------------------------------- 1 | # Chapter 03 - Creating a custom section via an extension point 2 | 3 | By the end of this chapter, we will have created a custom section in the SAP Fiori elements application using one of the available extension points. 4 | 5 | ## Steps 6 | 7 | - [1. Launch the SAP Fiori Tools Page Map](#1-launch-the-sap-fiori-tools-page-map)
8 | - [2. Edit the object page](#2-edit-the-object-page)
9 | - [3. Create a new custom section](#3-create-a-new-custom-section)
10 | - [4. Enter properties for new custom section](#4-enter-properties-for-new-custom-section)
11 | - [5. Inspect the new custom section](#5-inspect-the-new-custom-section)
12 | - [6. Test the new custom section](#6-test-the-new-custom-section)
13 | - [7. Further questions to discuss](#7-further-questions-to-discuss)
14 | 15 | ## 1. Launch the SAP Fiori Tools Page Map 16 | 17 | For this chapter we use another one of the extension of the SAP Fiori Tools: the Page Map. The Page Map allows us to edit and visualize the pages of our application as well as their navigation flow. 18 | 19 | ➡️ Open the command palette (Command/Ctrl + Shift + P), search for "Page Map", and launch the SAP Fiori Tools Page Map: 20 | 21 | ![command palette](command-palette.png) 22 | 23 | ## 2. Edit the object page 24 | 25 | ➡️ Click the pencil icon of the object page to edit it: 26 | 27 | ![Page Map 1](page-map1.png) 28 | 29 | ## 3. Create a new custom section 30 | 31 | ➡️ Click the plus icon in the "Sections" area of the Page Map to create a new custom section: 32 | 33 | ![Page Map 2](page-map2.png) 34 | 35 | ## 4. Enter properties for new custom section 36 | 37 | ➡️ Enter the following properties for the new custom section and click "Add": 38 | 39 | ![custom section](custom-section.png) 40 | 41 | We have created a new custom section using one of the available [extension points](https://sapui5.hana.ondemand.com/test-resources/sap/fe/core/fpmExplorer/index.html#/customElements/customElementsOverview) of the SAP Fiori elements flexible programming model. This custom section extension point allows us to have a walled playground for freestyle UI5 development within an SAP Fiori elements application. Let's inspect the generated artifacts. 42 | 43 | ## 5. Inspect the new custom section 44 | 45 | ➡️ Inspect the `app/bookshop-ui/webapp/ext/fragment` directory and its contents. 46 | 47 | The SAP Fiori Tools generated this new directory that includes an XML fragment as well as the corresponding JavaScript handler. These files allow for custom coding of any sort. The custom section is loaded into the application via the `manifest.json`, where its metadata (like path, position, and title) is maintained. Take a moment to stare at this code, which is part of the `manifest.json`: 48 | 49 | ```json 50 | "BooksObjectPage": { 51 | "type": "Component", 52 | "id": "BooksObjectPage", 53 | "name": "sap.fe.templates.ObjectPage", 54 | "options": { 55 | "settings": { 56 | "editableHeaderContent": false, 57 | "entitySet": "Books", 58 | "content": { 59 | "body": { 60 | "sections": { 61 | "Order": { 62 | "template": "bookshopui.ext.fragment.Order", 63 | "position": { 64 | "placement": "After", 65 | "anchor": "GeneratedFacet1" 66 | }, 67 | "title": "Order", 68 | "type": "XMLFragment" 69 | } 70 | } 71 | } 72 | } 73 | } 74 | }, 75 | "controlAggregation": "midColumnPages", 76 | "contextPattern": "/Books({key})" 77 | } 78 | 79 | ``` 80 | 81 | ## 6. Test the new custom section 82 | 83 | ➡️ (Re)visit the URL of the SAP CAP server and refresh the page. Click "Go", then click one of the books in the table to navigate to its object page and see the custom section: 84 | 85 | ![object page](object-page.png) 86 | 87 | ## 7. Further questions to discuss 88 | 89 | ➡️ If you happen to finish this chapter early, think about the following questions (that we will discuss later): 90 | 91 | - What other common use-cases are there for XML fragments, apart from custom sections? 92 | - What is a `manifest.json`? Is this file specific to UI5? 93 | - How do you personally like the experience using the SAP Fiori Tools so far? (There is no right or wrong answer to this question.) 94 | 95 | Continue to [Chapter 04 - Using a JavaScript handler](/chapters/04-handler/) 96 | -------------------------------------------------------------------------------- /chapters/04-handler/object-page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SAP-samples/fiori-elements-fpm-exercises-codejam/9207b7fc262add0babb02c85b467279335977255/chapters/04-handler/object-page.png -------------------------------------------------------------------------------- /chapters/04-handler/readme.md: -------------------------------------------------------------------------------- 1 | # Chapter 04 - Using the JavaScript handler 2 | 3 | By the end of this chapter, we will have implemented the order feature of the bookshop using the JavaScript handler of our custom section. 4 | 5 | ## Steps 6 | 7 | - [1. Inspect the XML fragment](#1-inspect-the-xml-fragment)
8 | - [2. Add UI controls to the XML fragment](#2-add-ui-controls-to-the-xml-fragment)
9 | - [3. Implement the `.onSubmitOrder` method](#3-implement-the-onsubmitorder-method)
10 | - [4. Test the order feature](#4-test-the-order-feature)
11 | - [5. Further questions to discuss](#5-further-questions-to-discuss)
12 | 13 | ## 1. Inspect the XML fragment 14 | 15 | Before we implement the order feature, we want to make sure we really understand how the XML fragment currently works and how it loads its JavaScript handler. 16 | 17 | ➡️ Open the `app/bookshop-ui/webapp/ext/fragment/Order.fragment.xml` file and inspect its content. 18 | 19 | The XML fragment consists of a simple vertical box (``) and a button (`