This commit is contained in:
Fenris Wolf 2024-09-09 21:01:02 +02:00
parent ffb4304b0f
commit 0461344aad
3 changed files with 252 additions and 92 deletions

View file

@ -79,18 +79,18 @@
],
"events": [
{
"name": "38.KW",
"name": "Krautnudeln",
"begin": {
"timezone_shift": 2,
"date": {"year": 2024, "month": 9, "day": 20},
"date": {"year": 2024, "month": 9, "day": 21},
"time": {"hour": 17, "minute": 0, "second": 0}
},
"end": {
"timezone_shift": 2,
"date": {"year": 2024, "month": 9, "day": 20},
"date": {"year": 2024, "month": 9, "day": 21},
"time": {"hour": 19, "minute": 0, "second": 0}
},
"description": "Krautnudeln"
"description": null
}
]
}

View file

@ -213,17 +213,21 @@ function calendar_view_table(
timezone_shift ?: int;
} = {}
) : Array<
Array<
{
pit : type_pit;
entries : Array<
{
calendar_id : type_calendar_id;
event : type_event;
}
>;
}
>
{
week : int;
data : Array<
{
pit : type_pit;
entries : Array<
{
calendar_id : type_calendar_id;
event : type_event;
}
>;
today : boolean;
}
>;
}
>
{
options = Object.assign(
@ -266,17 +270,21 @@ function calendar_view_table(
to_pit
);
let result : Array<
Array<
{
pit : type_pit;
entries : Array<
{
calendar_id : type_calendar_id;
event : type_event;
}
>;
}
>
{
week : int;
data : Array<
{
pit : type_pit;
entries : Array<
{
calendar_id : type_calendar_id;
event : type_event;
}
>;
today : boolean;
}
>;
}
> = [];
let row : Array<
{
@ -287,6 +295,7 @@ function calendar_view_table(
event : type_event;
}
>;
today : boolean;
}
> = [];
let day : int = 0;
@ -298,10 +307,11 @@ function calendar_view_table(
{
"pit": pit_current,
"entries": [],
"today": false, // TODO
}
);
if (day % 7 === 0) {
result.push(row);
result.push({"week": (from.week + Math.floor(day / 7)), "data": row});
row = [];
}
else {
@ -325,9 +335,9 @@ function calendar_view_table(
const week : int = Math.floor(Math.floor(distance_days) / 7);
const day : int = (Math.floor(distance_days) % 7);
process.stderr.write(JSON.stringify({entry, distance_days, week, day}, undefined, "\t") + "\n");
// process.stderr.write(JSON.stringify({entry, distance_days, week, day}, undefined, "\t") + "\n");
result[week][day].entries.push(entry);
result[week].data[day].entries.push(entry);
}
)
);
@ -360,7 +370,23 @@ function calendar_view_table_html(
},
options
);
const rows = calendar_view_table(
const rows : Array<
{
week : int;
data : Array<
{
pit : type_pit;
entries : Array<
{
calendar_id : type_calendar_id;
event : type_event;
}
>;
today : boolean;
}
>;
}
> = calendar_view_table(
data,
calendar_id,
from,
@ -370,75 +396,209 @@ function calendar_view_table_html(
}
);
return (
(
"<style>\n"
+
"table {border-collapse: collapse;}\n"
+
"td {border: 1px solid black; padding: 8px; margin: 8px; width: 14%;}\n"
+
"</style>\n"
)
+
"<table>\n"
+
(
"\t<thead>\n"
+
"\t</thead>\n"
)
+
(
"\t<tbody>\n"
+
(
rows
.map(
(row) => (
"\t\t<tr>\n"
+
(
row
.map(
(cell) => (
"\t\t\t<td>\n"
+
new lib_plankton.xml.class_node_complex(
"div",
{
"class": "calendar",
},
[
new lib_plankton.xml.class_node_complex(
"style",
{},
[
new lib_plankton.xml.class_node_text(
"html {background-color: #111; color: #FFF; font-family: sans-serif;}\n"
+
"table {width: 100%; border-collapse: collapse;}\n"
+
".calendar-cell {border: 1px solid #444; padding: 8px; vertical-align: top;}\n"
+
".calendar-cell-day {width: 13.5%;}\n"
+
".calendar-cell-week {width: 5.5%;}\n"
+
".calendar-cell-regular {width: 13.5%;}\n"
+
".calendar-day {font-size: 0.75em;}\n"
+
".calendar-events {margin: 0; padding: 0; list-style-type: none;}\n"
+
".calendar-event_entry {margin: 4px; padding: 4px; border-radius: 2px; font-size: 0.75em;}\n"
)
]
),
new lib_plankton.xml.class_node_complex(
"table",
{
},
[
new lib_plankton.xml.class_node_complex(
"thead",
{
},
[
new lib_plankton.xml.class_node_complex(
"tr",
{
},
(
"\t\t\t\t<ul>\n"
+
(
cell.entries
[
new lib_plankton.xml.class_node_complex(
"th",
{
"class": "calendar-cell",
},
[
]
),
]
.concat(
["Mo","Di","Mi","Do","Fr","Sa","So"]
.map(
entry => (
"\t\t\t\t\t<li>\n"
+
entry.event.name
+
"\t\t\t\t\t</li>\n"
(day) => new lib_plankton.xml.class_node_complex(
"th",
{
"class": "calendar-cell calendar-cell-day",
},
[
new lib_plankton.xml.class_node_text(day)
]
)
)
)
)
)
]
),
new lib_plankton.xml.class_node_complex(
"tbody",
{
},
(
rows
.map(
(row) => (
new lib_plankton.xml.class_node_complex(
"tr",
{
},
(
[
new lib_plankton.xml.class_node_complex(
"th",
{
"class": "calendar-cell calendar-cell-week",
},
[
new lib_plankton.xml.class_node_text(
row.week.toFixed(0).padStart(2, "0")
)
]
),
]
.concat(
row.data
.map(
(cell) => (
new lib_plankton.xml.class_node_complex(
"td",
{
"class": (
(
["calendar-cell", "calendar-cell-regular"]
.concat(cell.today ? ["today"] : [])
)
.join(" ")
),
"title": lib_plankton.call.convey(
cell.pit,
[
pit_to_datetime,
(x : type_datetime) => lib_plankton.string.coin(
"{{year}}-{{month}}-{{day}}",
{
"year": x.date.year.toFixed(0).padStart(4, "0"),
"month": x.date.month.toFixed(0).padStart(2, "0"),
"day": x.date.day.toFixed(0).padStart(2, "0"),
}
),
]
)
},
[
new lib_plankton.xml.class_node_complex(
"span",
{
"class": "calendar-day",
},
[
new lib_plankton.xml.class_node_text(
lib_plankton.call.convey(
cell.pit,
[
pit_to_datetime,
(x : type_datetime) => lib_plankton.string.coin(
"{{day}}",
{
"year": x.date.year.toFixed(0).padStart(4, "0"),
"month": x.date.month.toFixed(0).padStart(2, "0"),
"day": x.date.day.toFixed(0).padStart(2, "0"),
}
),
]
)
)
]
),
new lib_plankton.xml.class_node_complex(
"ul",
{
"class": "calendar-events",
},
(
cell.entries
.map(
entry => (
new lib_plankton.xml.class_node_complex(
"li",
{
"class": "calendar-event_entry",
"style": lib_plankton.string.coin(
"background-color: {{color}}",
{
"color": lib_plankton.call.convey(
entry.calendar_id,
[
(n : int) => ({"n": n, "saturation": 0.25, "value": 0.5}),
lib_plankton.color.give_generic,
lib_plankton.color.output_hex,
]
),
}
),
},
[
new lib_plankton.xml.class_node_text(entry.event.name),
]
)
)
)
)
),
]
)
)
)
)
)
.join("")
)
+
"\t\t\t\t</ul>\n"
)
// JSON.stringify(cell) + "\n"
+
"\t\t\t</td>\n"
)
)
.join("")
)
+
"\t\t</tr>\n"
)
]
)
.join("")
)
+
"\t</tbody>\n"
)
+
"</table>\n"
]
).compile()
);
}

View file

@ -113,11 +113,11 @@ async function main(
4,
{
"year": 2024,
"week": 37
"week": 35
},
{
"year": 2024,
"week": 40
"week": 41
},
{
"timezone_shift": parseInt(args["timezone_shift"]),