[task-408] [mod] Nutzername im Menü-Knopf anzeigen

This commit is contained in:
fenris 2025-10-17 00:43:10 +02:00
parent 1a36af56ae
commit b1c8bf5806
6 changed files with 55 additions and 11 deletions

View file

@ -3,7 +3,7 @@ namespace _dali
/** /**
*/ */
let _actions_login : Array<(() => Promise<void>)> = []; let _actions_login : Array<((name ?: (null | string)) => Promise<void>)> = [];
/** /**
@ -19,7 +19,7 @@ namespace _dali
/** /**
*/ */
export function listen_login( export function listen_login(
action : (() => Promise<void>) action : ((name ?: (null | string)) => Promise<void>)
) )
: void : void
{ {
@ -41,13 +41,14 @@ namespace _dali
/** /**
*/ */
export async function notify_login( export async function notify_login(
name : (null | string)
) )
: Promise<void> : Promise<void>
{ {
_is_logged_in = true; _is_logged_in = true;
for (const action of _actions_login) for (const action of _actions_login)
{ {
await action(); await action(name);
} }
} }
@ -76,6 +77,20 @@ namespace _dali
} }
/**
*/
export async function oidc_finish(
session_key : string
)
: Promise<void>
{
await _dali.backend.set_session_key(session_key);
const status = await _dali.backend.status();
await _dali.notify_login(status.name);
return Promise.resolve<void>(undefined);
}
/** /**
*/ */
export async function logout( export async function logout(

View file

@ -98,8 +98,9 @@ namespace _dali
_dali.overlay.clear(); _dali.overlay.clear();
_dali.overlay.toggle({"mode": false}); _dali.overlay.toggle({"mode": false});
}, },
"action_success": () => { "action_success": async () => {
_dali.notify_login(); const status = await _dali.backend.status();
_dali.notify_login(status.name);
_dali.overlay.clear(); _dali.overlay.clear();
_dali.overlay.toggle({"mode": false}); _dali.overlay.toggle({"mode": false});
}, },
@ -145,13 +146,15 @@ namespace _dali
); );
await widget_menu.load(document.querySelector("header")); await widget_menu.load(document.querySelector("header"));
_dali.listen_login( _dali.listen_login(
async () => { async (name) => {
widget_menu.set_groups(["logged_in"]); widget_menu.set_groups(["logged_in"]);
widget_menu.set_label(name);
} }
); );
_dali.listen_logout( _dali.listen_logout(
async () => { async () => {
widget_menu.set_groups(["logged_out"]); widget_menu.set_groups(["logged_out"]);
widget_menu.set_label(null);
} }
); );
} }
@ -175,7 +178,7 @@ namespace _dali
); );
if (status.logged_in) if (status.logged_in)
{ {
_dali.notify_login(); _dali.notify_login(status.name);
} }
else else
{ {

View file

@ -7,8 +7,7 @@ namespace _dali.pages
"oidc_finish", "oidc_finish",
async (parameters, target_element) => { async (parameters, target_element) => {
target_element.innerHTML = ""; target_element.innerHTML = "";
await _dali.backend.set_session_key(parameters["session_key"]); await _dali.oidc_finish(parameters["session_key"]);
await _dali.notify_login();
lib_plankton.zoo_page.set( lib_plankton.zoo_page.set(
{ {
"name": "overview", "name": "overview",

View file

@ -334,6 +334,7 @@ namespace _dali.backend
: Promise< : Promise<
{ {
logged_in : boolean; logged_in : boolean;
name : (null | string);
} }
> >
{ {

View file

@ -2,7 +2,7 @@
{ {
margin-left: auto; margin-left: auto;
margin-right: 8px; margin-right: 8px;
max-width: 40px; width: fit-content;
} }
.widget-menu.widget-menu-collapsed > .widget-menu-platform .widget-menu.widget-menu-collapsed > .widget-menu-platform
@ -12,6 +12,7 @@
.widget-menu-button .widget-menu-button
{ {
text-transform: initial;
} }
.widget-menu-entry .widget-menu-entry

View file

@ -30,6 +30,11 @@ namespace _dali.widgets.menu
private initial_groups : Array<string>; private initial_groups : Array<string>;
/**
*/
private label : (null | string);
/** /**
*/ */
private container : (null | HTMLElement); private container : (null | HTMLElement);
@ -41,10 +46,12 @@ namespace _dali.widgets.menu
entry_data_list : Array<type_entry_data>, entry_data_list : Array<type_entry_data>,
{ {
"initial_groups": initial_groups = [], "initial_groups": initial_groups = [],
"initial_label": initial_label = "=",
} }
: :
{ {
initial_groups ?: Array<string>; initial_groups ?: Array<string>;
initial_label ?: string;
} }
= =
{ {
@ -60,6 +67,7 @@ namespace _dali.widgets.menu
) )
); );
this.initial_groups = initial_groups; this.initial_groups = initial_groups;
this.label = initial_label;
this.container = null; this.container = null;
} }
@ -79,6 +87,23 @@ namespace _dali.widgets.menu
); );
} }
/**
*/
public set_label(
label ?: string
)
: void
{
this.label = label;
this.container.querySelector(".widget-menu-button").textContent = (
(this.label === null)
?
"[=]"
:
("[" + this.label + "]")
);
}
/** /**
*/ */
@ -115,7 +140,7 @@ namespace _dali.widgets.menu
// button // button
{ {
const dom_button : HTMLElement = document.createElement("button"); const dom_button : HTMLElement = document.createElement("button");
dom_button.textContent = "[=]"; dom_button.textContent = "[" + this.label + "]";
dom_button.classList.add("widget-menu-button"); dom_button.classList.add("widget-menu-button");
dom_button.addEventListener( dom_button.addEventListener(
"click", "click",