frontend-dali/source/main.ts

234 lines
4.6 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
{
/**
*/
function nav_groups(
logged_in : boolean
2025-10-17 00:10:28 +02:00
)
: Array<string>
{
return (
logged_in
?
["logged_in"]
:
["logged_out"]
);
}
/**
* @todo reload page when switching to "logged_out"
*/
async function update(
2025-10-17 00:10:28 +02:00
)
: Promise<void>
{
lib_plankton.log.debug(
"dali.update"
);
2025-10-17 00:10:28 +02:00
const logged_in : boolean = _dali.is_logged_in();
lib_plankton.zoo_page.nav_set_groups(nav_groups(logged_in));
// lib_plankton.zoo_page.reload();
}
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
lib_plankton.log.set_main_logger(
[
2025-10-23 21:58:51 +02:00
{
"kind": "minlevel",
"data": {
"core": {
"kind": "console",
"data": {
}
},
"threshold": "info"
}
},
]
);
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(
async (code) => JSON.parse(
await lib_plankton.file.read(
"data/localization/" + code + ".loc.json"
)
)
)
),
"order": order,
"autopromote": false,
}
);
}
2025-10-17 00:10:28 +02:00
await _dali.backend.initialize(
_dali.conf.get()["backend"]
);
await _dali.model.initialize(
);
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
/*
"nav_entries": [
2025-10-17 00:10:28 +02:00
],
*/
"nav_initial_groups": [],
}
);
// menu widget
{
const widget_menu : _dali.widgets.menu.class_widget_menu = new _dali.widgets.menu.class_widget_menu(
[
{
2025-10-17 00:10:28 +02:00
"label": lib_plankton.translate.get("common.login"),
"groups": ["logged_out"],
2025-10-17 00:10:28 +02:00
"action": () => {
const widget_login = new _dali.widgets.login.class_widget_login(
{
"action_cancel": () => {
_dali.overlay.clear();
_dali.overlay.toggle({"mode": false});
},
"action_success": async () => {
const status = await _dali.backend.status();
_dali.notify_login(status.name);
2025-10-17 00:10:28 +02:00
_dali.overlay.clear();
_dali.overlay.toggle({"mode": false});
},
}
);
_dali.overlay.clear();
_dali.overlay.toggle({"mode": true});
widget_login.load(_dali.overlay.get_content_element());
},
},
{
"label": lib_plankton.translate.get("page.overview.title"),
"groups": ["logged_out", "logged_in"],
2025-10-17 00:10:28 +02:00
"action": () => {
lib_plankton.zoo_page.set(
{
"name": "overview",
"parameters": {}
}
);
},
},
{
"label": lib_plankton.translate.get("page.caldav.title"),
"groups": ["logged_in"],
2025-10-17 00:10:28 +02:00
"action": () => {
lib_plankton.zoo_page.set(
{
"name": "caldav",
"parameters": {}
}
);
},
},
{
2025-10-17 00:10:28 +02:00
"label": lib_plankton.translate.get("common.logout"),
"groups": ["logged_in"],
2025-10-17 00:10:28 +02:00
"action": () => {
_dali.logout();
},
},
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
}
);
}
await update();
2025-10-14 00:16:22 +02:00
await _dali.overlay.initialize();
2025-10-17 00:10:28 +02:00
/*
lib_plankton.call.loop(
() => {
update();
},
_dali.conf.get().misc.update_interval
);
2025-10-17 00:10:28 +02:00
*/
// check if logged_in
{
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
lib_plankton.zoo_page.start();
2024-09-12 00:02:12 +02:00
return Promise.resolve<void>(undefined);
}
}