Now create MMM-Dnevni_citat.js
Inside you need first to registar module
Module.register("MMM-Dnevni_citat", {
defaults: {
updateInterval: 10 x 60 x 1000, // minute ,seconds ,milliseconds
//retryDelay: 5000 // not needed for now
},
Then first function will be start function
start: function () {
Log.info("Starting module: " + this.name);
requiresVersion: "2.1.0";
this.loaded = false;
this.scheduleUpdate();
},
with first function we are calling second ( scheduleUpdate) , how often will fetch data.
scheduleUpdate: function () {
setInterval(() => {
this.getData();
}, this.config.updateInterval);
this.getData();
},
Then we are calling getData function. Sending socketNotification to node_helper.
getData: function () {
this.sendSocketNotification(''GET_TEXT_DATA'', this.config);
},
Whe node_helper send back, next function will check if data is received and update DOM
socketNotificationReceived: function (notification, payload) {
if (notification === "TEXT_RESULT") {
this.textDataRecived = payload;
this.loaded = true;
},this.updateDom();
Now only is left to create DOM
getDom: function () {
var wrapper = document.createElement("div");
if (!this.loaded) {
wrapper.innerHTML = "LOADING";
return wrapper;
}
if (this.loaded) {
// here to add elements and styling
return wrapper;
}
},