Skip to content

Commit 9fabaf4

Browse files
committed
Refresh by Interval
Automatically Reload the content and page after a certain interval
1 parent 9ec22c6 commit 9fabaf4

1,633 files changed

Lines changed: 119286 additions & 58 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/DataviewLoader/DataviewLoader.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
<attributeType name="Boolean" />
3535
</attributeTypes>
3636
</property>
37+
<property key="refreshTime" type="integer" defaultValue="0">
38+
<caption>Reload each seconds</caption>
39+
<category>Refresh</category>
40+
<description>Reload the content each X interval of seconds. 0 = disabled</description>
41+
</property>
3742
<property key="fadeContent" type="boolean" defaultValue="false">
3843
<caption>Fade in content</caption>
3944
<category>Behavior</category>

src/DataviewLoader/widget/DataviewLoader.js

Lines changed: 74 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ define([
4040

4141
// DOM elements
4242
divContent: null,
43-
divLoader: null,
43+
divLoader: null,
4444

4545
// Internal variables. Non-primitives created in the prototype are shared between all widget instances.
4646
_handles: null,
@@ -49,7 +49,7 @@ define([
4949
_pageInitiated: false,
5050
_form: null,
5151
active: true,
52-
prevForm : null,
52+
prevForm: null,
5353
// dojo.declare.constructor is called to construct the widget instance. Implement to initialize non-primitive properties.
5454
constructor: function () {
5555
//logger.debug(this.id + ".constructor");
@@ -59,26 +59,26 @@ define([
5959
// dijit._WidgetBase.postCreate is called after constructing the widget. Implement to do extra setup work.
6060
postCreate: function () {
6161
logger.debug(this.id + ".postCreate");
62-
63-
62+
63+
6464
this._updateRendering();
6565
this._setupEvents();
6666
},
6767

6868
// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
6969
update: function (obj, callback) {
70-
if(this._contextObj !== obj){
70+
if (this._contextObj !== obj) {
7171
console.log(this.id + ".update on new object");
7272
this._loadingStarted = false;
7373
this._pageInitiated = false;
74-
74+
7575
this._contextObj = obj;
7676
this._resetSubscriptions();
7777
this._updateRendering(callback); // We're passing the callback to updateRendering to be called after DOM-manipulation
7878
} else {
7979
// The callback, coming from update, needs to be executed, to let the page know it finished rendering
8080
this._executeCallback(callback, "update");
81-
}
81+
}
8282
},
8383

8484
// mxui.widget._WidgetBase.enable is called when the widget should enable editing. Implement to enable editing if widget is input widget.
@@ -96,13 +96,13 @@ define([
9696
console.log(this.id + ".resize");
9797
// TODO: How to handle tabs and conditional visibility
9898
if (this.domNode.offsetParent !== null && this.visibilityCheck) {
99-
if(this.refreshAction == "Attribute" && this.refreshtAttr && this._contextObj) {
99+
if (this.refreshAction == "Attribute" && this.refreshtAttr && this._contextObj) {
100100
if (this._contextObj.get(this.refreshtAttr))
101101
this._loadAndShowcontent();
102102
else
103103
console.log(this.id + ".resize Skip because " + this.refreshtAttr + " is false");
104104
} else {
105-
this._loadAndShowcontent();
105+
this._loadAndShowcontent();
106106
}
107107
}
108108
},
@@ -112,8 +112,8 @@ define([
112112
logger.debug(this.id + ".uninitialize");
113113
// Clean up listeners, helper objects, etc. There is no need to remove listeners added with this.connect / this.subscribe / this.own.
114114
this.active = false;
115-
116-
if(this._form != null){
115+
116+
if (this._form != null) {
117117
this._form.destroy();
118118
}
119119
},
@@ -128,25 +128,39 @@ define([
128128

129129
// Attach events to HTML dom elements
130130
_setupEvents: function () {
131-
//logger.debug(this.id + "._setupEvents");
132-
if(this.fadeContent){
131+
// Set fading of content
132+
if (this.fadeContent) {
133133
dojoClass.add(this.divContent, "loaderfade");
134134
}
135+
136+
// Set refreshing each time
137+
if (this.refreshTime > 0) {
138+
setInterval(dojoLang.hitch(this, function () {
139+
if (this._loadingStarted == false) {
140+
if (this.pageMF) {
141+
this._pageInitiated = false;
142+
}
143+
this._updateRendering();
144+
} else {
145+
console.log(this.id + ".Refresh skip because of loading started.");
146+
}
147+
}), this.refreshTime * 1000);
148+
}
135149
},
136150

137151
// Rerender the interface.
138152
_updateRendering: function (callback) {
139153
logger.debug(this.id + "._updateRendering");
140154

141155
if (this._contextObj) {
142-
if(this.loadingText){
143-
var text = "<div class=\"text-center\"><h3 class=\"loaderheader\">"+this.loadingText+"</h3></div>";
156+
if (this.loadingText && this.divLoader.innerHTML.indexOf(this.loadingText) === -1) {
157+
var text = "<div class=\"text-center\"><h3 class=\"loaderheader\">" + this.loadingText + "</h3></div>";
144158
this.divLoader.innerHTML = text + this.divLoader.innerHTML;
145159
}
146-
160+
147161
dojoStyle.set(this.divContent, "display", "none");
148162
dojoStyle.set(this.divLoader, "display", "block");
149-
163+
150164
if (this.domNode.offsetParent !== null || !this.visibilityCheck) {
151165
this._loadAndShowcontent();
152166
}
@@ -158,7 +172,7 @@ define([
158172

159173
_loadAndShowcontent: function () {
160174
logger.debug(this.id + "._loadAndShowcontent");
161-
if(this._loadingStarted == false){
175+
if (this._loadingStarted == false) {
162176
this._loadingStarted = true;
163177
if (this._contextObj && this.loadingMF) {
164178
this._execMf(this.loadingMF, this._contextObj.getGuid(), this._processMicroflowCallback, this._processMicroflowFailure);
@@ -171,26 +185,26 @@ define([
171185
_processMicroflowCallback: function (objs) {
172186
logger.debug(this.id + '._processMicroflowCallback');
173187
if (this.active) {
174-
if(this.asyncCall)
188+
if (this.asyncCall)
175189
this._setPage(this._contextObj);
176190
else
177191
this._setPage(objs[0]);
178192
} else {
179-
console.info(this.id + "._processMicroflowCallback Skip loading because widget is destroyed.");
193+
console.info(this.id + "._processMicroflowCallback Skip loading because widget is destroyed.");
180194
}
181195
},
182-
_processMicroflowFailure: function (){
183-
if(this.errorText){
184-
if(this._pageInitiated)
196+
_processMicroflowFailure: function () {
197+
if (this.errorText) {
198+
if (this._pageInitiated)
185199
this._form.close();
186200
this._pageInitiated = false;
187-
this.divContent.innerHTML= "<div class=\"text-center\"><h3 class=\"loaderheader\">"+this.errorText+"</h3></div>";
201+
this.divContent.innerHTML = "<div class=\"text-center\"><h3 class=\"loaderheader\">" + this.errorText + "</h3></div>";
188202

189203
this._showPage();
190204
}
191205
},
192-
193-
_openFormByFormProp : function (pageContext){
206+
207+
_openFormByFormProp: function (pageContext) {
194208
var props = {
195209
location: "node",
196210
domNode: this.divContent,
@@ -199,14 +213,14 @@ define([
199213
console.log(error.description);
200214
}
201215
};
202-
203-
if(pageContext)
216+
217+
if (pageContext)
204218
props.context = pageContext;
205219
this._form = mx.ui.openForm(this.pageContent, props);
206220
},
207-
208-
_openFormByMF : function(pageObj, pageContext){
209-
this._execMf(this.pageMF, pageObj.getGuid(), function(response){
221+
222+
_openFormByMF: function (pageObj, pageContext) {
223+
this._execMf(this.pageMF, pageObj.getGuid(), function (response) {
210224
this._form = mx.ui.openForm(response, {
211225
context: pageContext,
212226
location: "node",
@@ -216,55 +230,57 @@ define([
216230
console.log(error.description);
217231
}
218232
});
219-
}, function(){alert("Error bij aanroepen custom form MF");});
233+
}, function () {
234+
alert("Error bij aanroepen custom form MF");
235+
});
220236
},
221237

222238
_setPage: function (pageObj) {
223239
logger.debug(this.id + '._setPage');
224240

225-
if(this._pageInitiated) {
241+
if (this._pageInitiated) {
226242
if (this._loadingStarted) {
227243
this._showPage();
228244
} else {
229245
console.log(this.id + "_setPage skip because already set.");
230246
}
231247
} else {
232248
this._pageInitiated = true;
233-
this.divContent.innerHTML= "";
249+
this.divContent.innerHTML = "";
234250
console.log(this.id + "_setPage");
235251
if (pageObj) {
236252
var pageContext = new mendix.lib.MxContext();
237253
pageContext.setTrackObject(pageObj);
238-
239-
if(this.pageMF != null && this.pageMF != '')
254+
255+
if (this.pageMF != null && this.pageMF != '')
240256
this._openFormByMF(pageObj, pageContext);
241-
else
257+
else
242258
this._openFormByFormProp(pageContext);
243-
259+
244260
} else {
245-
if(this.pageMF != null && this.pageMF != '')
261+
if (this.pageMF != null && this.pageMF != '')
246262
alert("Page microflow is not supported without context");
247-
else
263+
else
248264
this._openFormByFormProp();
249-
265+
250266
}
251267
}
252268
},
253269

254270
_showPage: function (mxform) {
255271
logger.debug(this.id + "._showPage on form");
256-
257-
if(this.prevForm != null && mxform != null){
272+
273+
if (this.prevForm != null && mxform != null) {
258274
this.prevForm.destroy();
259275
}
260276
this.prevForm = mxform;
261-
277+
262278
dojoStyle.set(this.divContent, "display", "block");
263279
dojoStyle.set(this.divLoader, "display", "none");
264-
280+
265281
this._loadingStarted = false;
266282
},
267-
283+
268284
// Reset subscriptions.
269285
_resetSubscriptions: function () {
270286
logger.debug(this.id + "._resetSubscriptions");
@@ -277,37 +293,39 @@ define([
277293
this.subscribe({
278294
guid: this._contextObj.getGuid(),
279295
callback: dojoLang.hitch(this, function (guid) {
280-
if(this._loadingStarted == false){
281-
if(this.pageMF) {
296+
if (this._loadingStarted == false) {
297+
if (this.pageMF) {
282298
this._pageInitiated = false;
283299
}
284-
if(this.refreshAction == "Attribute" && this.refreshtAttr && this._contextObj.get(this.refreshtAttr)){
300+
if (this.refreshAction == "Attribute" && this.refreshtAttr && this._contextObj.get(this.refreshtAttr)) {
285301
console.log(this.id + ".Refresh triggered on attribute change.");
286302
this._updateRendering();
287-
} else if(this.refreshAction == "Object") {
303+
} else if (this.refreshAction == "Object") {
288304
console.log(this.id + ".Refresh triggered on object change.");
289305
this._updateRendering();
290-
}
306+
}
291307
} else {
292308
console.log(this.id + ".Refresh skip because of loading started.");
293309
}
294310
})
295311
});
296312
}
297313
},
298-
314+
299315
_execMf: function (mf, guid, cb, cbfailure) {
300316
logger.debug(this.id + "._execMf" + (mf ? ": " + mf : ""));
301317
if (mf && guid) {
302-
mx.ui.action(mf, {
303-
async : this.asyncCall,
318+
mx.data.action({
304319
params: {
305320
applyto: "selection",
321+
actionname: mf,
306322
guids: [guid]
307323
},
324+
async: this.asyncCall,
325+
origin: this.mxform,
308326
callback: (cb && typeof cb === "function" ? dojoLang.hitch(this, cb) : null),
309327
error: (cbfailure && typeof cbfailure === "function" ? dojoLang.hitch(this, cbfailure) : null)
310-
}, this);
328+
});
311329
}
312330
},
313331

@@ -320,4 +338,4 @@ define([
320338
});
321339
});
322340

323-
require(["DataviewLoader/widget/DataviewLoader"]);
341+
require(["DataviewLoader/widget/DataviewLoader"]);

src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="DataviewLoader" version="2.1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="DataviewLoader" version="2.2.0" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="DataviewLoader/DataviewLoader.xml" />
66
</widgetFiles>

test/.mendix-cache/base_data

10 KB
Binary file not shown.

test/.mendix-cache/base_rev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
29
1+
33

test/.svn/wc.db

0 Bytes
Binary file not shown.

test/DataviewLoader.mpr

14 KB
Binary file not shown.

test/packages/DataviewLoader.mpk

15.8 MB
Binary file not shown.

test/widgets/DataviewLoader.mpk

149 Bytes
Binary file not shown.

test8/.classpath

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="javasource"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="lib" path="C:/Program Files/Mendix/8.2.2.60770/runtime/bundles/com.mendix.json.jar"/><classpathentry kind="lib" path="C:/Program Files/Mendix/8.2.2.60770/runtime/bundles/com.mendix.logging-api.jar"/><classpathentry kind="lib" path="C:/Program Files/Mendix/8.2.2.60770/runtime/bundles/com.mendix.m2ee-api.jar"/><classpathentry kind="lib" path="C:/Program Files/Mendix/8.2.2.60770/runtime/bundles/com.mendix.public-api.jar"/><classpathentry kind="lib" path="C:/Program Files/Mendix/8.2.2.60770/runtime/bundles/javax.servlet-api.servlet.jar"/>
6+
<classpathentry kind="lib" path="userlib/animal-sniffer-annotations-1.17.jar"/><classpathentry kind="lib" path="userlib/antisamy-1.5.3.jar"/><classpathentry kind="lib" path="userlib/axiom-api-1.2.12.jar"/><classpathentry kind="lib" path="userlib/checker-qual-2.5.2.jar"/><classpathentry kind="lib" path="userlib/com.google.guava-14.0.1.jar"/><classpathentry kind="lib" path="userlib/com.springsource.org.apache.batik.css-1.7.0.jar"/><classpathentry kind="lib" path="userlib/commons-codec-1.10.jar"/><classpathentry kind="lib" path="userlib/commons-io-2.6.jar"/><classpathentry kind="lib" path="userlib/commons-lang-2.5.jar"/><classpathentry kind="lib" path="userlib/commons-lang3-3.7.jar"/><classpathentry kind="lib" path="userlib/commons-logging-1.1.jar"/><classpathentry kind="lib" path="userlib/commons-logging-1.2.jar"/><classpathentry kind="lib" path="userlib/error_prone_annotations-2.2.0.jar"/><classpathentry kind="lib" path="userlib/fontbox-2.0.13.jar"/><classpathentry kind="lib" path="userlib/guava-27.0-jre.jar"/><classpathentry kind="lib" path="userlib/guice-2.0.jar"/><classpathentry kind="lib" path="userlib/j2objc-annotations-1.1.jar"/><classpathentry kind="lib" path="userlib/jempbox-1.8.5.jar"/><classpathentry kind="lib" path="userlib/joda-time-2.9.6.jar"/><classpathentry kind="lib" path="userlib/jsr305-3.0.2.jar"/><classpathentry kind="lib" path="userlib/nekohtml.jar"/><classpathentry kind="lib" path="userlib/openid4java-1.0.0.jar"/><classpathentry kind="lib" path="userlib/org.apache.commons.fileupload-1.2.1.jar"/><classpathentry kind="lib" path="userlib/org.apache.commons.io-2.3.0.jar"/><classpathentry kind="lib" path="userlib/org.apache.commons.lang3.jar"/><classpathentry kind="lib" path="userlib/org.apache.httpcomponents.httpclient-osgi.jar"/><classpathentry kind="lib" path="userlib/org.apache.httpcomponents.httpcore-osgi.jar"/><classpathentry kind="lib" path="userlib/owasp-java-html-sanitizer-20181114.1.jar"/><classpathentry kind="lib" path="userlib/pdfbox-2.0.13.jar"/><classpathentry kind="lib" path="userlib/pdfbox-app-2.0.3.jar"/><classpathentry kind="lib" path="userlib/xml-apis-ext.jar"/>
7+
<classpathentry kind="output" path="deployment/run/bin"/>
8+
</classpath>

0 commit comments

Comments
 (0)