From c7211da53f7c7cedb480d0d23547735422e7d4c5 Mon Sep 17 00:00:00 2001 From: Rik Bos Date: Wed, 24 Jun 2020 11:23:39 -0600 Subject: [PATCH 1/3] Preventing the microflow timer to trigger a new action before the previous one is finished --- src/MicroflowTimer/widget/MicroflowTimer.js | 571 +++++++++++--------- 1 file changed, 307 insertions(+), 264 deletions(-) diff --git a/src/MicroflowTimer/widget/MicroflowTimer.js b/src/MicroflowTimer/widget/MicroflowTimer.js index 187006d..aa0daa6 100644 --- a/src/MicroflowTimer/widget/MicroflowTimer.js +++ b/src/MicroflowTimer/widget/MicroflowTimer.js @@ -1,275 +1,318 @@ define([ - "dojo/_base/declare", - "mxui/widget/_WidgetBase", - "dojo/_base/lang", - "dojo/_base/array" -], function(declare, _WidgetBase, lang, dojoArray) { - "use strict"; - - return declare("MicroflowTimer.widget.MicroflowTimer", [_WidgetBase], { - - // Parameters configured in the Modeler. - interval: 30000, - once: false, - startatonce: true, - callEvent: "", // "callMicroflow" | "callNanoflow" - microflow: "", - nanoflow: null, - firstIntervalAttr: null, - intervalAttr: null, - timerStatusAttr: null, - - // Internal variables. Non-primitives created in the prototype are shared between all widget instances. - _handles: null, - _contextObj: null, - _timer: null, - _timeout: null, - _timerStarted: false, - - postCreate: function() { - this._handles = []; - - if(!(this.microflow && this.callEvent == "callMicroflow" || this.nanoflow.nanoflow && this.callEvent == "callNanoflow")) { - mx.ui.error("No action specified for " + this.callEvent) - } - }, - - update: function (obj, callback) { - logger.debug(this.id + ".update"); - - this._contextObj = obj; - this._resetSubscriptions(); - - //changes the interval to the attribute value, if set - if (this._contextObj && this.intervalAttr) { - this.interval = this._contextObj.get(this.intervalAttr); - } - - if (!this._timerStarted) { - this._runTimer(); - } - - this._executeCallback(callback, "update"); - }, - - resize: function(box) {}, - - uninitialize: function() { - this._stopTimer(); - }, - - _checkTimerStatus: function() { - logger.debug(this.id + "._checkStatus"); - - var running, newInterval; - - //both optional attributes are used - if (this.intervalAttr && this.timerStatusAttr) { - //get the running state - running = this._contextObj.get(this.timerStatusAttr); - //change the interval if it was set in the attribute - newInterval = this._contextObj.get(this.intervalAttr); - if (this.interval !== newInterval) { - this.interval = newInterval; - //stop and start the timer if it's running and will keep running - if (running && this._timerStarted) { - this._intervalChange(newInterval); - } - } - - this._timerStatusChange(running); - - //just timer status is used - } else if (this.timerStatusAttr) { - running = this._contextObj.get(this.timerStatusAttr); - this._timerStatusChange(running); - - //just interval is used - } else if (this.intervalAttr) { - newInterval = this._contextObj.get(this.intervalAttr); - if (this.interval !== newInterval) { - this.interval = newInterval; - this._intervalChange(newInterval); - } - } - - }, - - _timerStatusChange: function (running) { - if (running !== this._timerStarted) { - if (running) { - this._runTimer(); - } else { - this._stopTimer(); - } - } - }, - - //Called when the optional timer interval attribute is changed - _intervalChange: function (newInterval) { - logger.debug(this.id + "._intervalChange"); - - this.interval = newInterval; - - if (this._timerStarted) { - this._stopTimer(); - this._runTimer(); - } - }, - - _runTimer: function() { - logger.debug(this.id + "._runTimer", this.interval); - if (this.callEvent !== "" && this._contextObj) { - this._timerStarted = true; - - //if there's a first interval, get and use that first, then use the regular interval - if (this.firstIntervalAttr) { - var firstInterval = this._contextObj.get(this.firstIntervalAttr); - - if (this.once) { - this._timeout = setTimeout(lang.hitch(this, this._executeEvent), firstInterval); - } else { - if (this.startatonce) { - this._executeEvent(); - } - this._timeout = setTimeout(lang.hitch(this, function() { - this._executeEvent(); - this._timer = setInterval(lang.hitch(this, this._executeEvent), this.interval); - }), firstInterval); - } - //otherwise just use the regulat interval - } else { - if (this.once) { - this._timeout = setTimeout(lang.hitch(this, this._executeEvent), this.interval); - } else { - if (this.startatonce) { - this._executeEvent(); - } - this._timer = setInterval(lang.hitch(this, this._executeEvent), this.interval); - } - } - } - }, - - _stopTimer: function() { - logger.debug(this.id + "._stopTimer"); - this._timerStarted = false; + "dojo/_base/declare", + "mxui/widget/_WidgetBase", + "dojo/_base/lang", + "dojo/_base/array", +], function (declare, _WidgetBase, lang, dojoArray) { + "use strict"; + + return declare("MicroflowTimer.widget.MicroflowTimer", [_WidgetBase], { + // Parameters configured in the Modeler. + interval: 30000, + once: false, + startatonce: true, + callEvent: "", // "callMicroflow" | "callNanoflow" + microflow: "", + nanoflow: null, + firstIntervalAttr: null, + intervalAttr: null, + timerStatusAttr: null, + + // Internal variables. Non-primitives created in the prototype are shared between all widget instances. + _handles: null, + _contextObj: null, + _timer: null, + _timeout: null, + _timerStarted: false, + + _flowRunning: false, + + postCreate: function () { + this._handles = []; + + if ( + !( + (this.microflow && this.callEvent == "callMicroflow") || + (this.nanoflow.nanoflow && this.callEvent == "callNanoflow") + ) + ) { + mx.ui.error("No action specified for " + this.callEvent); + } + }, + + update: function (obj, callback) { + logger.debug(this.id + ".update"); + + this._contextObj = obj; + this._resetSubscriptions(); + + //changes the interval to the attribute value, if set + if (this._contextObj && this.intervalAttr) { + this.interval = this._contextObj.get(this.intervalAttr); + } + + if (!this._timerStarted) { + this._runTimer(); + } + + this._executeCallback(callback, "update"); + }, + + resize: function (box) {}, + + uninitialize: function () { + this._stopTimer(); + }, + + _checkTimerStatus: function () { + logger.debug(this.id + "._checkStatus"); + + var running, newInterval; + + //both optional attributes are used + if (this.intervalAttr && this.timerStatusAttr) { + //get the running state + running = this._contextObj.get(this.timerStatusAttr); + //change the interval if it was set in the attribute + newInterval = this._contextObj.get(this.intervalAttr); + if (this.interval !== newInterval) { + this.interval = newInterval; + //stop and start the timer if it's running and will keep running + if (running && this._timerStarted) { + this._intervalChange(newInterval); + } + } - if (this._timer !== null) { - logger.debug(this.id + "._stopTimer timer cleared"); - clearInterval(this._timer); - this._timer = null; - } - if (this._timeout !== null) { - logger.debug(this.id + "._stopTimer timeout cleared"); - clearTimeout(this._timeout); - this._timeout = null; - } - }, - - _executeEvent: function() { - if(this.callEvent === "callMicroflow" && this.microflow) { - this._execMf() - } else if (this.callEvent === "callNanoflow" && this.nanoflow.nanoflow){ - this._executeNanoFlow() - } else { - return; - } - }, + this._timerStatusChange(running); - _execMf: function() { - logger.debug(this.id + "._execMf"); - if (!this._contextObj) { - return; - } + //just timer status is used + } else if (this.timerStatusAttr) { + running = this._contextObj.get(this.timerStatusAttr); + this._timerStatusChange(running); - if (this.microflow) { - var mfObject = { - params: { - actionname: this.microflow, - applyto: "selection", - guids: [this._contextObj.getGuid()] - }, - callback: lang.hitch(this, function(result) { - if (!result) { - logger.debug(this.id + "._execMf callback, stopping timer"); - this._stopTimer(); - } - }), - error: lang.hitch(this, function(error) { - logger.error(this.id + ": An error ocurred while executing microflow: ", error); - }) - }; - - if (!mx.version || mx.version && parseInt(mx.version.split(".")[0]) < 6) { - mfObject.store = { - caller: this.mxform - }; - } else { - mfObject.origin = this.mxform; - } - - mx.data.action(mfObject, this); + //just interval is used + } else if (this.intervalAttr) { + newInterval = this._contextObj.get(this.intervalAttr); + if (this.interval !== newInterval) { + this.interval = newInterval; + this._intervalChange(newInterval); + } + } + }, + + _timerStatusChange: function (running) { + if (running !== this._timerStarted) { + if (running) { + this._runTimer(); + } else { + this._stopTimer(); + } + } + }, + + //Called when the optional timer interval attribute is changed + _intervalChange: function (newInterval) { + logger.debug(this.id + "._intervalChange"); + + this.interval = newInterval; + + if (this._timerStarted) { + this._stopTimer(); + this._runTimer(); + } + }, + + _runTimer: function () { + logger.debug(this.id + "._runTimer", this.interval); + if (this.callEvent !== "" && this._contextObj) { + this._timerStarted = true; + + //if there's a first interval, get and use that first, then use the regular interval + if (this.firstIntervalAttr) { + var firstInterval = this._contextObj.get(this.firstIntervalAttr); + + if (this.once) { + this._timeout = setTimeout( + lang.hitch(this, this._executeEvent), + firstInterval + ); + } else { + if (this.startatonce) { + this._executeEvent(); } - }, - - _executeNanoFlow: function() { - if (this.nanoflow.nanoflow && this.mxcontext) { - mx.data.callNanoflow({ - nanoflow: this.nanoflow, - origin: this.mxform, - context: this.mxcontext, - callback: lang.hitch(this, function(result) { - if (!result) { - logger.debug(this.id + "._executeNanoFlow callback, stopping timer"); - this._stopTimer(); - } - }), - error: lang.hitch(this, function(error) { - logger.error(this.id + ": An error ocurred while executing nanoflow: ", error); - }) - }); + this._timeout = setTimeout( + lang.hitch(this, function () { + this._executeEvent(); + this._timer = setInterval( + lang.hitch(this, this._executeEvent), + this.interval + ); + }), + firstInterval + ); + } + //otherwise just use the regulat interval + } else { + if (this.once) { + this._timeout = setTimeout( + lang.hitch(this, this._executeEvent), + this.interval + ); + } else { + if (this.startatonce) { + this._executeEvent(); } - }, - - // Reset subscriptions. - _resetSubscriptions: function() { - this.unsubscribeAll(); - - // When a mendix object exists create subscribtions. - if (this._contextObj && this.timerStatusAttr) { - this.subscribe({ - guid: this._contextObj.getGuid(), - callback: lang.hitch(this, function(guid) { - this._checkTimerStatus(); - }) - }); - - this.subscribe({ - guid: this._contextObj.getGuid(), - attr: this.timerStatusAttr, - callback: lang.hitch(this, function(guid, attr, attrValue) { - this._checkTimerStatus(); - }) - }); - - this.subscribe({ - guid: this._contextObj.getGuid(), - attr: this.intervalAttr, - callback: lang.hitch(this, function(guid, attr, attrValue) { - this._intervalChange(); - }) - }); + this._timer = setInterval( + lang.hitch(this, this._executeEvent), + this.interval + ); + } + } + } + }, + + _stopTimer: function () { + logger.debug(this.id + "._stopTimer"); + this._timerStarted = false; + + if (this._timer !== null) { + logger.debug(this.id + "._stopTimer timer cleared"); + clearInterval(this._timer); + this._timer = null; + } + if (this._timeout !== null) { + logger.debug(this.id + "._stopTimer timeout cleared"); + clearTimeout(this._timeout); + this._timeout = null; + } + }, + + _executeEvent: function () { + if (this._flowRunning === true) { + return; + } + + this._flowRunning = true; + + if (this.callEvent === "callMicroflow" && this.microflow) { + this._execMf(); + } else if (this.callEvent === "callNanoflow" && this.nanoflow.nanoflow) { + this._executeNanoFlow(); + } else { + return; + } + }, + + _execMf: function () { + logger.debug(this.id + "._execMf"); + if (!this._contextObj) { + return; + } + + if (this.microflow) { + var mfObject = { + params: { + actionname: this.microflow, + applyto: "selection", + guids: [this._contextObj.getGuid()], + }, + callback: lang.hitch(this, function (result) { + if (!result) { + logger.debug(this.id + "._execMf callback, stopping timer"); + this._stopTimer(); } - }, + this._flowRunning = false; + }), + error: lang.hitch(this, function (error) { + logger.error( + this.id + ": An error ocurred while executing microflow: ", + error + ); + this._flowRunning = false; + }), + }; + + if ( + !mx.version || + (mx.version && parseInt(mx.version.split(".")[0]) < 6) + ) { + mfObject.store = { + caller: this.mxform, + }; + } else { + mfObject.origin = this.mxform; + } - _executeCallback: function (cb, from) { - logger.debug(this.id + "._executeCallback" + (from ? " from " + from : "")); - if (cb && typeof cb === "function") { - cb(); + mx.data.action(mfObject, this); + } + }, + + _executeNanoFlow: function () { + if (this.nanoflow.nanoflow && this.mxcontext) { + mx.data.callNanoflow({ + nanoflow: this.nanoflow, + origin: this.mxform, + context: this.mxcontext, + callback: lang.hitch(this, function (result) { + if (!result) { + logger.debug( + this.id + "._executeNanoFlow callback, stopping timer" + ); + this._stopTimer(); } - } - }); + this._flowRunning = false; + }), + error: lang.hitch(this, function (error) { + logger.error( + this.id + ": An error ocurred while executing nanoflow: ", + error + ); + this._flowRunning = false; + }), + }); + } + }, + + // Reset subscriptions. + _resetSubscriptions: function () { + this.unsubscribeAll(); + + // When a mendix object exists create subscribtions. + if (this._contextObj && this.timerStatusAttr) { + this.subscribe({ + guid: this._contextObj.getGuid(), + callback: lang.hitch(this, function (guid) { + this._checkTimerStatus(); + }), + }); + + this.subscribe({ + guid: this._contextObj.getGuid(), + attr: this.timerStatusAttr, + callback: lang.hitch(this, function (guid, attr, attrValue) { + this._checkTimerStatus(); + }), + }); + + this.subscribe({ + guid: this._contextObj.getGuid(), + attr: this.intervalAttr, + callback: lang.hitch(this, function (guid, attr, attrValue) { + this._intervalChange(); + }), + }); + } + }, + + _executeCallback: function (cb, from) { + logger.debug( + this.id + "._executeCallback" + (from ? " from " + from : "") + ); + if (cb && typeof cb === "function") { + cb(); + } + }, + }); }); -require(["MicroflowTimer/widget/MicroflowTimer"]) +require(["MicroflowTimer/widget/MicroflowTimer"]); From 9f10e24de94bcd59e64e5836bc2084900e965d82 Mon Sep 17 00:00:00 2001 From: Rik Bos Date: Wed, 24 Jun 2020 11:24:17 -0600 Subject: [PATCH 2/3] Added latest mpk --- test/widgets/MicroflowTimer.mpk | Bin 3777 -> 3812 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/test/widgets/MicroflowTimer.mpk b/test/widgets/MicroflowTimer.mpk index c78f57cd74dd803fd06886e6e97dabe7b503adfd..ce82dab12d07edfa5c75cb5cea00589638540f75 100644 GIT binary patch literal 3812 zcmZ`+XIK-;whc%xLFrAUilK8TDiC@{FqF_cQbIzL8U*Q}ARxhjRHZ{eM2Zk%Km@7M zTj(ePL3)%Th(5jV-cvm1%>0-=-?!JA+4Ez~UJ%1G6s!OM4FFIKAwU3s8caW8Bbe(g zUw4FWh&jyL?UoeezsWTJN!HN5@BsHCsg?`?p#QP@IlIE0J=`Qiy%7-)lz^|L8Pr0A zw$CC(B=3?HHp~+U&1&doVS&dO#<*pcJ4H_czQLP^yvZalMjT`czH`fp#K3uN9UW{0 zT!Tm{K-fQJdx{}3+%A>#``36iJ)7>z==k)4B34Fi!{wb{^Ob-yHS~&m!cMg&6YYQ@0UkvpjbMavN&Dz z?NU{wR{?8YZQ@y(xJzLFc>RKpm2mX;ODALT6pc%DmCzp<Gq%k1m6j7~kld@UozFBv=vrP5 zTMcV;dzjSwLsKm;Nn4KvKocTip0EMtr&+|&p3uNEL(SQ2D2*nuLb}~t;jTlG)$(?W z&wY_>nDTdzRYsq2wo_EtXmM<_(1btWRt$lnJKk1N#`$cn9?MF08gTb#!aRopdEfgI zP<%l4>$)2zv5rgUl1k_)Tx8>^m(#`LnO1qZPV}fYOU(@wgGROP%&AdNlJG0%6fRv$5eR zLG~F=(%sjejCAsz{6<#D!%2FiNrz?DU%9^?x4=N&ny9`OzyJEN+RX~i?$ECp&QU0m zst~h^w8&M{`vFqK+d;ry+&Xm~qhRHvWE{PIzi!F_BXI|i7UOoFD+0vJ)_LgJRl4L8 zK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.js | 583 +++++++++----------- 1 file changed, 276 insertions(+), 307 deletions(-) diff --git a/src/MicroflowTimer/widget/MicroflowTimer.js b/src/MicroflowTimer/widget/MicroflowTimer.js index aa0daa6..362dabf 100644 --- a/src/MicroflowTimer/widget/MicroflowTimer.js +++ b/src/MicroflowTimer/widget/MicroflowTimer.js @@ -1,318 +1,287 @@ define([ - "dojo/_base/declare", - "mxui/widget/_WidgetBase", - "dojo/_base/lang", - "dojo/_base/array", -], function (declare, _WidgetBase, lang, dojoArray) { - "use strict"; - - return declare("MicroflowTimer.widget.MicroflowTimer", [_WidgetBase], { - // Parameters configured in the Modeler. - interval: 30000, - once: false, - startatonce: true, - callEvent: "", // "callMicroflow" | "callNanoflow" - microflow: "", - nanoflow: null, - firstIntervalAttr: null, - intervalAttr: null, - timerStatusAttr: null, - - // Internal variables. Non-primitives created in the prototype are shared between all widget instances. - _handles: null, - _contextObj: null, - _timer: null, - _timeout: null, - _timerStarted: false, - - _flowRunning: false, - - postCreate: function () { - this._handles = []; - - if ( - !( - (this.microflow && this.callEvent == "callMicroflow") || - (this.nanoflow.nanoflow && this.callEvent == "callNanoflow") - ) - ) { - mx.ui.error("No action specified for " + this.callEvent); - } - }, - - update: function (obj, callback) { - logger.debug(this.id + ".update"); - - this._contextObj = obj; - this._resetSubscriptions(); - - //changes the interval to the attribute value, if set - if (this._contextObj && this.intervalAttr) { - this.interval = this._contextObj.get(this.intervalAttr); - } - - if (!this._timerStarted) { - this._runTimer(); - } - - this._executeCallback(callback, "update"); - }, - - resize: function (box) {}, - - uninitialize: function () { - this._stopTimer(); - }, - - _checkTimerStatus: function () { - logger.debug(this.id + "._checkStatus"); - - var running, newInterval; - - //both optional attributes are used - if (this.intervalAttr && this.timerStatusAttr) { - //get the running state - running = this._contextObj.get(this.timerStatusAttr); - //change the interval if it was set in the attribute - newInterval = this._contextObj.get(this.intervalAttr); - if (this.interval !== newInterval) { - this.interval = newInterval; - //stop and start the timer if it's running and will keep running - if (running && this._timerStarted) { - this._intervalChange(newInterval); - } - } + "dojo/_base/declare", + "mxui/widget/_WidgetBase", + "dojo/_base/lang", + "dojo/_base/array" +], function(declare, _WidgetBase, lang, dojoArray) { + "use strict"; + + return declare("MicroflowTimer.widget.MicroflowTimer", [_WidgetBase], { + + // Parameters configured in the Modeler. + interval: 30000, + once: false, + startatonce: true, + callEvent: "", // "callMicroflow" | "callNanoflow" + microflow: "", + nanoflow: null, + firstIntervalAttr: null, + intervalAttr: null, + timerStatusAttr: null, + + // Internal variables. Non-primitives created in the prototype are shared between all widget instances. + _handles: null, + _contextObj: null, + _timer: null, + _timeout: null, + _timerStarted: false, + + _flowRunning: false, + + postCreate: function() { + this._handles = []; + + if(!(this.microflow && this.callEvent == "callMicroflow" || this.nanoflow.nanoflow && this.callEvent == "callNanoflow")) { + mx.ui.error("No action specified for " + this.callEvent) + } + }, - this._timerStatusChange(running); + update: function (obj, callback) { + logger.debug(this.id + ".update"); - //just timer status is used - } else if (this.timerStatusAttr) { - running = this._contextObj.get(this.timerStatusAttr); - this._timerStatusChange(running); + this._contextObj = obj; + this._resetSubscriptions(); - //just interval is used - } else if (this.intervalAttr) { - newInterval = this._contextObj.get(this.intervalAttr); - if (this.interval !== newInterval) { - this.interval = newInterval; - this._intervalChange(newInterval); - } - } - }, - - _timerStatusChange: function (running) { - if (running !== this._timerStarted) { - if (running) { - this._runTimer(); - } else { - this._stopTimer(); - } - } - }, - - //Called when the optional timer interval attribute is changed - _intervalChange: function (newInterval) { - logger.debug(this.id + "._intervalChange"); - - this.interval = newInterval; - - if (this._timerStarted) { - this._stopTimer(); - this._runTimer(); - } - }, - - _runTimer: function () { - logger.debug(this.id + "._runTimer", this.interval); - if (this.callEvent !== "" && this._contextObj) { - this._timerStarted = true; - - //if there's a first interval, get and use that first, then use the regular interval - if (this.firstIntervalAttr) { - var firstInterval = this._contextObj.get(this.firstIntervalAttr); - - if (this.once) { - this._timeout = setTimeout( - lang.hitch(this, this._executeEvent), - firstInterval - ); - } else { - if (this.startatonce) { - this._executeEvent(); + //changes the interval to the attribute value, if set + if (this._contextObj && this.intervalAttr) { + this.interval = this._contextObj.get(this.intervalAttr); } - this._timeout = setTimeout( - lang.hitch(this, function () { - this._executeEvent(); - this._timer = setInterval( - lang.hitch(this, this._executeEvent), - this.interval - ); - }), - firstInterval - ); - } - //otherwise just use the regulat interval - } else { - if (this.once) { - this._timeout = setTimeout( - lang.hitch(this, this._executeEvent), - this.interval - ); - } else { - if (this.startatonce) { - this._executeEvent(); + + if (!this._timerStarted) { + this._runTimer(); } - this._timer = setInterval( - lang.hitch(this, this._executeEvent), - this.interval - ); - } - } - } - }, - - _stopTimer: function () { - logger.debug(this.id + "._stopTimer"); - this._timerStarted = false; - - if (this._timer !== null) { - logger.debug(this.id + "._stopTimer timer cleared"); - clearInterval(this._timer); - this._timer = null; - } - if (this._timeout !== null) { - logger.debug(this.id + "._stopTimer timeout cleared"); - clearTimeout(this._timeout); - this._timeout = null; - } - }, - - _executeEvent: function () { - if (this._flowRunning === true) { - return; - } - - this._flowRunning = true; - - if (this.callEvent === "callMicroflow" && this.microflow) { - this._execMf(); - } else if (this.callEvent === "callNanoflow" && this.nanoflow.nanoflow) { - this._executeNanoFlow(); - } else { - return; - } - }, - - _execMf: function () { - logger.debug(this.id + "._execMf"); - if (!this._contextObj) { - return; - } - - if (this.microflow) { - var mfObject = { - params: { - actionname: this.microflow, - applyto: "selection", - guids: [this._contextObj.getGuid()], - }, - callback: lang.hitch(this, function (result) { - if (!result) { - logger.debug(this.id + "._execMf callback, stopping timer"); - this._stopTimer(); + + this._executeCallback(callback, "update"); + }, + + resize: function(box) {}, + + uninitialize: function() { + this._stopTimer(); + }, + + _checkTimerStatus: function() { + logger.debug(this.id + "._checkStatus"); + + var running, newInterval; + + //both optional attributes are used + if (this.intervalAttr && this.timerStatusAttr) { + //get the running state + running = this._contextObj.get(this.timerStatusAttr); + //change the interval if it was set in the attribute + newInterval = this._contextObj.get(this.intervalAttr); + if (this.interval !== newInterval) { + this.interval = newInterval; + //stop and start the timer if it's running and will keep running + if (running && this._timerStarted) { + this._intervalChange(newInterval); + } + } + + this._timerStatusChange(running); + + //just timer status is used + } else if (this.timerStatusAttr) { + running = this._contextObj.get(this.timerStatusAttr); + this._timerStatusChange(running); + + //just interval is used + } else if (this.intervalAttr) { + newInterval = this._contextObj.get(this.intervalAttr); + if (this.interval !== newInterval) { + this.interval = newInterval; + this._intervalChange(newInterval); + } } - this._flowRunning = false; - }), - error: lang.hitch(this, function (error) { - logger.error( - this.id + ": An error ocurred while executing microflow: ", - error - ); - this._flowRunning = false; - }), - }; - - if ( - !mx.version || - (mx.version && parseInt(mx.version.split(".")[0]) < 6) - ) { - mfObject.store = { - caller: this.mxform, - }; - } else { - mfObject.origin = this.mxform; - } - mx.data.action(mfObject, this); - } - }, - - _executeNanoFlow: function () { - if (this.nanoflow.nanoflow && this.mxcontext) { - mx.data.callNanoflow({ - nanoflow: this.nanoflow, - origin: this.mxform, - context: this.mxcontext, - callback: lang.hitch(this, function (result) { - if (!result) { - logger.debug( - this.id + "._executeNanoFlow callback, stopping timer" - ); - this._stopTimer(); + }, + + _timerStatusChange: function (running) { + if (running !== this._timerStarted) { + if (running) { + this._runTimer(); + } else { + this._stopTimer(); + } + } + }, + + //Called when the optional timer interval attribute is changed + _intervalChange: function (newInterval) { + logger.debug(this.id + "._intervalChange"); + + this.interval = newInterval; + + if (this._timerStarted) { + this._stopTimer(); + this._runTimer(); + } + }, + + _runTimer: function() { + logger.debug(this.id + "._runTimer", this.interval); + if (this.callEvent !== "" && this._contextObj) { + this._timerStarted = true; + + //if there's a first interval, get and use that first, then use the regular interval + if (this.firstIntervalAttr) { + var firstInterval = this._contextObj.get(this.firstIntervalAttr); + + if (this.once) { + this._timeout = setTimeout(lang.hitch(this, this._executeEvent), firstInterval); + } else { + if (this.startatonce) { + this._executeEvent(); + } + this._timeout = setTimeout(lang.hitch(this, function() { + this._executeEvent(); + this._timer = setInterval(lang.hitch(this, this._executeEvent), this.interval); + }), firstInterval); + } + //otherwise just use the regulat interval + } else { + if (this.once) { + this._timeout = setTimeout(lang.hitch(this, this._executeEvent), this.interval); + } else { + if (this.startatonce) { + this._executeEvent(); + } + this._timer = setInterval(lang.hitch(this, this._executeEvent), this.interval); + } + } + } + }, + + _stopTimer: function() { + logger.debug(this.id + "._stopTimer"); + this._timerStarted = false; + + if (this._timer !== null) { + logger.debug(this.id + "._stopTimer timer cleared"); + clearInterval(this._timer); + this._timer = null; + } + if (this._timeout !== null) { + logger.debug(this.id + "._stopTimer timeout cleared"); + clearTimeout(this._timeout); + this._timeout = null; + } + }, + + _executeEvent: function() { + if (this._flowRunning === true) { + return; + } + + this._flowRunning = true; + + if(this.callEvent === "callMicroflow" && this.microflow) { + this._execMf() + } else if (this.callEvent === "callNanoflow" && this.nanoflow.nanoflow){ + this._executeNanoFlow() + } else { + return; + } + }, + + _execMf: function() { + logger.debug(this.id + "._execMf"); + if (!this._contextObj) { + return; } - this._flowRunning = false; - }), - error: lang.hitch(this, function (error) { - logger.error( - this.id + ": An error ocurred while executing nanoflow: ", - error - ); - this._flowRunning = false; - }), - }); - } - }, - - // Reset subscriptions. - _resetSubscriptions: function () { - this.unsubscribeAll(); - - // When a mendix object exists create subscribtions. - if (this._contextObj && this.timerStatusAttr) { - this.subscribe({ - guid: this._contextObj.getGuid(), - callback: lang.hitch(this, function (guid) { - this._checkTimerStatus(); - }), - }); - - this.subscribe({ - guid: this._contextObj.getGuid(), - attr: this.timerStatusAttr, - callback: lang.hitch(this, function (guid, attr, attrValue) { - this._checkTimerStatus(); - }), - }); - - this.subscribe({ - guid: this._contextObj.getGuid(), - attr: this.intervalAttr, - callback: lang.hitch(this, function (guid, attr, attrValue) { - this._intervalChange(); - }), - }); - } - }, - - _executeCallback: function (cb, from) { - logger.debug( - this.id + "._executeCallback" + (from ? " from " + from : "") - ); - if (cb && typeof cb === "function") { - cb(); - } - }, - }); + + if (this.microflow) { + var mfObject = { + params: { + actionname: this.microflow, + applyto: "selection", + guids: [this._contextObj.getGuid()] + }, + callback: lang.hitch(this, function(result) { + if (!result) { + logger.debug(this.id + "._execMf callback, stopping timer"); + this._stopTimer(); + } + this._flowRunning = false; + }), + error: lang.hitch(this, function(error) { + logger.error(this.id + ": An error ocurred while executing microflow: ", error); + this._flowRunning = false; + }) + }; + + if (!mx.version || mx.version && parseInt(mx.version.split(".")[0]) < 6) { + mfObject.store = { + caller: this.mxform + }; + } else { + mfObject.origin = this.mxform; + } + + mx.data.action(mfObject, this); + } + }, + + _executeNanoFlow: function() { + if (this.nanoflow.nanoflow && this.mxcontext) { + mx.data.callNanoflow({ + nanoflow: this.nanoflow, + origin: this.mxform, + context: this.mxcontext, + callback: lang.hitch(this, function(result) { + if (!result) { + logger.debug(this.id + "._executeNanoFlow callback, stopping timer"); + this._stopTimer(); + } + this._flowRunning = false; + }), + error: lang.hitch(this, function(error) { + logger.error(this.id + ": An error ocurred while executing nanoflow: ", error); + this._flowRunning = false; + }) + }); + } + }, + + // Reset subscriptions. + _resetSubscriptions: function() { + this.unsubscribeAll(); + + // When a mendix object exists create subscribtions. + if (this._contextObj && this.timerStatusAttr) { + this.subscribe({ + guid: this._contextObj.getGuid(), + callback: lang.hitch(this, function(guid) { + this._checkTimerStatus(); + }) + }); + + this.subscribe({ + guid: this._contextObj.getGuid(), + attr: this.timerStatusAttr, + callback: lang.hitch(this, function(guid, attr, attrValue) { + this._checkTimerStatus(); + }) + }); + + this.subscribe({ + guid: this._contextObj.getGuid(), + attr: this.intervalAttr, + callback: lang.hitch(this, function(guid, attr, attrValue) { + this._intervalChange(); + }) + }); + } + }, + + _executeCallback: function (cb, from) { + logger.debug(this.id + "._executeCallback" + (from ? " from " + from : "")); + if (cb && typeof cb === "function") { + cb(); + } + } + }); }); -require(["MicroflowTimer/widget/MicroflowTimer"]); +require(["MicroflowTimer/widget/MicroflowTimer"])