Skip to content

Commit 0a2a0d5

Browse files
authored
Docs: add implementing a UI modal (OpenEMS#2389)
1 parent fd67d77 commit 0a2a0d5

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed
Loading

doc/modules/ROOT/pages/ui/implementing-a-widget.adoc

+43-1
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,46 @@ Shows a horizontal line, that is used to divide children of AbstractFlatWidgetLi
135135
Passing data can be done two ways:
136136

137137
- @Input() channelAddress: provide channel, which will be subscribed in AbstractFlatWidgetLine.
138-
- @Input() value: subscribe in the ts-file and pass the subscribed value.
138+
- @Input() value: subscribe in the ts-file and pass the subscribed value.
139+
140+
### Creating a modal
141+
142+
Creating a `modal-widget` is pretty similar to creating a `flat-widget`.
143+
The model should act as the detailed view of a `flat-widget` and can also fit the purpose of user interaction.
144+
145+
There are multiple implementations of `modals` at the creation time of this page, but the one thats considered best practice is the unit-testable version.
146+
147+
#### Creating a Line
148+
149+
Lets take a look at one link:https://github.com/OpenEMS/openems/blob/develop/ui/src/app/edge/live/common/consumption/modal/modal.ts[example].
150+
151+
[source, html]
152+
----
153+
public static generateView(
154+
config: EdgeConfig, role: Role, translate: TranslateService)
155+
:OeFormlyView {
156+
157+
// Total
158+
lines.push({
159+
type: 'channel-line',
160+
name: translate.instant('General.TOTAL'),
161+
channel: '_sum/ConsumptionActivePower',
162+
converter: Converter.ONLY_POSITIVE_POWER_AND_NEGATIVE_AS_ZERO
163+
});
164+
165+
return {
166+
title: translate.instant('General.grid'),
167+
lines: lines
168+
};
169+
}
170+
----
171+
172+
Predefined fields in link:https://github.com/OpenEMS/openems/blob/develop/ui/src/app/shared/genericComponents/shared/oe-formly-component.ts[OeFormlyField] can be used here.
173+
174+
For this line we use the type 'channel-line'. This represents a line, where a channel has to be subscribed. You also need to specify the link:https://github.com/OpenEMS/openems/blob/develop/ui/src/app/shared/genericComponents/shared/converter.ts[converter], that uses the data coming from this channel and mutates it. A link:https://github.com/OpenEMS/openems/blob/develop/ui/src/app/shared/genericComponents/shared/filter.ts[filter], which has to return a boolean, decides if the line will be shown or not.
175+
176+
NOTE: Lines should always present one line of data visualisation. It could be consisting of a identifier and a value or just a value. The value or channel will be shown at the end of the line, the name, if provided, at the start.
177+
178+
This line will be looking like this:
179+
180+
image::modal-line-example-consumption.png[]

0 commit comments

Comments
 (0)