more subtle user bar on top

This commit is contained in:
Mateo Körber Belmonte
2025-03-03 20:36:26 +01:00
parent 4fd34b703a
commit 8e230c4e07
2 changed files with 70 additions and 69 deletions
+70 -16
View File
@@ -3,25 +3,79 @@ document.addEventListener('DOMContentLoaded', function() {
const isAdmin = localStorage.getItem('userRole') === 'admin'; const isAdmin = localStorage.getItem('userRole') === 'admin';
const userName = localStorage.getItem('userName') || 'Benutzer'; const userName = localStorage.getItem('userName') || 'Benutzer';
// Header-Bereich mit Benutzerinfos und Logout-Button hinzufügen // Erstelle einen minimalistischen Header mit Dropdown
const header = document.createElement('div'); const userMenu = document.createElement('div');
header.className = 'user-header'; userMenu.className = 'user-menu';
header.innerHTML = ` userMenu.innerHTML = `
<div class="user-info"> <div class="user-dropdown">
Angemeldet als: <span class="user-name">${userName}</span> <span class="user-name-display">${userName} ▼</span>
${isAdmin ? '<span class="admin-badge">Administrator</span>' : ''} <div class="dropdown-content">
</div> ${isAdmin ? '<a href="/admin/settings">Admin-Bereich</a>' : ''}
<div class="header-buttons"> <a href="/logout">Abmelden</a>
${isAdmin ? '<button onclick="window.location.href=\'/admin/settings\'" class="admin-button">Admin-Bereich</button>' : ''} </div>
<button onclick="window.location.href=\'/logout\'" class="logout-button">Abmelden</button>
</div> </div>
`; `;
// Header vor dem Container einfügen // Füge CSS für das Dropdown-Menü hinzu
const container = document.querySelector('.container'); const style = document.createElement('style');
if (container) { style.textContent = `
container.parentNode.insertBefore(header, container); .user-menu {
} position: fixed;
top: 10px;
right: 20px;
z-index: 1000;
}
.user-dropdown {
position: relative;
display: inline-block;
}
.user-name-display {
color: white;
font-weight: bold;
cursor: pointer;
padding: 5px 10px;
border-radius: 4px;
background-color: rgba(168, 20, 17, 0.8);
}
.dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: white;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
margin-top: 5px;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
border-bottom: 1px solid #f1f1f1;
}
.dropdown-content a:last-child {
border-bottom: none;
}
.dropdown-content a:hover {
background-color: #f1f1f1;
}
.user-dropdown:hover .dropdown-content {
display: block;
}
`;
document.head.appendChild(style);
// Füge das Menü zum Body hinzu
document.body.appendChild(userMenu);
// Admin-spezifische Elemente anzeigen/verbergen // Admin-spezifische Elemente anzeigen/verbergen
const adminElements = document.querySelectorAll('.admin-only'); const adminElements = document.querySelectorAll('.admin-only');
-53
View File
@@ -207,59 +207,6 @@ button {
display: block; display: block;
} }
.user-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 20px;
background-color: white;
margin-bottom: 15px;
border-radius: 8px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
.user-name {
font-weight: bold;
margin-right: 10px;
color: black;
}
.user-info {
color: black
}
.admin-badge {
background-color: #a81411;
color: white;
padding: 3px 8px;
border-radius: 4px;
font-size: 12px;
margin-left: 8px;
}
.header-buttons {
display: flex;
gap: 10px;
}
.logout-button {
padding: 6px 12px;
background-color: #6c757d;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.admin-button {
padding: 6px 12px;
background-color: #a81411;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
/* Für Admin-Only Elemente */ /* Für Admin-Only Elemente */
.admin-only { .admin-only {
display: none; /* Standardmäßig versteckt, wird via JS eingeblendet */ display: none; /* Standardmäßig versteckt, wird via JS eingeblendet */