133 lines
2.7 KiB
TypeScript
133 lines
2.7 KiB
TypeScript
/**
|
|
*/
|
|
namespace _zeitbild.frontend
|
|
{
|
|
|
|
/**
|
|
*/
|
|
type type_conf = {
|
|
view_mode : string;
|
|
calendar_ids : Array<int>;
|
|
timezone_shift : int;
|
|
};
|
|
|
|
|
|
/**
|
|
*/
|
|
async function render(
|
|
conf : type_conf,
|
|
calendar_ids : Array<type_calendar_id>
|
|
) : Promise<void>
|
|
{
|
|
calendar_ids.sort();
|
|
const target : HTMLElement = (document.querySelector("body") as HTMLBodyElement);
|
|
switch (conf.view_mode) {
|
|
default: {
|
|
throw (new Error("invalid view mode"));
|
|
break;
|
|
}
|
|
case "table": {
|
|
const content : string = await _zeitbild.frontend.view.calendar_view_table_html(
|
|
calendar_ids,
|
|
{
|
|
"from": {
|
|
"year": 2024,
|
|
"week": 35
|
|
},
|
|
"to": {
|
|
"year": 2024,
|
|
"week": 43
|
|
},
|
|
"timezone_shift": conf.timezone_shift,
|
|
}
|
|
);
|
|
target.innerHTML = content;
|
|
/*
|
|
document.querySelectorAll(".tableview-sources-entry").forEach(
|
|
(element) => {
|
|
element.addEventListener(
|
|
"click",
|
|
(event) => {
|
|
const element_ : HTMLElement = (event.target as HTMLElement);
|
|
const calendar_id : type_calendar_id = parseInt(element_.getAttribute("rel") as string);
|
|
const active : boolean = element_.classList.toggle("tableview-sources-entry-active");
|
|
render(
|
|
conf,
|
|
lib_plankton.call.convey(
|
|
calendar_ids,
|
|
[
|
|
(x : Array<int>) => (
|
|
active
|
|
?
|
|
calendar_ids.concat([calendar_id])
|
|
:
|
|
calendar_ids.filter(y => (y !== calendar_id))
|
|
),
|
|
]
|
|
)
|
|
);
|
|
}
|
|
);
|
|
}
|
|
);
|
|
*/
|
|
break;
|
|
}
|
|
case "list": {
|
|
const content : string = await _zeitbild.frontend.view.calendar_view_list_html(
|
|
calendar_ids,
|
|
{
|
|
"timezone_shift": conf.timezone_shift,
|
|
}
|
|
);
|
|
target.innerHTML = content;
|
|
break;
|
|
}
|
|
}
|
|
return Promise.resolve<void>(undefined);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function main(
|
|
) : Promise<void>
|
|
{
|
|
// init
|
|
lib_plankton.log.conf_push(
|
|
[
|
|
lib_plankton.log.channel_make({"kind": "console", "data": {"threshold": "info"}}),
|
|
]
|
|
);
|
|
|
|
// conf
|
|
const conf : type_conf = lib_plankton.json.decode(await lib_plankton.file.read("conf.json"));
|
|
|
|
// args
|
|
|
|
const url : URL = new URL(window.location.toString());
|
|
const calendar_ids : Array<type_calendar_id> = (
|
|
(url.searchParams.get("ids") !== null)
|
|
?
|
|
lib_plankton.call.convey(
|
|
url.searchParams.get("ids"),
|
|
[
|
|
(x : string) => lib_plankton.string.split(x, ","),
|
|
(x : Array<string>) => x.map(y => parseInt(y)),
|
|
]
|
|
)
|
|
:
|
|
(await _zeitbild.frontend.resources.backend.calendar_list()).map(x => x.key)
|
|
);
|
|
|
|
// exec
|
|
await render(
|
|
conf,
|
|
calendar_ids
|
|
);
|
|
|
|
return Promise.resolve<void>(undefined);
|
|
}
|
|
|
|
}
|
|
|