frontend-dali/source/main.ts

222 lines
5 KiB
TypeScript
Raw Normal View History

2025-10-23 23:16:11 +02:00
/*
This file is part of »dali«.
Copyright 2025 'kcf' <fenris@folksprak.org>
»dali« is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
»dali« is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with »dali«. If not, see <http://www.gnu.org/licenses/>.
*/
2024-09-19 01:40:27 +02:00
2024-09-12 00:02:12 +02:00
/**
*/
2025-09-25 17:54:20 +02:00
namespace _dali
2024-09-12 00:02:12 +02:00
{
/**
*/
export async function main(
2025-10-17 00:10:28 +02:00
)
: Promise<void>
2024-09-12 00:02:12 +02:00
{
// conf
2025-09-25 17:54:20 +02:00
await _dali.conf.init(
"conf.json"
);
// init:logger
lib_plankton.log.set_main_logger(
[
2025-10-23 21:58:51 +02:00
{
"kind": "minlevel",
"data": {
"core": {
"kind": "console",
"data": {
}
},
"threshold": "info"
}
},
]
);
// init:overlay
{
await _dali.overlay.initialize();
_dali.helpers.loading(true);
}
2025-10-20 13:13:12 +02:00
// init:localization
{
const order : Array<string> = ["deu", "eng"];
await lib_plankton.translate.initialize(
{
"verbosity": 1,
"packages": await Promise.all(
order.map(
code => (
Promise.resolve(code)
.then<string>(code => Promise.resolve(lib_plankton.string.coin("data/localization/{{code}}.loc.json", {"code": code})))
.then<string>(lib_plankton.file.read)
.then<any>(content => Promise.resolve(JSON.parse(content)))
2025-10-20 13:13:12 +02:00
)
)
),
"order": order,
"autopromote": false,
}
);
}
// init:backend
2025-10-17 00:10:28 +02:00
await _dali.backend.initialize(
_dali.conf.get()["backend"]
);
// init:model
2025-10-17 00:10:28 +02:00
await _dali.model.initialize(
);
// init:page
lib_plankton.zoo_page.init(
document.querySelector("main"),
{
"fallback": {
2024-10-10 23:00:51 +02:00
"name": "overview",
"parameters": {}
},
2025-10-17 00:10:28 +02:00
}
);
// init:menu
2025-10-17 00:10:28 +02:00
{
const widget_menu : _dali.widgets.class_widget_menu = new _dali.widgets.class_widget_menu(
2025-10-17 00:10:28 +02:00
[
{
2025-10-17 00:10:28 +02:00
"label": lib_plankton.translate.get("common.login"),
"groups": ["logged_out"],
"action": async () => {
_dali.helpers.loading(true);
const widget : lib_plankton.zoo_widget.interface_widget = new _dali.widgets.class_widget_login(
2025-10-17 00:10:28 +02:00
{
"action_cancel": () => {
_dali.overlay.clear();
_dali.overlay.toggle({"mode": false});
},
"action_success": async () => {
_dali.helpers.loading(true);
const status = await _dali.backend.status();
_dali.notify_login(status.name);
// _dali.overlay.clear();
_dali.helpers.loading(false);
2025-10-17 00:10:28 +02:00
},
}
);
await widget.load(_dali.overlay.get_content_element());
// _dali.helpers.loading(false);
2025-10-17 00:10:28 +02:00
_dali.overlay.toggle({"mode": true});
},
},
{
"label": lib_plankton.translate.get("widget.caldav.title"),
"groups": ["logged_in"],
"action": async () => {
_dali.helpers.loading(true);
const widget : lib_plankton.zoo_widget.interface_widget = new _dali.widgets.class_widget_caldav();
await widget.load(_dali.overlay.get_content_element());
// _dali.helpers.loading(false);
_dali.overlay.toggle({"mode": true});
2025-10-17 00:10:28 +02:00
},
},
{
2025-10-17 00:10:28 +02:00
"label": lib_plankton.translate.get("common.logout"),
"groups": ["logged_in"],
"action": async () => {
_dali.helpers.loading(true);
await _dali.logout();
_dali.helpers.loading(false);
2025-10-17 00:10:28 +02:00
},
},
2025-10-17 00:10:28 +02:00
]
);
await widget_menu.load(document.querySelector("header"));
_dali.listen_login(
async (name) => {
2025-10-17 00:10:28 +02:00
widget_menu.set_groups(["logged_in"]);
widget_menu.set_label(name);
2025-10-17 00:10:28 +02:00
}
);
_dali.listen_logout(
async () => {
widget_menu.set_groups(["logged_out"]);
widget_menu.set_label(null);
2025-10-17 00:10:28 +02:00
}
);
}
// process actions
{
let url_search_params : URLSearchParams = new URLSearchParams(window.location.search);
const action : (null | string) = url_search_params.get("action");
switch (action)
{
case "oidc_finish":
{
try
{
await _dali.oidc_finish(url_search_params.get("session_key"));
}
catch (error_)
{
// do nothing
}
document.location = "/";
break;
}
default:
case null:
{
// do nothing
break;
}
}
}
// process status
2025-10-17 00:10:28 +02:00
{
const status = await _dali.backend.status();
lib_plankton.log.info(
"dali.status",
status
);
if (status.logged_in)
{
_dali.notify_login(status.name);
2025-10-17 00:10:28 +02:00
}
else
{
_dali.notify_logout();
}
}
2024-09-12 00:02:12 +02:00
// load overview
{
const widget : lib_plankton.zoo_widget.interface_widget = (
new _dali.widgets.class_widget_overview(
)
);
await widget.load(document.querySelector("main"));
}
_dali.helpers.loading(false);
2024-09-12 00:02:12 +02:00
return Promise.resolve<void>(undefined);
}
}