frontend-dali/source/logic/main.ts

137 lines
2.7 KiB
TypeScript
Raw Normal View History

2024-09-19 01:40:27 +02:00
2024-09-12 00:02:12 +02:00
/**
*/
2024-09-19 01:40:27 +02:00
namespace _zeitbild.frontend_web
2024-09-12 00:02:12 +02:00
{
/**
*/
type type_conf = {
view_mode : string;
calendar_ids : Array<int>;
timezone_shift : int;
};
/**
*/
async function render(
) : Promise<void>
{
const target : HTMLElement = (document.querySelector("body") as HTMLBodyElement);
2024-09-19 01:40:27 +02:00
const view_type : string = "table";
switch (view_type) {
2024-09-12 00:02:12 +02:00
default: {
throw (new Error("invalid view mode"));
break;
}
case "table": {
2024-09-19 01:40:27 +02:00
const content : string = await _zeitbild.frontend_web.view.calendar_view_table_html(
2024-09-12 00:02:12 +02:00
{
2024-09-19 01:40:27 +02:00
"calendar_ids": null,
2024-09-12 00:02:12 +02:00
"from": {
"year": 2024,
2024-09-19 01:40:27 +02:00
"week": 37
2024-09-12 00:02:12 +02:00
},
"to": {
"year": 2024,
"week": 43
},
2024-09-19 01:40:27 +02:00
"timezone_shift": /*conf.timezone_shift*/0,
2024-09-12 00:02:12 +02:00
}
);
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": {
2024-09-19 01:40:27 +02:00
const content : string = await _zeitbild.frontend_web.view.calendar_view_list_html(
null,
2024-09-12 00:02:12 +02:00
{
2024-09-19 01:40:27 +02:00
"timezone_shift": /*conf.timezone_shift*/0,
2024-09-12 00:02:12 +02:00
}
);
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
2024-09-19 01:40:27 +02:00
await _zeitbild.frontend_web.conf.init(("conf.json"));
2024-09-12 00:02:12 +02:00
2024-09-19 01:40:27 +02:00
// setup
await _zeitbild.frontend_web.backend.session_begin(
"alice",
"alice"
);
2024-09-12 00:02:12 +02:00
2024-09-19 01:40:27 +02:00
// args
/*
2024-09-12 00:02:12 +02:00
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)),
]
)
:
2024-09-19 01:40:27 +02:00
(await _zeitbild.frontend_web.backend.calendar_list()).map(x => x.key)
2024-09-12 00:02:12 +02:00
);
2024-09-19 01:40:27 +02:00
*/
2024-09-12 00:02:12 +02:00
// exec
2024-09-19 01:40:27 +02:00
await render();
2024-09-12 00:02:12 +02:00
return Promise.resolve<void>(undefined);
}
}