Skip to content

Commit 1da757b

Browse files
committed
docs: add missing js parts to readme
1 parent b4c434d commit 1da757b

File tree

26 files changed

+898
-211
lines changed

26 files changed

+898
-211
lines changed

steps/03/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ As we now use the `sap.m` library with our app, we need to add the dependency to
134134

135135
We open a terminal in the root folder of our app and exectue the following command:
136136

137-
```sh
137+
```sh
138138
ui5 add sap.m
139139
```
140140

steps/14/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ html[dir="ltr"] .myAppDemoWT .myCustomButton.sapMBtn {
5959
font-weight: bold;
6060
}
6161
```
62-
***
6362

6463
### webapp/manifest.json
6564

@@ -84,8 +83,6 @@ We configure the CSS file to our app descriptor: In the `resources` section of t
8483
}
8584
```
8685

87-
***
88-
8986
### webapp/view/App.view.xml
9087

9188
The app control is configured with our custom namespace class `myAppDemoWT`. This class has no styling rules set and is used in the definition of the CSS rules to define CSS selectors that are only valid for this app.
@@ -130,7 +127,7 @@ To highlight the output text, we replace the text control by a `FormattedText` c
130127
</Shell>
131128
</mvc:View>
132129
```
133-
130+
&nbsp;
134131
The actual color now depends on the selected theme which ensures that the color always fits to the theme and is semantically clear. For a complete list of the available CSS class names, see [CSS Classes for Theme Parameters](https://sdk.openui5.org/topic/ea08f53503da42c19afd342f4b0c9ec7.html).
135132

136133
***

steps/15/README.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ You can download the solution for this step here: [📥 Download step 15](https:
3232
</details>
3333
***
3434

35-
### webapp/controller/HelloPanel.controller.ts \(New\)
35+
### webapp/controller/HelloPanel.controller.?s \(New\)
3636

37-
In folder `webapp/controller` we create a new `HelloPanel.controller.ts` file and move the method `onShowHello` of the app controller to it, so we get a reusable asset.
37+
In folder `webapp/controller` we create a new `HelloPanel.controller.?s` file and move the method `onShowHello` of the app controller to it, so we get a reusable asset.
3838

3939
```ts
4040
import Controller from "sap/ui/core/mvc/Controller";
@@ -58,6 +58,27 @@ export default class HelloPanel extends Controller {
5858
MessageToast.show(msg);
5959
}
6060
};
61+
62+
```
63+
64+
```js
65+
sap.ui.define(["sap/ui/core/mvc/Controller", "sap/m/MessageToast"], function (Controller, MessageToast) {
66+
"use strict";
67+
68+
const HelloPanel = Controller.extend("ui5.walkthrough.controller.HelloPanel", {
69+
onShowHello: function _onShowHello() {
70+
// read msg from i18n model
71+
const recipient = this.getView()?.getModel()?.getProperty("/recipient/name");
72+
const resourceBundle = this.getView()?.getModel("i18n")?.getResourceBundle();
73+
const msg = resourceBundle.getText("helloMsg", [recipient]);
74+
// show message
75+
MessageToast.show(msg);
76+
}
77+
});
78+
;
79+
return HelloPanel;
80+
});
81+
6182
```
6283
6384
### webapp/view/HelloPanel.view.xml \(New\)
@@ -89,7 +110,6 @@ We create a new `HelloPanel.view.xml` file in folder `webapp/view` and move the
89110
</Panel>
90111
</mvc:View>
91112
```
92-
***
93113
94114
### webapp/view/App.view.xml
95115
@@ -115,9 +135,7 @@ In the App view, we remove the panel control and its content and put the `XMLVie
115135
</mvc:View>
116136
```
117137
118-
***
119-
120-
### webapp/controller/App.controller.ts
138+
### webapp/controller/App.controller.?s
121139
122140
We remove the `onShowHello` method from the App controller, as this is not needed anymore.
123141
@@ -129,8 +147,21 @@ import Controller from "sap/ui/core/mvc/Controller";
129147
export default class App extends Controller {
130148

131149
};
150+
132151
```
133152
153+
```js
154+
sap.ui.define(["sap/ui/core/mvc/Controller"], function (Controller) {
155+
"use strict";
156+
157+
const App = Controller.extend("ui5.walkthrough.controller.App", {});
158+
;
159+
return App;
160+
});
161+
162+
```
163+
&nbsp;
164+
134165
We have now moved everything out of the app view and controller. The app controller remains an empty stub for now, we will use it later to add more functionality.
135166
136167
&nbsp;

steps/16/README.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ We add a new XML file to declaratively define our dialog in a fragment. The frag
5151
title="Hello {/recipient/name}"/>
5252
</core:FragmentDefinition>
5353
```
54-
54+
&nbsp;
5555
The syntax is similar to a view, but since fragments do not have a controller this attribute is missing. Also, the fragment does not have any footprint in the DOM tree of the app, and there is no control instance of the fragment itself (only the contained controls). It is simply a container for a set of reuse controls.
5656

57-
***
57+
### webapp/controller/HelloPanel.controller.?s
5858

59-
### webapp/controller/HelloPanel.controller.ts
60-
61-
In the HelloPanel controller, we define a new event handler function `onOpenDialog` which calls the dialog in the HelloDialog fragment when triggered. To do so we need to import the `sap.m.Dialog` module.
59+
In the HelloPanel controller, we define a new event handler function `onOpenDialog` which calls the dialog in the HelloDialog fragment when triggered. To do so we need the `sap.m.Dialog` module.
6260

6361
Using async/await, we handle the opening of the dialog asynchronously whenever the event is triggered.
6462

@@ -88,8 +86,34 @@ export default class HelloPanel extends Controller {
8886
this.dialog.open();
8987
}
9088
};
89+
9190
```
91+
```js
92+
sap.ui.define(["sap/ui/core/mvc/Controller", "sap/m/MessageToast"], function (Controller, MessageToast) {
93+
"use strict";
94+
95+
const HelloPanel = Controller.extend("ui5.walkthrough.controller.HelloPanel", {
96+
onShowHello: function _onShowHello() {
97+
// read msg from i18n model
98+
const recipient = this.getView()?.getModel()?.getProperty("/recipient/name");
99+
const resourceBundle = this.getView()?.getModel("i18n")?.getResourceBundle();
100+
const msg = resourceBundle.getText("helloMsg", [recipient]);
101+
// show message
102+
MessageToast.show(msg);
103+
},
104+
onOpenDialog: async function _onOpenDialog() {
105+
this.dialog ??= await this.loadFragment({
106+
name: "ui5.walkthrough.view.HelloDialog"
107+
});
108+
this.dialog.open();
109+
}
110+
});
111+
;
112+
return HelloPanel;
113+
});
92114

115+
```
116+
&nbsp;
93117
> 💡 **Tip:** <br>
94118
> To reuse the dialog opening and closing functionality in other controllers, you might create a new file `ui5.walkthrough.controller.controller.BaseController`, which extends `sap.ui.core.mvc.Controller`, and put all your dialog-related coding into this controller. Now, all the other controllers can extend from `ui5.walkthrough.controller.BaseController` instead of `sap.ui.core.mvc.Controller`.
95119
@@ -142,7 +166,7 @@ We add a new button to the view to open the dialog and assign an unique `id`to i
142166
</Panel>
143167
</mvc:View>
144168
```
145-
169+
&nbsp;
146170
You will need the id of the button control `id="helloDialogButton"` in [Step 28: Integration Test with OPA](../28/README.md).
147171
148172
It is a good practice to set a unique ID like `helloWorldButton` to key controls of your app so that they can be identified easily. If the attribute `id` is not specified, the OpenUI5 runtime generates unique but changing ID like `\_\_button23` for the control. Inspect the DOM elements of your app in the browser to see the difference.

steps/17/README.md

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You can download the solution for this step here: [📥 Download step 17](https:
3030
</details>
3131
***
3232

33-
### webapp/controller/HelloPanel.controller.ts
33+
### webapp/controller/HelloPanel.controller.?s
3434

3535
We add an event handler function into the HelloPanel controller file that closes the dialog when triggered. To get the dialog instance we use the `byId` function and then call the `close` function of the dialog.
3636

@@ -46,23 +46,56 @@ import Dialog from "sap/m/Dialog";
4646
* @namespace ui5.walkthrough.controller
4747
*/
4848
export default class HelloPanel extends Controller {
49-
50-
49+
private dialog: Dialog;
5150
onShowHello(): void {
52-
...
51+
// read msg from i18n model
52+
const recipient = (this.getView()?.getModel() as JSONModel)?.getProperty("/recipient/name");
53+
const resourceBundle = (this.getView()?.getModel("i18n") as ResourceModel)?.getResourceBundle() as ResourceBundle;
54+
const msg = resourceBundle.getText("helloMsg", [recipient]);
55+
// show message
56+
MessageToast.show(msg);
5357
}
5458
async onOpenDialog(): Promise<void> {
55-
...
59+
this.dialog ??= await this.loadFragment({
60+
name: "ui5.walkthrough.view.HelloDialog"
61+
}) as Dialog;
62+
this.dialog.open();
5663
}
5764
onCloseDialog(): void {
58-
// note: We don't need to chain to the pDialog promise, since this event-handler
59-
// is only called from within the loaded dialog itself.
6065
(this.byId("helloDialog") as Dialog)?.close();
61-
}
66+
}
6267
};
68+
6369
```
6470

65-
***
71+
```js
72+
sap.ui.define(["sap/ui/core/mvc/Controller", "sap/m/MessageToast"], function (Controller, MessageToast) {
73+
"use strict";
74+
75+
const HelloPanel = Controller.extend("ui5.walkthrough.controller.HelloPanel", {
76+
onShowHello: function _onShowHello() {
77+
// read msg from i18n model
78+
const recipient = this.getView()?.getModel()?.getProperty("/recipient/name");
79+
const resourceBundle = this.getView()?.getModel("i18n")?.getResourceBundle();
80+
const msg = resourceBundle.getText("helloMsg", [recipient]);
81+
// show message
82+
MessageToast.show(msg);
83+
},
84+
onOpenDialog: async function _onOpenDialog() {
85+
this.dialog ??= await this.loadFragment({
86+
name: "ui5.walkthrough.view.HelloDialog"
87+
});
88+
this.dialog.open();
89+
},
90+
onCloseDialog: function _onCloseDialog() {
91+
this.byId("helloDialog")?.close();
92+
}
93+
});
94+
;
95+
return HelloPanel;
96+
});
97+
98+
```
6699
67100
### webapp/i18n/i18n.properties
68101
@@ -80,8 +113,6 @@ openDialogButtonText=Say Hello With Dialog
80113
dialogCloseButtonText=Ok
81114
```
82115
83-
***
84-
85116
### webapp/view/HelloDialog.fragment.xml
86117
87118
In the fragment definition, we add a button to the `beginButton` aggregation of the dialog and refer the press handler to the event handler we just defined in the controller of the panel’s content view.
@@ -101,7 +132,7 @@ In the fragment definition, we add a button to the `beginButton` aggregation of
101132
</Dialog>
102133
</core:FragmentDefinition>
103134
```
104-
135+
&nbsp;
105136
By using the `loadFragment` function to create the fragment content in the controller of the panel’s content view, the method will be invoked there when the button is pressed. The dialog has an aggregation named `beginButton` as well as `endButton`. Placing buttons in both of these aggregations makes sure that the `beginButton` is placed before the `endButton` on the UI. What `before` means, however, depends on the text direction of the current language. We therefore use the terms `begin` and `end` as a synonym to “left” and “right". In languages with left-to-right direction, the `beginButton` will be rendered left, the `endButton` on the right side of the dialog footer; in right-to-left mode for specific languages the order is switched.
106137
107138
&nbsp;

steps/17/webapp/controller/HelloPanel.controller.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ export default class HelloPanel extends Controller {
2525
this.dialog.open();
2626
}
2727
onCloseDialog(): void {
28-
// note: We don't need to chain to the pDialog promise, since this event-handler
29-
// is only called from within the loaded dialog itself.
3028
(this.byId("helloDialog") as Dialog)?.close();
3129
}
3230
};

steps/18/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,11 @@ We add an icon to the button that opens the dialog. The `sap-icon://` protocol i
6565
</Panel>
6666
</mvc:View>
6767
```
68-
68+
&nbsp;
6969
>💡 **Tip:** <br>
7070
> You can look up other icons using the [Icon Explorer tool](https://sdk.openui5.org/test-resources/sap/m/demokit/iconExplorer/webapp/index.html).
7171
> To call any icon, use its name as listed in the *Icon Explorer* in <code>sap-icon://<i>&lt;iconname&gt;</i></code>.
7272
73-
***
7473

7574
### webapp/view/HelloDialog.fragment.xml
7675

steps/19/README.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
## Step 19: Aggregation Binding
22

33
Now that we have established a good structure for our app, it's time to add some more functionality. We start exploring more features of data binding by adding some invoice data in JSON format that we display in a list below the panel.
4-
54
&nbsp;
65

76
***
@@ -81,16 +80,13 @@ We create a new folder `model` in our app project and place the new `localInvoic
8180
]
8281
}
8382
```
84-
83+
&nbsp;
8584
The `localinvoices` file simply contains five invoices in a JSON format that we can use to bind controls against them in the app. JSON is a very lightweight format for storing data and can be directly used as a data source for OpenUI5 applications.
8685

87-
***
88-
8986
### webapp/manifest.json
9087

9188
We add a new named model `invoice` to the `sap.ui5` section of the descriptor. This time we want a JSONModel, so we set the type to `sap.ui.model.json.JSONModel`. The `uri` key is the path to our data relative to the component.
9289

93-
9490
```json
9591
{
9692
...
@@ -122,11 +118,9 @@ We add a new named model `invoice` to the `sap.ui5` section of the descriptor. T
122118
}
123119
}
124120
```
125-
121+
&nbsp;
126122
With this little configuration our component will automatically instantiate a new `JSONModel` which loads the invoice data from the `localInvoices.json` file. Finally, the instantiated `JSONModel` is put onto the component as a named model invoice. The named model is then visible throughout our app.
127123

128-
***
129-
130124
### webapp/i18n/i18n.properties
131125

132126
In the text bundle we create a new text for a Invoice List title we will need in the view we are about to create.
@@ -167,11 +161,9 @@ In the `items` aggregation, we define the template for the list that will be aut
167161
</List>
168162
</mvc:View>
169163
```
170-
164+
&nbsp;
171165
The binding in the list item works, because we have bound the `items` aggregation via `items={invoice>/Invoices}` to the invoices.
172166

