Skip to content

Commit 726bcdb

Browse files
committed
Add nanoflow support
1 parent e063057 commit 726bcdb

File tree

2 files changed

+59
-14
lines changed

2 files changed

+59
-14
lines changed

src/MicroflowTimer/MicroflowTimer.xml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22
<widget id="MicroflowTimer.widget.MicroflowTimer" needsEntityContext="true" xmlns="http://www.mendix.com/widget/1.0/">
33
<name>MicroflowTimer</name>
44
<description>The description of this widget.</description>
5-
65
<icon></icon>
76

87
<properties>
98
<property key="interval" type="integer" defaultValue="30000">
109
<caption>Interval (in ms)</caption>
1110
<category>Behavior</category>
12-
<description>
13-
Defines how often the microflow is called. Note that the inteval is in milliseconds, so the default, 30000, equals 30 seconds. Note that, unless Execute Once is set to true, the microflow is invoked immediately after loading the form for the first
14-
time.
15-
</description>
11+
<description>Defines how often the microflow is called. Note that the inteval is in milliseconds, so the default, 30000, equals 30 seconds. Note that, unless Execute Once is set to true, the microflow is invoked immediately after loading the form for the first time. </description>
1612
</property>
1713
<property key="once" type="boolean" defaultValue="false">
1814
<caption>Execute once</caption>
@@ -24,12 +20,27 @@
2420
<category>Behavior</category>
2521
<description>If true (and execute once is false), the microflow will be invoked the first time if the widget has loaded. If false, the microflow will be invoked the first time after interval has passed.</description>
2622
</property>
27-
<property key="microflow" type="microflow" required="true">
23+
<property key="callEvent" type="enumeration" defaultValue="callMicroflow">
24+
<caption>Call event</caption>
25+
<category>Behavior</category>
26+
<description/>
27+
<enumerationValues>
28+
<enumerationValue key="callMicroflow">Call a microflow</enumerationValue>
29+
<enumerationValue key="callNanoflow">Call a nanoflow</enumerationValue>
30+
</enumerationValues>
31+
</property>
32+
<property key="microflow" type="microflow" required="false">
2833
<caption>Microflow</caption>
2934
<category>Behavior</category>
3035
<description>The microflow to be executed. If the microflow returns false, it will not be executed any longer until the context changes.</description>
3136
<returnType type="Boolean"/>
3237
</property>
38+
<property key="nanoflow" type="nanoflow" required="false">
39+
<caption>Nanoflow</caption>
40+
<category>Behavior</category>
41+
<description>The nanoflow to be executed. If the nanoflow returns false, it will not be executed any longer until the context changes.</description>
42+
<returnType type="Boolean"/>
43+
</property>
3344
<property key="firstIntervalAttr" type="attribute" required="false">
3445
<caption>First tick delay</caption>
3546
<category>Context</category>

src/MicroflowTimer/widget/MicroflowTimer.js

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ define([
1212
interval: 30000,
1313
once: false,
1414
startatonce: true,
15+
callEvent: null,
1516
microflow: "",
17+
nanoflow: "",
1618
firstIntervalAttr: null,
1719
intervalAttr: null,
1820
timerStatusAttr: null,
@@ -113,33 +115,33 @@ define([
113115

114116
_runTimer: function() {
115117
logger.debug(this.id + "._runTimer", this.interval);
116-
if (this.microflow !== "" && this._contextObj) {
118+
if (this.callEvent !== "" && this._contextObj) {
117119
this._timerStarted = true;
118120

119121
//if there's a first interval, get and use that first, then use the regular interval
120122
if (this.firstIntervalAttr) {
121123
var firstInterval = this._contextObj.get(this.firstIntervalAttr);
122124

123125
if (this.once) {
124-
this._timeout = setTimeout(lang.hitch(this, this._execMf), firstInterval);
126+
this._timeout = setTimeout(lang.hitch(this, this._executeEvent), firstInterval);
125127
} else {
126128
if (this.startatonce) {
127-
this._execMf();
129+
this._executeEvent();
128130
}
129131
this._timeout = setTimeout(lang.hitch(this, function() {
130-
this._execMf();
131-
this._timer = setInterval(lang.hitch(this, this._execMf), this.interval);
132+
this._executeEvent();
133+
this._timer = setInterval(lang.hitch(this, this._executeEvent), this.interval);
132134
}), firstInterval);
133135
}
134136
//otherwise just use the regulat interval
135137
} else {
136138
if (this.once) {
137-
this._timeout = setTimeout(lang.hitch(this, this._execMf), this.interval);
139+
this._timeout = setTimeout(lang.hitch(this, this._executeEvent), this.interval);
138140
} else {
139141
if (this.startatonce) {
140-
this._execMf();
142+
this._executeEvent();
141143
}
142-
this._timer = setInterval(lang.hitch(this, this._execMf), this.interval);
144+
this._timer = setInterval(lang.hitch(this, this._executeEvent), this.interval);
143145
}
144146
}
145147
}
@@ -161,6 +163,14 @@ define([
161163
}
162164
},
163165

166+
_executeEvent: function() {
167+
if(this.callEvent == "callMicroflow") {
168+
this._execMf()
169+
} else {
170+
this._executeNanoFlow()
171+
}
172+
},
173+
164174
_execMf: function() {
165175
logger.debug(this.id + "._execMf");
166176
if (!this._contextObj) {
@@ -197,6 +207,30 @@ define([
197207
}
198208
},
199209

210+
_executeNanoFlow: function() {
211+
logger.debug(this.id + "._executeNanoFlow");
212+
if (!this._contextObj) {
213+
return;
214+
}
215+
216+
if (this.nanoflow.nanoflow) {
217+
mx.data.callNanoflow({
218+
nanoflow: this.nanoflow,
219+
origin: this.mxform,
220+
context: this.mxcontext,
221+
callback: lang.hitch(this, function(result) {
222+
if (!result) {
223+
logger.debug(this.id + "._executeNanoFlow callback, stopping timer");
224+
this._stopTimer();
225+
}
226+
}),
227+
error: lang.hitch(this, function(error) {
228+
logger.error(this.id + ": An error ocurred while executing nanoflow: ", error);
229+
})
230+
});
231+
}
232+
},
233+
200234
// Reset subscriptions.
201235
_resetSubscriptions: function() {
202236
// Release handles on previous object, if any.

0 commit comments

Comments
 (0)