Skip to content

Commit d8e5839

Browse files
authored
Update predbat-table-card.js
Adding support for debug mode and LIMIT column
1 parent 2fb83ac commit d8e5839

File tree

1 file changed

+61
-9
lines changed

1 file changed

+61
-9
lines changed

predbat-table-card.js

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ class PredbatTableCard extends HTMLElement {
593593

594594
} else if(column === "state-column"){
595595

596-
596+
// alert ⚠
597+
597598
newContent = theItem.value.replace(/[]/g, '').trim();
598599
newContent = this.adjustStatusFields(newContent);
599600

@@ -655,14 +656,30 @@ class PredbatTableCard extends HTMLElement {
655656
} else if(column === "limit-column"){
656657

657658
if(theItem.value.replace(/\s/g, '').length > 0){
659+
660+
let debugSVG = ``;
661+
let debugString = theItem.value;
662+
663+
if (theItem.value.includes("(") || theItem.value.includes(")")) {
664+
const match = theItem.value.match(/(\d+)\s*\((\d+)\)/);
665+
// match[1]
666+
debugSVG = `<svg version="1.1" width="26" height="26" id="limitSVG">
667+
<circle cx="13" cy="13" r="11" stroke="#2a3240" stroke-width="1" stroke-dasharray="5,3" fill="#e1e1e1"/>
668+
<text class="pill" x="13" y="14" dominant-baseline="middle" text-anchor="middle" fill="#2a3240" font-size="10">${match[2]}</text>
669+
</svg>`;
670+
debugString = match[1];
671+
//console.log('Match: ' + match);
672+
}
673+
674+
const mainSVG = `<svg version="1.1" width="26" height="26" id="limitSVG">
675+
<circle cx="13" cy="13" r="11" stroke="#2a3240" stroke-width="2" fill="#e1e1e1"/>
676+
<text class="pill" x="13" y="14" dominant-baseline="middle" text-anchor="middle" fill="#2a3240" font-size="10" font-weight="bold">${debugString}</text>
677+
</svg>`;
658678

659679
newCell.innerHTML = `
660680
661681
<div class="iconContainer">
662-
<svg version="1.1" width="26" height="26" id="limitSVG">
663-
<circle cx="13" cy="13" r="11" stroke="#2a3240" stroke-width="2" fill="#e1e1e1"/>
664-
<text class="pill" x="13" y="14" dominant-baseline="middle" text-anchor="middle" fill="#2a3240" font-size="10"} font-weight="bold">${theItem.value}</text>
665-
</svg>
682+
${mainSVG} ${debugSVG}
666683
</div>`;
667684

668685
}
@@ -1167,11 +1184,9 @@ class PredbatTableCard extends HTMLElement {
11671184
});
11681185
}
11691186
}
1170-
1171-
newTRObject[headerClassesArray[headerIndex]] = {"value": tdElement.innerHTML, "color": bgColor};
1172-
1173-
11741187

1188+
newTRObject[headerClassesArray[headerIndex]] = {"value": tdElement.innerHTML, "color": bgColor};
1189+
11751190
//exception||override for 12 cells and 11 headers (-1 count difference) and handling index 2
11761191
if(countDifference < 0 && tdIndex == 3) {
11771192
// having to do some nasty overrides here because of colspan stuff and my brain cant do the math today. will fix.
@@ -1210,11 +1225,48 @@ class PredbatTableCard extends HTMLElement {
12101225
newDataObject.push(newTRObject);
12111226
}
12121227

1228+
1229+
12131230
});
12141231

12151232
// Get the modified HTML
1233+
1234+
//const newDate = this.getStringToDate(newDataObject[30]['time-column'].value);
1235+
1236+
//console.log(newDate);
1237+
//console.log(newDataObject[30]['time-column'].value);
1238+
12161239
return newDataObject;
12171240
}
1241+
1242+
getStringToDate(input) {
1243+
const [day, time] = input.split(' '); // Split into "Tue" and "09:00"
1244+
const [hours, minutes] = time.split(':').map(Number); // Split and convert time to numbers
1245+
1246+
// Map days of the week to numbers (Sunday = 0, Monday = 1, ..., Saturday = 6)
1247+
const dayMap = { Sun: 0, Mon: 1, Tue: 2, Wed: 3, Thu: 4, Fri: 5, Sat: 6 };
1248+
const targetDay = dayMap[day];
1249+
1250+
if (targetDay === undefined) {
1251+
throw new Error('Invalid day in input');
1252+
}
1253+
1254+
// Get today's date
1255+
const now = new Date();
1256+
const currentDay = now.getDay();
1257+
1258+
// Calculate the difference between today and the target day
1259+
const dayDifference = (targetDay - currentDay + 7) % 7; // Ensures it's positive
1260+
const targetDate = new Date(now);
1261+
1262+
// Set the target date to the upcoming target day
1263+
targetDate.setDate(now.getDate() + dayDifference);
1264+
1265+
// Set the time
1266+
targetDate.setHours(hours, minutes, 0, 0);
1267+
1268+
return targetDate;
1269+
}
12181270

12191271
getStyles(isDarkMode) {
12201272

0 commit comments

Comments
 (0)