/* This file is part of »dali«. Copyright 2025 'kcf' »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 . */ /** */ namespace _dali { /** */ function nav_groups( logged_in : boolean ) : Array { return ( logged_in ? ["logged_in"] : ["logged_out"] ); } /** */ export async function main( ) : Promise { // conf await _dali.conf.init( "conf.json" ); // init lib_plankton.log.set_main_logger( [ { "kind": "minlevel", "data": { "core": { "kind": "console", "data": { } }, "threshold": "info" } }, ] ); // init:localization { const order : Array = ["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, } ); } await _dali.backend.initialize( _dali.conf.get()["backend"] ); await _dali.model.initialize( ); lib_plankton.zoo_page.init( document.querySelector("main"), { "fallback": { "name": "overview", "parameters": {} }, /* "nav_entries": [ ], */ "nav_initial_groups": [], } ); // menu widget { const widget_menu : _dali.widgets.menu.class_widget_menu = new _dali.widgets.menu.class_widget_menu( [ { "label": lib_plankton.translate.get("common.login"), "groups": ["logged_out"], "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); _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"], "action": () => { lib_plankton.zoo_page.set( { "name": "overview", "parameters": {} } ); }, }, { "label": lib_plankton.translate.get("page.caldav.title"), "groups": ["logged_in"], "action": () => { lib_plankton.zoo_page.set( { "name": "caldav", "parameters": {} } ); }, }, { "label": lib_plankton.translate.get("common.logout"), "groups": ["logged_in"], "action": () => { _dali.logout(); }, }, ] ); await widget_menu.load(document.querySelector("header")); _dali.listen_login( async (name) => { widget_menu.set_groups(["logged_in"]); widget_menu.set_label(name); } ); _dali.listen_logout( async () => { widget_menu.set_groups(["logged_out"]); widget_menu.set_label(null); } ); } await _dali.overlay.initialize(); // 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); } else { _dali.notify_logout(); } } lib_plankton.zoo_page.start(); return Promise.resolve(undefined); } }