Read the statement by Michael Teeuw here.
read csv-data and put it in an array
-
@Perlchamp click on line number 122 for a stop… birthday is not defined once you leave the for loop…
-
yes i did. all variables are correct
-
@Perlchamp and getDom() will be called multiple times, once before your data arrives, maybe once more than when you data is ready
and it does the innerText statement?
and u look at the element, and look at the inner text and its correct?
i am running out of energy for the day… been since 6am. now 11pm
-
122 => next => marks “return”(131) => next => marks end of 131 => next => jumped to main.js
-
@Perlchamp mark the line for the second for(
for(var birthday of Object.keys(this.active_birthdays)){ for(var name of this.active_birthdays[birthday]){ // stop on this line
and remove the other stops
-
the same see picture i did send to you. it’s line 122 => stop => refresh => and than like posted before
no does nothing … ok never mind. coming from germany it’s now 06:00 in the morning did’t sleep … -
@Perlchamp tomorrow, very close
-
don’t worry about me and sleep well.
-
@Perlchamp thx…
in debugging
put a stop on the self.updateDom() in the notiification code.
no place elsehit refresh
when it stops there,
scroll down to getdom and add a stop on the 1st for loop linehit run arrow,
should stop in getdom now, with data -
@perl here is the updated perlchamp.js, shows date, persons name and age (no formatting)
Module.register("perlchamp", { defaults: { language: "de", dimmEntries: true, // true: dims entries and the associated // symbol when the date has expired. // false: delete entries and the associated // symbol when the date has expired. // used if look forward is desired, add to module config in config.js days_forward:0, }, // place to save birthdays to display active_birthdays : {}, init: function(){ Log.log(this.name + " is in init!"); }, start: function(){ Log.log("Starting module: " + this.name); // Set locale moment.locale(config.language); }, loaded: function(callback) { Log.log(this.name + " is loaded!"); callback(); }, // return list of other functional scripts to use, if any (like require in node_helper) getScripts: function() { return ["moment.js"]; }, // return list of stylesheet files to use if any getStyles: function() { return [this.data.path + "/css/perlchamp.css"]; }, /* // return list of translation files to use, if any getTranslations: function() { return { // sample of list of files to specify here, if no files, do not use this routine, , or return empty list // en: "translations/en.json", (folders and filenames in your module folder) // de: "translations/de.json" } }, */ // only called if the module header was configured in module config in config.js getHeader: function() { return this.data.header; }, // messages received from other modules and the system (NOT from your node helper) // payload is a notification dependent data structure notificationReceived: function(notification, payload, sender) { // once everybody is loaded up if(notification==="ALL_MODULES_STARTED"){ // send our config to our node_helper this.sendSocketNotification("CONFIG",this.config); } if (sender) { Log.log(this.name + " received a module notification: " + notification + " from sender: " + sender.name); } else { Log.log(this.name + " received a system notification: " + notification); } }, // messages received from from your node helper (NOT other modules or the system) // payload is a notification dependent data structure, up to you to design between module and node_helper socketNotificationReceived: function(notification, payload) { /* Log.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload); if(notification === "message_from_helper"){ this.config.message = payload; // tell mirror runtime that our data has changed, // we will be called back at GetDom() to provide the updated content this.updateDom(1000); } */ if(notification === "have data"){ var self = this Log.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload); var now = moment(); // clear the old list this.active_birthdays={} // only calculate in advance once var birthday_time_window=moment().add(self.config.days_forward,'days') // loop thru the birthdays from the file for( var birthday of payload) { // get 1st 5 chars of birthdate, thru month // we will use this as the key in the hash var birth_date=birthday.birth.substring(0,5) // get the birthday as a moment in this year, for comparing var birth_date_moment = moment(birth_date+now.year(),"DD.MMYYYY") // u can add days to a moment object and then compare if the birthdate is before that date (and after now) // so within the next xx days // if the date is the same or later, don't use time of day if(birth_date_moment.startOf('day').isSameOrAfter(now.startOf('day')) && birth_date_moment.startOf('day').isSameOrBefore(birthday_time_window.startOf('day')) ){ // birthday is in this month // check the hash if we've seen anything for today yet // if we haven't see this date yet if(self.active_birthdays[birth_date] == undefined){ // create the holder for its info (array of info) in the hash self.active_birthdays[birth_date]=[] } // save the persons name and age on the list self.active_birthdays[birth_date].push({'name':birthday.name, 'age': now.diff(moment(birthday.birth,'DD.MM.YYYY'), 'years') }) } } // tell MM to call and get our content self.updateDom(); } /* this.config.message = payload; // tell mirror runtime that our data has changed, // we will be called back at GetDom() to provide the updated content this.updateDom(1000) // filters the birthdaylist and output only the birthdays // of the current month, sorted (ascending) by days in // the following format: // [{ day: "10", name: ["firstname lastname",...] }] // set variables var today_month = moment().format("MM"); var today_day_month = moment().format("DD.MM"); var result = Object.entries(jsonObj .filter(({birth}) => birth.split('.')[1] === today_month) .reduce((a, {birth, name}) => { const day = +birth.split('.')[0]; a[day] = [...(a[day] || []), name]; return a }, {}) ).map(([day, name]) => ({day, name})).sort((a, b) => +a.day - b.day); birthdaysArray = result; // for debugging only //console.log("filtered and sorted: ", birthdaysArray); */ }, // system notification your module is being hidden // typically you would stop doing UI updates (getDom/updateDom) if the module is hidden suspend: function(){ }, // system notification your module is being unhidden/shown // typically you would resume doing UI updates (getDom/updateDom) if the module is shown resume: function(){ }, // this is the major worker of the module, it provides the displayable content for this module getDom: function() { var wrapper = document.createElement("div"); // create your table and header here for(var birthday of Object.keys(this.active_birthdays)){ for(var person of this.active_birthdays[birthday]){ var m=document.createElement('div') // create tyour table row here m.innerText=birthday+ ' '+ person.name+' age='+person.age wrapper.appendChild(m) } } // create your table footer here // pass the created content back to MM to add to DOM. return wrapper; } })
this is the birthdays.csv I was using
the column names are the field names in the jsonobjbirth, name 12.07.1952, Sam 11.09.1944, Peg 02.05.1939, Frank 09.04.1953, June 09.04.1953, Jane 30.12.1955, Joan 02.05.1939, Sue 05.05.1955, mary