Skip to content

Commit 8bb3ef3

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents c93a312 + c167a56 commit 8bb3ef3

File tree

5 files changed

+35
-47
lines changed

5 files changed

+35
-47
lines changed

README.md

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,4 @@
1-
# Microflow Timer [![Support](https://img.shields.io/badge/Mendix%20Support%3A-Platform-green.svg)](https://docs.mendix.com/community/app-store/app-store-content-support)
1+
Please see [Microflow Timer](https://docs.mendix.com/appstore/widgets/microflow-timer) in the Mendix documentation for details.
22

3-
This widget can be used to time and execute a Microflow or Nanoflow as long as a certain form is open. The microflow or nanoflow can be executed once or repeatedly, in which case it will not stop until it returns false or until the form is closed. In offline profile only a nanoflow can be used.
4-
5-
## Typical usage scenario
6-
7-
* Update a grid or object after a certain amount of time, for example a message inbox
8-
* Close a form with a message automatically after 10 seconds
9-
* Automatically make backup copies while the user is still editing an object.
10-
* Open a form and directly trigger validation errors. (to achieve this, use interval: 0, execute once: true, start at once: true) (new in 1.2)
11-
12-
## Features and limitations
13-
14-
* Adds timed behavior to your applications.
15-
* Run a Microflow or Nanoflow.
16-
17-
## Configuration
18-
19-
* The widget requires a dataview or template grid context. This object will be send as argument to the invoked microflow or nanoflow.
20-
21-
## Properties
22-
23-
* Interval (in ms): Defines how often the microflow or nanoflow 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.
24-
* Execute once: If true, the microflow will be invoked only once, and interval defines after how many seconds.
25-
26-
* Microflow: The microflow to be executed. If the microflow returns false, it will not be executed any longer until the context changes.
27-
* Nanoflow: The nanoflow to be executed. If the nanoflow returns false, it will not be executed any longer until the context changes.
28-
* Start at once: If true (and execute once is true), the microflow or nanoflow will be invoked the first time if the widget has loaded. If false, the microflow or nanoflow will be invoked the first time after interval has passed.
3+
## Raising problems/issues
4+
- We encourage everyone to open a Support ticket on [Mendix Support](https://support.mendix.com) in case of problems with widgets or scaffolding tools (Pluggable Widgets Generator or Pluggable Widgets Tools)

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MicroflowTimer/widget/MicroflowTimer.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@ define([
2626
_timeout: null,
2727
_timerStarted: false,
2828

29+
_flowRunning: false,
30+
2931
postCreate: function() {
3032
this._handles = [];
3133

32-
if(!(this.microflow && this.callEvent == "callMicroflow" || this.nanoflow.nanoflow && this.callEvent == "callNanoflow")) {
33-
mx.ui.error("No action specified for " + this.callEvent)
34+
if(!(this.microflow && this.callEvent === "callMicroflow" || this.nanoflow.nanoflow && this.callEvent === "callNanoflow")) {
35+
mx.ui.error("No action specified for " + this.callEvent);
3436
}
3537
},
3638

3739
update: function (obj, callback) {
38-
logger.debug(this.id + ".update");
40+
mx.logger.debug(this.id + ".update");
3941

4042
this._contextObj = obj;
4143
this._resetSubscriptions();
@@ -59,7 +61,7 @@ define([
5961
},
6062

6163
_checkTimerStatus: function() {
62-
logger.debug(this.id + "._checkStatus");
64+
mx.logger.debug(this.id + "._checkStatus");
6365

6466
var running, newInterval;
6567

@@ -107,7 +109,7 @@ define([
107109

108110
//Called when the optional timer interval attribute is changed
109111
_intervalChange: function (newInterval) {
110-
logger.debug(this.id + "._intervalChange");
112+
mx.logger.debug(this.id + "._intervalChange");
111113

112114
this.interval = newInterval;
113115

@@ -118,7 +120,7 @@ define([
118120
},
119121

120122
_runTimer: function() {
121-
logger.debug(this.id + "._runTimer", this.interval);
123+
mx.logger.debug(this.id + "._runTimer", this.interval);
122124
if (this.callEvent !== "" && this._contextObj) {
123125
this._timerStarted = true;
124126

@@ -152,33 +154,39 @@ define([
152154
},
153155

154156
_stopTimer: function() {
155-
logger.debug(this.id + "._stopTimer");
157+
mx.logger.debug(this.id + "._stopTimer");
156158
this._timerStarted = false;
157159

158160
if (this._timer !== null) {
159-
logger.debug(this.id + "._stopTimer timer cleared");
161+
mx.logger.debug(this.id + "._stopTimer timer cleared");
160162
clearInterval(this._timer);
161163
this._timer = null;
162164
}
163165
if (this._timeout !== null) {
164-
logger.debug(this.id + "._stopTimer timeout cleared");
166+
mx.logger.debug(this.id + "._stopTimer timeout cleared");
165167
clearTimeout(this._timeout);
166168
this._timeout = null;
167169
}
168170
},
169171

170172
_executeEvent: function() {
173+
if (this._flowRunning === true) {
174+
return;
175+
}
176+
177+
this._flowRunning = true;
178+
171179
if(this.callEvent === "callMicroflow" && this.microflow) {
172-
this._execMf()
180+
this._execMf();
173181
} else if (this.callEvent === "callNanoflow" && this.nanoflow.nanoflow){
174-
this._executeNanoFlow()
182+
this._executeNanoFlow();
175183
} else {
176184
return;
177185
}
178186
},
179187

180188
_execMf: function() {
181-
logger.debug(this.id + "._execMf");
189+
mx.logger.debug(this.id + "._execMf");
182190
if (!this._contextObj) {
183191
return;
184192
}
@@ -192,12 +200,14 @@ define([
192200
},
193201
callback: lang.hitch(this, function(result) {
194202
if (!result) {
195-
logger.debug(this.id + "._execMf callback, stopping timer");
203+
mx.logger.debug(this.id + "._execMf callback, stopping timer");
196204
this._stopTimer();
197205
}
206+
this._flowRunning = false;
198207
}),
199208
error: lang.hitch(this, function(error) {
200-
logger.error(this.id + ": An error ocurred while executing microflow: ", error);
209+
mx.logger.error(this.id + ": An error ocurred while executing microflow: ", error);
210+
this._flowRunning = false;
201211
})
202212
};
203213

@@ -221,12 +231,14 @@ define([
221231
context: this.mxcontext,
222232
callback: lang.hitch(this, function(result) {
223233
if (!result) {
224-
logger.debug(this.id + "._executeNanoFlow callback, stopping timer");
234+
mx.logger.debug(this.id + "._executeNanoFlow callback, stopping timer");
225235
this._stopTimer();
226236
}
237+
this._flowRunning = false;
227238
}),
228239
error: lang.hitch(this, function(error) {
229-
logger.error(this.id + ": An error ocurred while executing nanoflow: ", error);
240+
mx.logger.error(this.id + ": An error ocurred while executing nanoflow: ", error);
241+
this._flowRunning = false;
230242
})
231243
});
232244
}
@@ -264,12 +276,12 @@ define([
264276
},
265277

266278
_executeCallback: function (cb, from) {
267-
logger.debug(this.id + "._executeCallback" + (from ? " from " + from : ""));
279+
mx.logger.debug(this.id + "._executeCallback" + (from ? " from " + from : ""));
268280
if (cb && typeof cb === "function") {
269281
cb();
270282
}
271283
}
272284
});
273285
});
274286

275-
require(["MicroflowTimer/widget/MicroflowTimer"])
287+
require(["MicroflowTimer/widget/MicroflowTimer"]);

src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
<file path="MicroflowTimer/widget/"/>
99
</files>
1010
</clientModule>
11-
</package>
11+
</package>

test/widgets/MicroflowTimer.mpk

29 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)