173-
***
174-
175167
### webapp/view/App.view.xml
176168

177169
In the app view we add a second view and assign it to our newly created InvoiceList view to display our invoices below the panel.
@@ -227,6 +219,4 @@ In the app view we add a second view and assign it to our newly created InvoiceL
227219

228220
[API Reference: sap.m.List](https://sdk.openui5.org/#/api/sap.m.List)
229221

230-
[Samples: sap.m.List](https://sdk.openui5.org/#/entity/sap.m.List)
231-
232-
222+
[Samples: sap.m.List](https://sdk.openui5.org/#/entity/sap.m.List)

steps/20/README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ You can download the solution for this step here: [📥 Download step 20](https:
3030
</details>
3131
***
3232

33-
### webapp/controller/InvoiceList.controller.js \(New\)
33+
### webapp/controller/InvoiceList.controller.?s \(New\)
3434

35-
We want to display in our list view the price in Euro, and typically the currency is part of our data model on the back end. In our case this is not the case, so we need to define it directly in the app. We therefore create a controller for the invoice list and define a view model for the currency code for Euro. It is a simple JSON model with just one key `currency` and the value `EUR`.
35+
We want to display in our list view the price in Euro. Since currency information isn't available in our backend data model, we'll handle the currency formatting within the application.
36+
37+
We'll create a controller for the InvoiceList view and use a JSON model (`sap/ui/model/json/JSONModel`) to store the currency code. This model will contain a single property, `currency: "EUR"`, which will be used for formatting the prices in the view.
3638

3739
```ts
3840
import Controller from "sap/ui/core/mvc/Controller";
@@ -50,9 +52,26 @@ export default class App extends Controller {
5052
this.getView()?.setModel(viewModel, "view");
5153
}
5254
};
55+
5356
```
5457

55-
***
58+
```js
59+
sap.ui.define(["sap/ui/core/mvc/Controller", "sap/ui/model/json/JSONModel"], function (Controller, JSONModel) {
60+
"use strict";
61+
62+
const App = Controller.extend("ui5.walkthrough.controller.App", {
63+
onInit: function _onInit() {
64+
const viewModel = new JSONModel({
65+
currency: "EUR"
66+
});
67+
this.getView()?.setModel(viewModel, "view");
68+
}
69+
});
70+
;
71+
return App;
72+
});
73+
74+
```
5675
5776
### webapp/view/InvoiceList.view.xml
5877

0 commit comments

Comments
 (0)