112 lines
3.7 KiB
JavaScript
112 lines
3.7 KiB
JavaScript
// Функция для создания навигационной панели
|
||
function createNavigation() {
|
||
const navbar = document.getElementById('navbar-container');
|
||
if (!navbar) return;
|
||
// 👇 ДОБАВЛЯЕМ ПОДРОБНЫЕ ЛОГИ 👇
|
||
if (currentUser) {
|
||
console.log('ID:', currentUser.id);
|
||
console.log('ФИО:', currentUser.name);
|
||
console.log('Логин:', currentUser.login);
|
||
console.log('Роль:', currentUser.role);
|
||
} else {
|
||
console.log('currentUser отсутствует (не авторизован)');
|
||
}
|
||
// Базовые кнопки для всех авторизованных пользователей
|
||
const navButtons = [
|
||
{
|
||
onclick: "window.location.href = '/'",
|
||
className: "nav-btn tasks",
|
||
icon: "fas fa-cog",
|
||
text: "Главная",
|
||
id: "home-btn"
|
||
},
|
||
|
||
];
|
||
navButtons.push(
|
||
{
|
||
onclick: "showSection('tasks')",
|
||
className: "nav-btn tasks",
|
||
icon: "fas fa-list",
|
||
text: "Все задачи",
|
||
id: "tasks-btn"
|
||
},
|
||
{
|
||
onclick: "showSection('mytasks')",
|
||
className: "nav-btn my-tasks",
|
||
icon: "fas fa-user-edit",
|
||
text: "Мои задачи",
|
||
id: "my-tasks-btn"
|
||
},
|
||
{
|
||
onclick: "showSection('create-task')",
|
||
className: "nav-btn create",
|
||
icon: "fas fa-plus-circle",
|
||
text: "Создать задачу",
|
||
id: "create-task-btn"
|
||
}
|
||
);
|
||
navButtons.push(
|
||
{
|
||
onclick: "showKanbanSection()",
|
||
className: "nav-btn kanban",
|
||
icon: "fas fa-columns",
|
||
text: "Канбан",
|
||
id: "kanban-btn"
|
||
},
|
||
{
|
||
onclick: "showSection('profile')",
|
||
className: "nav-btn profile",
|
||
icon: "fas fa-user-circle",
|
||
text: "Личный кабинет",
|
||
id: "profile-btn"
|
||
}
|
||
);
|
||
|
||
if (currentUser && currentUser.role === 'admin') {
|
||
navButtons.push({
|
||
onclick: "showSection('runtasks')",
|
||
className: "nav-btn assigned-to-me",
|
||
icon: "fas fa-user-check",
|
||
text: "Мои задачи (Исполнитель)",
|
||
id: "kanban-btn"
|
||
});
|
||
}
|
||
// 👇 Кнопка админ-панели ТОЛЬКО для admin 👇
|
||
if (currentUser && currentUser.role === 'admin') {
|
||
navButtons.push({
|
||
onclick: "window.location.href = '/admin'",
|
||
className: "nav-btn admin",
|
||
icon: "fas fa-cog",
|
||
text: "Админ-панель",
|
||
id: "admin-btn"
|
||
});
|
||
}
|
||
|
||
// Кнопка выхода
|
||
navButtons.push({
|
||
onclick: "logout()",
|
||
className: "btn-logout",
|
||
icon: "fas fa-sign-out-alt",
|
||
text: "Выйти",
|
||
id: "logout-btn"
|
||
});
|
||
|
||
// Очищаем и создаем кнопки
|
||
navbar.innerHTML = '';
|
||
navButtons.forEach(button => {
|
||
const btn = document.createElement('button');
|
||
btn.setAttribute('onclick', button.onclick);
|
||
btn.className = button.className;
|
||
btn.id = button.id;
|
||
btn.innerHTML = `<i class="${button.icon}"></i> ${button.text}`;
|
||
navbar.appendChild(btn);
|
||
});
|
||
}
|
||
|
||
// Инициализация при загрузке страницы
|
||
document.addEventListener('DOMContentLoaded', function() {
|
||
// createNavigation();
|
||
|
||
// Если нужно обновлять навигацию при изменениях
|
||
// window.addEventListener('userRoleChanged', createNavigation);
|
||
}); |