I’ve setup the MagicMirror as digital calendar using a raspberry pi and portable touchscreen (in portrait orientation). The display in essence resembles the image shown here.
![alt text]https://drive.google.com/file/d/1-sQmG7VDPnp1sjRKCc-74JwL0Dd8rJCB/view?usp=sharing
The calendar module I’ve used is the MMM-CalendarExt3 module. What I am trying to achieve is add 3 buttons to the MMM-CalendarExt3.js code that will allow me dynamically switch (on demand) the current calendar view from the current month, to either the previous month or next, and back.
The settings of my MMM-CalendarExt3 module in config.js are pretty basic, like so:
…,
{
module: “MMM-CalendarExt3”,
position: “bottom_bar”,
title: “Our Family Calendar”,
config: {
mode: “month”,
cellDateOptions: { day: ‘numeric’ }, // suppress month from appear in cellDate
monthIndex: 0, //0=curr_month, -1=prev, 1=next
instanceId: “basicCalendar”,
maxEventLines: 6,
firstDayOfWeek: 0,
calendarSet: [],
fontSize: ‘18px’,
}
}, …
The (failed) modifications I’ve made to the getDom() function in the MMM-CalendarExt3.js module are as follows:
getDom() {
let dom = document.createElement("div");
dom.innerHTML = "";
dom.classList.add("bodice", `CX3_${this.activeConfig.instanceId}`, "CX3");
if (this.activeConfig.fontSize) {
dom.style.setProperty("--fontsize", this.activeConfig.fontSize);
}
// Add button container
const buttonContainer = document.createElement("div");
buttonContainer.style.display = "flex";
buttonContainer.style.justifyContent = "center";
buttonContainer.style.marginBottom = "10px";
buttonContainer.style.position = "absolute"; // Ensure it stays on top
buttonContainer.style.top = "10px"; // Position it at the top
buttonContainer.style.left = "50%"; // Center horizontally
buttonContainer.style.transform = "translateX(-50%)"; // Adjust centering
buttonContainer.style.zIndex = "1000"; // Ensure it stays above other elements
buttonContainer.style.backgroundColor = "rgba(255, 255, 255, 0.9)"; // Optional: Add background for better visibility
buttonContainer.style.padding = "5px"; // Optional: Add padding for aesthetics
buttonContainer.style.borderRadius = "5px"; // Optional: Add rounded corners
const prevButton = document.createElement("button");
prevButton.innerHTML = "Previous Month";
prevButton.style.margin = "0 5px";
prevButton.onclick = () => {
this.sendNotification("CX3_SET_CONFIG", { monthIndex: this.activeConfig.monthIndex - 1 });
};
const currentButton = document.createElement("button");
currentButton.innerHTML = "Current Month";
currentButton.style.margin = "0 5px";
currentButton.onclick = () => {
this.sendNotification("CX3_SET_CONFIG", { monthIndex: 0 });
};
const nextButton = document.createElement("button");
nextButton.innerHTML = "Next Month";
nextButton.style.margin = "0 5px";
nextButton.onclick = () => {
this.sendNotification("CX3_SET_CONFIG", { monthIndex: this.activeConfig.monthIndex + 1 });
};
buttonContainer.appendChild(prevButton);
buttonContainer.appendChild(currentButton);
buttonContainer.appendChild(nextButton);
dom.appendChild(buttonContainer);
if (!this.library?.loaded) {
Log.warn("[CX3] Module is not prepared yet, wait a while.");
return dom;
}
dom = this.draw(dom, this.activeConfig);
if (this.refreshTimer) {
clearTimeout(this.refreshTimer);
this.refreshTimer = null;
this.refreshTimer = setTimeout(() => {
clearTimeout(this.refreshTimer);
this.refreshTimer = null;
this.updateAnimate();
}, this.activeConfig.refreshInterval);
}
return dom;
}
The 3 issues I’ve encountered with the above code are as follows:
-
The above modification added the 3 buttons below the month heading (not beside, as shown in my image link). This is not really an issue.
-
The buttons appear momentarily at startup, and then get eclipsed (covered over) by the rest of the calendar cells when they render and appear. This is a problem since the buttons are not visible for users to tap.
-
MagicMirror seems to have disabled the “mouse cursor” and hence the ability for the buttons (previous month, current month, next month) to respond to user taps on the touchscreen.
Does anyone know of a workaround or suitable modules I can deploy to fit my requirements? If so, I would be grateful to hear from you.