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(
|
2024-09-30 12:06:41 +02:00
|
|
|
"conf.json"
|
|
|
|
|
);
|
2024-09-26 13:38:25 +02:00
|
|
|
|
2025-10-28 11:38:58 +01:00
|
|
|
// init:logger
|
2025-09-25 17:08:18 +02:00
|
|
|
lib_plankton.log.set_main_logger(
|
2024-09-30 12:06:41 +02:00
|
|
|
[
|
2025-10-23 21:58:51 +02:00
|
|
|
{
|
|
|
|
|
"kind": "minlevel",
|
|
|
|
|
"data": {
|
|
|
|
|
"core": {
|
|
|
|
|
"kind": "console",
|
|
|
|
|
"data": {
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"threshold": "info"
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-09-30 12:06:41 +02:00
|
|
|
]
|
|
|
|
|
);
|
2025-10-28 11:38:58 +01:00
|
|
|
// 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(
|
2025-10-28 11:38:58 +01:00
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-10-28 11:38:58 +01:00
|
|
|
// init:backend
|
2025-10-17 00:10:28 +02:00
|
|
|
await _dali.backend.initialize(
|
|
|
|
|
_dali.conf.get()["backend"]
|
|
|
|
|
);
|
2025-10-28 11:38:58 +01:00
|
|
|
// init:model
|
2025-10-17 00:10:28 +02:00
|
|
|
await _dali.model.initialize(
|
|
|
|
|
);
|
2025-10-28 11:38:58 +01:00
|
|
|
// init:page
|
2024-09-19 10:17:43 +02:00
|
|
|
lib_plankton.zoo_page.init(
|
|
|
|
|
document.querySelector("main"),
|
|
|
|
|
{
|
|
|
|
|
"fallback": {
|
2024-10-10 23:00:51 +02:00
|
|
|
"name": "overview",
|
2024-09-19 10:17:43 +02:00
|
|
|
"parameters": {}
|
2025-10-02 17:00:17 +02:00
|
|
|
},
|
2025-10-17 00:10:28 +02:00
|
|
|
}
|
|
|
|
|
);
|
2025-10-28 11:38:58 +01:00
|
|
|
// init:menu
|
2025-10-17 00:10:28 +02:00
|
|
|
{
|
2025-10-28 11:38:58 +01: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-02 17:00:17 +02:00
|
|
|
{
|
2025-10-17 00:10:28 +02:00
|
|
|
"label": lib_plankton.translate.get("common.login"),
|
2025-10-02 17:00:17 +02:00
|
|
|
"groups": ["logged_out"],
|
2025-10-28 11:38:58 +01:00
|
|
|
"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});
|
|
|
|
|
},
|
2025-10-17 00:43:10 +02:00
|
|
|
"action_success": async () => {
|
2025-10-28 11:38:58 +01:00
|
|
|
_dali.helpers.loading(true);
|
2025-10-17 00:43:10 +02:00
|
|
|
const status = await _dali.backend.status();
|
|
|
|
|
_dali.notify_login(status.name);
|
2025-10-28 11:38:58 +01:00
|
|
|
// _dali.overlay.clear();
|
|
|
|
|
_dali.helpers.loading(false);
|
2025-10-17 00:10:28 +02:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
);
|
2025-10-28 11:38:58 +01: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});
|
|
|
|
|
},
|
2025-10-02 17:00:17 +02:00
|
|
|
},
|
|
|
|
|
{
|
2025-10-28 11:38:58 +01:00
|
|
|
"label": lib_plankton.translate.get("widget.caldav.title"),
|
2025-10-02 17:00:17 +02:00
|
|
|
"groups": ["logged_in"],
|
2025-10-28 11:38:58 +01:00
|
|
|
"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-02 17:00:17 +02:00
|
|
|
},
|
|
|
|
|
{
|
2025-10-17 00:10:28 +02:00
|
|
|
"label": lib_plankton.translate.get("common.logout"),
|
2025-10-02 17:00:17 +02:00
|
|
|
"groups": ["logged_in"],
|
2025-10-28 11:38:58 +01:00
|
|
|
"action": async () => {
|
|
|
|
|
_dali.helpers.loading(true);
|
|
|
|
|
await _dali.logout();
|
|
|
|
|
_dali.helpers.loading(false);
|
2025-10-17 00:10:28 +02:00
|
|
|
},
|
2025-10-02 17:00:17 +02:00
|
|
|
},
|
2025-10-17 00:10:28 +02:00
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
await widget_menu.load(document.querySelector("header"));
|
|
|
|
|
_dali.listen_login(
|
2025-10-17 00:43:10 +02:00
|
|
|
async (name) => {
|
2025-10-17 00:10:28 +02:00
|
|
|
widget_menu.set_groups(["logged_in"]);
|
2025-10-17 00:43:10 +02:00
|
|
|
widget_menu.set_label(name);
|
2025-10-17 00:10:28 +02:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
_dali.listen_logout(
|
|
|
|
|
async () => {
|
|
|
|
|
widget_menu.set_groups(["logged_out"]);
|
2025-10-17 00:43:10 +02:00
|
|
|
widget_menu.set_label(null);
|
2025-10-17 00:10:28 +02:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-28 11:38:58 +01: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)
|
|
|
|
|
{
|
2025-10-17 00:43:10 +02:00
|
|
|
_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
|
|
|
|
2025-10-28 11:38:58 +01: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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|