[task-408] [mod] Nutzername im Menü-Knopf anzeigen
This commit is contained in:
parent
1a36af56ae
commit
b1c8bf5806
|
|
@ -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(
|
||||
action : (() => Promise<void>)
|
||||
action : ((name ?: (null | string)) => Promise<void>)
|
||||
)
|
||||
: void
|
||||
{
|
||||
|
|
@ -41,13 +41,14 @@ namespace _dali
|
|||
/**
|
||||
*/
|
||||
export async function notify_login(
|
||||
name : (null | string)
|
||||
)
|
||||
: Promise<void>
|
||||
{
|
||||
_is_logged_in = true;
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -98,8 +98,9 @@ namespace _dali
|
|||
_dali.overlay.clear();
|
||||
_dali.overlay.toggle({"mode": false});
|
||||
},
|
||||
"action_success": () => {
|
||||
_dali.notify_login();
|
||||
"action_success": async () => {
|
||||
const status = await _dali.backend.status();
|
||||
_dali.notify_login(status.name);
|
||||
_dali.overlay.clear();
|
||||
_dali.overlay.toggle({"mode": false});
|
||||
},
|
||||
|
|
@ -145,13 +146,15 @@ namespace _dali
|
|||
);
|
||||
await widget_menu.load(document.querySelector("header"));
|
||||
_dali.listen_login(
|
||||
async () => {
|
||||
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);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -175,7 +178,7 @@ namespace _dali
|
|||
);
|
||||
if (status.logged_in)
|
||||
{
|
||||
_dali.notify_login();
|
||||
_dali.notify_login(status.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ namespace _dali.pages
|
|||
"oidc_finish",
|
||||
async (parameters, target_element) => {
|
||||
target_element.innerHTML = "";
|
||||
await _dali.backend.set_session_key(parameters["session_key"]);
|
||||
await _dali.notify_login();
|
||||
await _dali.oidc_finish(parameters["session_key"]);
|
||||
lib_plankton.zoo_page.set(
|
||||
{
|
||||
"name": "overview",
|
||||
|
|
|
|||
|
|
@ -334,6 +334,7 @@ namespace _dali.backend
|
|||
: Promise<
|
||||
{
|
||||
logged_in : boolean;
|
||||
name : (null | string);
|
||||
}
|
||||
>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
{
|
||||
margin-left: auto;
|
||||
margin-right: 8px;
|
||||
max-width: 40px;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
.widget-menu.widget-menu-collapsed > .widget-menu-platform
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
.widget-menu-button
|
||||
{
|
||||
text-transform: initial;
|
||||
}
|
||||
|
||||
.widget-menu-entry
|
||||
|
|
|
|||
|
|
@ -30,6 +30,11 @@ namespace _dali.widgets.menu
|
|||
private initial_groups : Array<string>;
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
private label : (null | string);
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
private container : (null | HTMLElement);
|
||||
|
|
@ -41,10 +46,12 @@ namespace _dali.widgets.menu
|
|||
entry_data_list : Array<type_entry_data>,
|
||||
{
|
||||
"initial_groups": initial_groups = [],
|
||||
"initial_label": initial_label = "=",
|
||||
}
|
||||
:
|
||||
{
|
||||
initial_groups ?: Array<string>;
|
||||
initial_label ?: string;
|
||||
}
|
||||
=
|
||||
{
|
||||
|
|
@ -60,6 +67,7 @@ namespace _dali.widgets.menu
|
|||
)
|
||||
);
|
||||
this.initial_groups = initial_groups;
|
||||
this.label = initial_label;
|
||||
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
|
||||
{
|
||||
const dom_button : HTMLElement = document.createElement("button");
|
||||
dom_button.textContent = "[=]";
|
||||
dom_button.textContent = "[" + this.label + "]";
|
||||
dom_button.classList.add("widget-menu-button");
|
||||
dom_button.addEventListener(
|
||||
"click",
|
||||
|
|
|
|||
Loading…
Reference in a new issue