refactor: refs #6555 check if is Empty
gitea/worker-time-control/pipeline/pr-test This commit looks good Details

This commit is contained in:
jorgep 2024-06-19 13:18:43 +02:00
parent 496182fa54
commit 5e1a5f313a
1 changed files with 9 additions and 8 deletions

View File

@ -91,11 +91,11 @@ function printTimetable(timetable) {
const liTotals = createElement("li", {});
timetable.forEach((row, index) => {
for (let day = weekDays.length - 1; day >= 0; day--) {
const img = createElement("img", { attrs: { src: ifIsEmptyImage(row[`${day}daysAgoDirection`]) } });
const p = createElement("p", { text: ifIsEmptyText(row[`${day}daysAgo`]) });
const img = createElement("img", { attrs: { src: isEmpty(row[`${day}daysAgoDirection`], "image") } });
const p = createElement("p", { text: isEmpty(row[`${day}daysAgo`], "text") });
const innerDiv = createElement("div", { childs: [img, p] });
const outerDiv = createElement("div", { classes: ["time", ifIsEmpty(row[`${day}daysAgo`])], childs: [innerDiv] });
const outerDiv = createElement("div", { classes: ["time", isEmpty(row[`${day}daysAgo`])], childs: [innerDiv] });
liContent.append(outerDiv);
if (index === 0) {
@ -112,11 +112,12 @@ function printTimetable(timetable) {
timetableList.append(table);
}
const ifIsEmpty = (value) => (value?.trim() ? "show" : "hide");
const ifIsEmptyImage = (value) => (value?.trim() ? `img/${value}.svg` : "img/in.svg");
const ifIsEmptyText = (value) => (value?.toString()?.trim() ? value : "00:00");
const isEmpty = (value, type) => {
const val = value?.toString()?.trim();
if (!type) return val ? "show" : "hide";
if (type === "image") return val ? `img/${val}.svg` : "img/in.svg";
if (type === "text") return val ? val : "00:00";
};
function close() {
localStorage.removeItem("userData");