You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: steps/01/README.md
+13-2Lines changed: 13 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,12 +15,23 @@ As you know OpenUI5 is all about HTML5. Let's get started with building a first
15
15
16
16
You can access the live preview by clicking on this link: [🔗 Live Preview of Step 1](https://sap-samples.github.io/ui5-typescript-walkthrough/build/01/index.html).
17
17
18
-
Download solution for step 1 in [📥 TypeScript](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-01.zip) or [📥 JavaScript](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-01-js.zip).
19
-
20
18
***
21
19
22
20
### Coding
23
21
22
+
<detailsclass="ts-only">
23
+
24
+
You can download the solution for this step here: [📥 Download step 1](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-01.zip).
25
+
26
+
</details>
27
+
28
+
<detailsclass="js-only">
29
+
30
+
You can download the solution for this step here: [📥 Download step 1](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-01-js.zip).
31
+
32
+
</details>
33
+
34
+
24
35
### webapp \(New\)
25
36
26
37
We create a folder on our local machine which will contain all the sources of the app we're going to build. We'll refer to this folder as the “app root directory".
Copy file name to clipboardExpand all lines: steps/02/README.md
+70-16Lines changed: 70 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,11 +15,23 @@ Before we can do something with OpenUI5, we need to load and initialize it. This
15
15
16
16
You can access the live preview by clicking on this link: [🔗 Live Preview of Step 2](https://sap-samples.github.io/ui5-typescript-walkthrough/build/02/index-cdn.html).
17
17
18
-
Download solution for step 2 in [📥 TypeScript](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-02.zip) or [📥 JavaScript](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-02-js.zip).
19
-
20
18
***
19
+
### Coding
20
+
21
+
<detailsclass="ts-only">
22
+
23
+
You can download the solution for this step here: [📥 Download step 2](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-02.zip).
24
+
25
+
</details>
26
+
27
+
<detailsclass="js-only">
21
28
22
-
### Tooling
29
+
You can download the solution for this step here: [📥 Download step 2](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-02-js.zip).
30
+
31
+
</details>
32
+
33
+
34
+
### UI5 Tooling
23
35
24
36
First, let's set up our UI5 Tooling to use the OpenUI5 framework for our project. We also need to add the necessary OpenUI5 libraries as dependencies to the project's UI5 Tooling configuration.
The `ui5 add` command adds specific libraries as dependency to the projects UI5 Tooling configuration. In this case, we'e adding the `sap.ui.core` library, which provides core functionality of the OpenUI5 framework. This library is essential for bootstrapping OpenUI5. Additionally, we're adding the `themelib_sap_horizon` library which provides the visual styles for the Horizon theme. We'll use this theme with our application.
39
51
40
-
***
41
52
42
-
### package.json
53
+
<detailsclass="ts-only">
54
+
43
55
44
56
To work with TypeScript, we must install it in our project. To do this, we execute the following command in the terminal:
45
57
58
+
46
59
```sh
47
60
npm install typescript --save-dev
48
61
```
49
62
50
63
By running this command, npm will download the TypeScript package from the npm registry and install it in our project's "node_modules" directory. It will also add an entry for TypeScript in the "devDependencies" section of our package.json file, so that other developers working on the project can easily install the same version of TypeScript.
51
64
52
-
***
53
65
54
66
### tsconfig.json \(New\)
55
67
56
68
As a next step, we need to create the file `tsconfig.json` in the app root directory to indicate that this folder is the root of a TypeScript project. This file specifies various compiler options and project settings that affect how TypeScript code is compiled into JavaScript.
57
69
58
70
We specify the compiler options as follow:
59
71
72
+
60
73
```json
61
74
{
62
75
"compilerOptions": {
@@ -101,17 +114,19 @@ Let's go through the compiler options specified in the file:
101
114
102
115
***
103
116
104
-
### Coding
117
+
</details>
105
118
106
-
### webapp/index.ts\(New\)
119
+
### webapp/index.?s\(New\)
107
120
108
-
Now let's move on to the UI work. We create a new `index.ts` script in the webapp folder. In this script, we add a native `alert()` method with the message "UI5 is ready".
121
+
Now let's move on to the UI work. We create a new `index.?s` script in the webapp folder. In this script, we add a native `alert()` method with the message "UI5 is ready".
109
122
110
123
```ts
111
124
alert("UI5 is ready");
112
125
```
113
126
114
-
***
127
+
```js
128
+
alert("UI5 is ready");
129
+
```
115
130
116
131
### webapp/index.html
117
132
@@ -157,22 +172,30 @@ We initialize the core modules with the following configuration options:
157
172
</html>
158
173
```
159
174
160
-
> 📝 **Note:**
175
+
> 📝 **Note:**<br>
161
176
> The namespace is a unique identifier for your application file. It helps prevent naming conflicts with other modules or libraries.
162
177
163
178
***
164
179
165
-
### Tooling
166
-
167
-
### package.json
180
+
### UI5 Tooling
168
181
169
182
Let's enhance our tooling setup once again by installing some custom middleware for the ui5-server. This will help us handle our development project more efficiently.
170
183
171
184
We open a terminal and navigate to the root folder of our app. Then, we execute the following command:
When you run the command, npm will download the specified packages from the npm registry and store them in a folder called `node_modules` within your project directory. The `--save-dev` flag instructs npm to save these packages as development dependencies in the `devDependencies` section of the `package.json` file. Development dependencies are packages that are only needed during development and not in production. By separating them from production dependencies, we can keep our project clean and ensure that only the required packages are included when deploying the application.
178
201
@@ -182,21 +205,28 @@ Let's break down what each package does:
182
205
183
206
-`ui5-middleware-serveframework` is another middleware plugin for the UI5 Tooling that provides a web server to serve your OpenUI5 project during development. It allows you to easily serve the necessary OpenUI5 libraries and resources required by your application from your development environment.
184
207
208
+
<detailsclass="ts-only">
209
+
185
210
-`ui5-tooling-transpile` is a plugin for the UI5 Tooling that transpiles modern JavaScript (ES6+) and TypeScript into a compatible version for OpenUI5. OpenUI5 is based on older versions of JavaScript, so this plugin allows you to take advantage of the latest language features and syntax while ensuring that your code remains compatible with OpenUI5.
186
211
187
-
***
212
+
</details>
188
213
189
214
### ui5.yaml
190
215
191
216
Next, we have to configure the tooling extension we installed from npm to our UI5 Tooling setup, so we can use them in our project. To hook a custom task into a certain build phase of a project, it needs to reference another task that will get executed before or after it. The same applies for a custom middleware:
217
+
<detailsclass="ts-only">
192
218
193
219
- For the `ui5-tooling-transpile-task` we specify that this should happen after the`replaceVersion` task.
194
220
221
+
</details>
222
+
195
223
- All our custom middleware extensions will be called after the `compression` middleware.
196
224
197
225
> 📌 **Important:** <br>
198
226
> Middleware configurations are applied in the order in which they are defined.
199
227
228
+
<detailsclass="ts-only">
229
+
200
230
```yaml
201
231
framework:
202
232
name: OpenUI5
@@ -219,7 +249,31 @@ server:
219
249
```
220
250
Now you can benefit from live reload on changes, built framework resources at development time, and make use of TypeScript in OpenUI5.
221
251
222
-
> 📝 **Note:** <br>
252
+
</details>
253
+
254
+
<details class="js-only">
255
+
256
+
```yaml
257
+
framework:
258
+
name: OpenUI5
259
+
version: "1.132.1"
260
+
libraries:
261
+
- name: sap.ui.core
262
+
- name: themelib_sap_horizon
263
+
builder:
264
+
server:
265
+
customMiddleware:
266
+
- name: ui5-middleware-serveframework
267
+
afterMiddleware: compression
268
+
- name: ui5-middleware-livereload
269
+
afterMiddleware: compression
270
+
```
271
+
Now you can benefit from live reload on changes and built framework resources at development time.
272
+
273
+
</details>
274
+
275
+
<br>
276
+
> 📝 **Note:**<br>
223
277
> During its initial run, the `ui5-middleware-serveframework` middleware will build the framework, which can take a while. In all following steps, the build will not happen again and the framework is served from the built resources.
Copy file name to clipboardExpand all lines: steps/03/README.md
+59-12Lines changed: 59 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
## Step 3: Controls
2
2
3
-
Now it is time to build our first little UI by replacing the “Hello World” text in the HTML body by the OpenUI5 control `sap/m/Text`. In the beginning, we will use the TypeScript control API to set up the UI, the control instance is then placed into the HTML body.
3
+
Now it is time to build our first little UI by replacing the “Hello World” text in the HTML body by the OpenUI5 control `sap/m/Text`. In the beginning, we will create an OpenUI5 control instance and place into the HTML body.
4
4
5
5
6
6
@@ -15,13 +15,23 @@ Now it is time to build our first little UI by replacing the “Hello World” t
15
15
16
16
You can access the live preview by clicking on this link: [🔗 Live Preview of Step 3](https://sap-samples.github.io/ui5-typescript-walkthrough/build/03/index-cdn.html).
17
17
18
-
Download solution for step 3 in [📥 TypeScript](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-03.zip) or [📥 JavaScript](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-03-js.zip).
19
-
20
18
***
19
+
### Coding
20
+
<detailsclass="ts-only">
21
+
22
+
You can download the solution for this step here: [📥 Download step 3](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-03.zip).
23
+
24
+
</details>
21
25
22
-
### Tooling
26
+
<detailsclass="js-only">
23
27
24
-
### package.json
28
+
You can download the solution for this step here: [📥 Download step 3](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-03-js.zip).
29
+
30
+
</details>
31
+
32
+
<detailsclass="ts-only">
33
+
34
+
### UI5 Tooling
25
35
26
36
To get the type definitions for OpenUI5, we need to install them to our project. We open a terminal in the root folder of our app and exectue the following command:
We will replace the native script in our file with the OpenUI5 Text control displaying "Hello Word".
51
+
For this, we will create a new instance of the Text control, setting its `text` property to "Hello World" by passing it as an object to the constructor.
52
+
53
+
</details>
54
+
55
+
<detailsclass="js-only">
56
+
57
+
We will replace the native script in our file with the OpenUI5 Text control displaying "Hello Word".
58
+
For this, we will first use OpenUI5's module definition `sap.ui.define` to create a module. To instantiate and render the Text control, we will define the `sap/m/Text` module as a dependency to this module. We will then create a new instance of the Text control and set its `text` property to "Hello World".
35
59
36
-
### webapp/index.ts
60
+
</details>
37
61
38
-
Now we make some changes to our `index.ts` file: We remove the alert method and instantiate an OpenUI5 text control instead. We create an instance of the text control by passing its options as a TypeScript object to the constructor. In our case, we want the text control to display the message "Hello World", so we'll set the `text` property accordingly.
62
+
To place the text control to our HTML document, we chain the constructor call of the control with the `placeAt` method. This method is used to position OpenUI5 controls. In our case, we add the Text control to the DOM element with the ID `content`.
39
63
40
-
To place the text control to our HTML document, we chain the constructor call of the control with the `placeAt` method. This method is used to position OpenUI5 controls. In our case, we add the text control to the DOM element with the ID `content`.
64
+
<detailsclass="js-only">
65
+
66
+
> 📌 **Important:** <br>
67
+
> It is best practice to use of Anynchronous Module Loading (AMD) style for defining modules and their dependencies. This ensures better performance, proper dependency tracking between modules and helps avoid issues related to loading order.
68
+
69
+
</details>
41
70
42
71
```ts
43
72
importTextfrom"sap/m/Text";
@@ -47,7 +76,15 @@ new Text({
47
76
}).placeAt("content");
48
77
```
49
78
50
-
Controls are used to define appearance and behavior of parts of the screen.
79
+
```js
80
+
sap.ui.define(["sap/m/Text"], function (Text) {
81
+
"use strict";
82
+
83
+
newText({
84
+
text:"Hello World"
85
+
}).placeAt("content");
86
+
});
87
+
```
51
88
52
89
All controls of OpenUI5 have a fixed set of properties, aggregations, and associations for configuration. You can find their descriptions in the Demo Kit. In addition, each control comes with a set of public functions that you can look up in the API reference.
53
90
@@ -112,8 +149,6 @@ ui5 add sap.m
112
149
113
150
**Related Information**
114
151
115
-
[TypeScript definitions for OpenUI5](https://www.npmjs.com/package/@types/openui5)
116
-
117
152
[Working with Controls](https://sdk.openui5.org/topic/91f0a22d6f4d1014b6dd926db0e91070.html"Controls are used to define the appearance and behavior of screen areas.")
[TypeScript definitions for OpenUI5](https://www.npmjs.com/package/@types/openui5)
167
+
168
+
</details>
169
+
170
+
<detailsclass="js-only">
171
+
172
+
[Best Practices for Loading Modules](https://sdk.openui5.org/topic/00737d6c1b864dc3ab72ef56611491c4"This section provides best practices for OpenUI5 module loading patterns.")
Copy file name to clipboardExpand all lines: steps/04/README.md
+30-4Lines changed: 30 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,12 +16,23 @@ When working with OpenUI5, we recommend the use of XML views, as this produces t
16
16
17
17
You can access the live preview by clicking on this link: [🔗 Live Preview of Step 4](https://sap-samples.github.io/ui5-typescript-walkthrough/build/04/index-cdn.html).
18
18
19
-
Download solution for step 4 in [📥 TypeScript](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-04.zip) or [📥 JavaScript](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-04-js.zip).
20
-
21
19
***
22
20
23
21
### Coding
24
22
23
+
<detailsclass="ts-only">
24
+
25
+
You can download the solution for this step here: [📥 Download step 4](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-04.zip).
26
+
27
+
</details>
28
+
29
+
<detailsclass="js-only">
30
+
31
+
You can download the solution for this step here: [📥 Download step 4](https://sap-samples.github.io/ui5-typescript-walkthrough/ui5-typescript-walkthrough-step-04-js.zip).
32
+
33
+
</details>
34
+
35
+
25
36
### webapp/view/App.view.xml \(New\)
26
37
27
38
We create a new folder called `view` inside the `webapp` folder. This folder will hold all our XML view files. Inside the `view` folder, we create a new file called `App.view.xml`. In OpenUI5, the root node of an XML view is the `<mvc:View>` tag. To use this tag, we need to declare the XML namespace `mvc`, which corresponds to the `sap.ui.core.mvc` namespace. This namespace provides classes for creating and working with views and other Model-View-Controller \(MVC\) assets. Additionally, we declare the default XML namespace to the `sap.m` namespace. This namespace contains the majority of OpenUI5's UI assets, including the `Text` control that we want to use with our view.
@@ -46,9 +57,9 @@ We have created an XML view that displays a text control with the text "Hello Wo
46
57
47
58
***
48
59
49
-
### webapp/index.ts
60
+
### webapp/index.?s
50
61
51
-
As a next step, we are going to replace the `sap/m/Text` control in our `index.ts` file with the app view that we've just created. To do this, we utilize the `XMLView.create` function, which is a part of the `sap/ui/core/mvc/View` module. This function needs a `viewName` property, which indicates the resource that needs to be loaded. The `viewName` is a combination of the namespace defined in the bootstrap and the path to the app view, but without the ".view.xml" extension. In addition, we set the `id` property to "app". Providing a stable ID is beneficial as it offers an easy and consistent way to identify and refer to specific views and elements in your code, thus helping to keep your code organized.
62
+
As a next step, we are going to replace the `sap/m/Text` control in our `index.?s` file with the app view that we've just created. To do this, we utilize the `XMLView.create` function, which is a part of the `sap/ui/core/mvc/View` module. This function needs a `viewName` property, which indicates the resource that needs to be loaded. The `viewName` is a combination of the namespace defined in the bootstrap and the path to the app view, but without the ".view.xml" extension. In addition, we set the `id` property to "app". Providing a stable ID is beneficial as it offers an easy and consistent way to identify and refer to specific views and elements in your code, thus helping to keep your code organized.
52
63
53
64
```ts
54
65
importXMLViewfrom"sap/ui/core/mvc/XMLView";
@@ -61,6 +72,21 @@ XMLView.create({
61
72
});
62
73
63
74
```
75
+
76
+
```js
77
+
sap.ui.define(["sap/ui/core/mvc/XMLView"], function (XMLView) {
78
+
"use strict";
79
+
80
+
XMLView.create({
81
+
viewName:"ui5.walkthrough.view.App",
82
+
id:"app"
83
+
}).then(function (view) {
84
+
view.placeAt("content");
85
+
});
86
+
});
87
+
88
+
```
89
+
64
90
We have now embed our app view to the body of the HTML document.
0 commit comments