%
This commit is contained in:
@@ -1,361 +1,361 @@
|
||||
let currentUser = null;
|
||||
let users = [];
|
||||
let filteredUsers = [];
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
checkAuth();
|
||||
setupEventListeners();
|
||||
});
|
||||
|
||||
async function checkAuth() {
|
||||
try {
|
||||
const response = await fetch('/api/user');
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
currentUser = data.user;
|
||||
|
||||
if (currentUser.role !== 'admin') {
|
||||
window.location.href = '/';
|
||||
return;
|
||||
}
|
||||
|
||||
showAdminInterface();
|
||||
} else {
|
||||
showLoginInterface();
|
||||
}
|
||||
} catch (error) {
|
||||
showLoginInterface();
|
||||
}
|
||||
}
|
||||
|
||||
function showLoginInterface() {
|
||||
document.getElementById('login-modal').style.display = 'block';
|
||||
document.querySelector('.admin-container').style.display = 'none';
|
||||
}
|
||||
|
||||
function showAdminInterface() {
|
||||
document.getElementById('login-modal').style.display = 'none';
|
||||
document.querySelector('.admin-container').style.display = 'block';
|
||||
|
||||
let userInfo = `Администратор: ${currentUser.name}`;
|
||||
if (currentUser.auth_type === 'ldap') {
|
||||
userInfo += ` (LDAP)`;
|
||||
}
|
||||
|
||||
document.getElementById('current-user').textContent = userInfo;
|
||||
|
||||
loadUsers();
|
||||
loadDashboardStats();
|
||||
}
|
||||
|
||||
function setupEventListeners() {
|
||||
document.getElementById('login-form').addEventListener('submit', login);
|
||||
document.getElementById('edit-user-form').addEventListener('submit', updateUser);
|
||||
}
|
||||
|
||||
async function login(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const login = document.getElementById('login').value;
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ login, password })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
currentUser = data.user;
|
||||
|
||||
if (currentUser.role !== 'admin') {
|
||||
window.location.href = '/';
|
||||
return;
|
||||
}
|
||||
|
||||
showAdminInterface();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка входа');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка подключения к серверу');
|
||||
}
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
try {
|
||||
await fetch('/api/logout', { method: 'POST' });
|
||||
currentUser = null;
|
||||
showLoginInterface();
|
||||
} catch (error) {
|
||||
console.error('Ошибка выхода:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function showAdminSection(sectionName) {
|
||||
document.querySelectorAll('.admin-tab').forEach(tab => {
|
||||
tab.classList.remove('active');
|
||||
});
|
||||
|
||||
document.querySelectorAll('.admin-section').forEach(section => {
|
||||
section.classList.remove('active');
|
||||
});
|
||||
|
||||
document.querySelector(`.admin-tab[onclick="showAdminSection('${sectionName}')"]`).classList.add('active');
|
||||
document.getElementById(`admin-${sectionName}`).classList.add('active');
|
||||
|
||||
if (sectionName === 'users') {
|
||||
loadUsers();
|
||||
} else if (sectionName === 'dashboard') {
|
||||
loadDashboardStats();
|
||||
}
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
try {
|
||||
const response = await fetch('/admin/users');
|
||||
if (!response.ok) {
|
||||
throw new Error('Ошибка загрузки пользователей');
|
||||
}
|
||||
users = await response.json();
|
||||
filteredUsers = [...users];
|
||||
renderUsersTable();
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки пользователей:', error);
|
||||
showError('users-table-body', 'Ошибка загрузки пользователей');
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDashboardStats() {
|
||||
try {
|
||||
const response = await fetch('/admin/stats');
|
||||
if (!response.ok) {
|
||||
throw new Error('Ошибка загрузки статистики');
|
||||
}
|
||||
|
||||
const stats = await response.json();
|
||||
updateStatsUI(stats);
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки статистики:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function updateStatsUI(stats) {
|
||||
// Задачи
|
||||
document.getElementById('total-tasks').textContent = stats.totalTasks;
|
||||
document.getElementById('active-tasks').textContent = stats.activeTasks;
|
||||
document.getElementById('closed-tasks').textContent = stats.closedTasks;
|
||||
document.getElementById('deleted-tasks').textContent = stats.deletedTasks;
|
||||
|
||||
// Процент активных задач
|
||||
if (stats.totalTasks > 0) {
|
||||
const activePercentage = Math.round((stats.activeTasks / stats.totalTasks) * 100);
|
||||
document.getElementById('active-tasks-bar').style.width = `${activePercentage}%`;
|
||||
}
|
||||
|
||||
// Назначения
|
||||
document.getElementById('total-assignments').textContent = stats.totalAssignments;
|
||||
document.getElementById('assigned-count').textContent = stats.assignedCount;
|
||||
document.getElementById('in-progress-count').textContent = stats.inProgressCount;
|
||||
document.getElementById('completed-count').textContent = stats.completedCount;
|
||||
document.getElementById('overdue-count').textContent = stats.overdueCount;
|
||||
document.getElementById('rework-count').textContent = stats.reworkCount;
|
||||
|
||||
// Пользователи
|
||||
document.getElementById('total-users').textContent = stats.totalUsers;
|
||||
document.getElementById('admin-users').textContent = stats.adminUsers;
|
||||
document.getElementById('teacher-users').textContent = stats.teacherUsers;
|
||||
document.getElementById('ldap-users').textContent = stats.ldapUsers;
|
||||
document.getElementById('local-users').textContent = stats.localUsers;
|
||||
|
||||
// Файлы
|
||||
document.getElementById('total-files').textContent = stats.totalFiles;
|
||||
const fileSizeMB = (stats.totalFilesSize / 1024 / 1024).toFixed(2);
|
||||
document.getElementById('total-files-size').textContent = `${fileSizeMB} MB`;
|
||||
|
||||
}
|
||||
|
||||
function searchUsers() {
|
||||
const search = document.getElementById('user-search').value.toLowerCase();
|
||||
filteredUsers = users.filter(user =>
|
||||
user.login.toLowerCase().includes(search) ||
|
||||
user.name.toLowerCase().includes(search) ||
|
||||
user.email.toLowerCase().includes(search) ||
|
||||
user.role.toLowerCase().includes(search) ||
|
||||
user.auth_type.toLowerCase().includes(search)
|
||||
);
|
||||
renderUsersTable();
|
||||
}
|
||||
|
||||
function renderUsersTable() {
|
||||
const tbody = document.getElementById('users-table-body');
|
||||
|
||||
if (!filteredUsers || filteredUsers.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="9" class="loading">Пользователи не найдены</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
tbody.innerHTML = filteredUsers.map(user => `
|
||||
<tr>
|
||||
<td>${user.id}</td>
|
||||
<td>
|
||||
${user.login}
|
||||
${user.auth_type === 'ldap' ? '<span class="ldap-badge">LDAP</span>' : ''}
|
||||
</td>
|
||||
<td>${user.name}</td>
|
||||
<td>${user.email}</td>
|
||||
<td>
|
||||
${user.role === 'admin' ? 'Администратор' : 'Учитель'}
|
||||
${user.role === 'admin' ? '<span class="admin-badge">ADMIN</span>' : ''}
|
||||
</td>
|
||||
<td>${user.auth_type === 'ldap' ? 'LDAP' : 'Локальная'}</td>
|
||||
<td>${formatDate(user.created_at)}</td>
|
||||
<td>${user.last_login ? formatDateTime(user.last_login) : 'Никогда'}</td>
|
||||
<td class="user-actions">
|
||||
<button class="edit-btn" onclick="openEditUserModal(${user.id})" title="Редактировать">✏️</button>
|
||||
<button class="delete-btn" onclick="deleteUser(${user.id})" title="Удалить" ${user.id === currentUser.id ? 'disabled' : ''}>🗑️</button>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
async function openEditUserModal(userId) {
|
||||
try {
|
||||
const response = await fetch(`/admin/users/${userId}`);
|
||||
if (!response.ok) {
|
||||
throw new Error('Ошибка загрузки пользователя');
|
||||
}
|
||||
|
||||
const user = await response.json();
|
||||
|
||||
document.getElementById('edit-user-id').value = user.id;
|
||||
document.getElementById('edit-login').value = user.login;
|
||||
document.getElementById('edit-name').value = user.name;
|
||||
document.getElementById('edit-email').value = user.email;
|
||||
document.getElementById('edit-role').value = user.role;
|
||||
document.getElementById('edit-auth-type').value = user.auth_type;
|
||||
document.getElementById('edit-groups').value = user.groups || '[]';
|
||||
document.getElementById('edit-description').value = user.description || '';
|
||||
|
||||
document.getElementById('edit-user-modal').style.display = 'block';
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка загрузки пользователя');
|
||||
}
|
||||
}
|
||||
|
||||
function closeEditUserModal() {
|
||||
document.getElementById('edit-user-modal').style.display = 'none';
|
||||
}
|
||||
|
||||
async function updateUser(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const userId = document.getElementById('edit-user-id').value;
|
||||
const login = document.getElementById('edit-login').value;
|
||||
const name = document.getElementById('edit-name').value;
|
||||
const email = document.getElementById('edit-email').value;
|
||||
const role = document.getElementById('edit-role').value;
|
||||
const auth_type = document.getElementById('edit-auth-type').value;
|
||||
const groups = document.getElementById('edit-groups').value;
|
||||
const description = document.getElementById('edit-description').value;
|
||||
|
||||
if (!login || !name || !email) {
|
||||
alert('Заполните обязательные поля');
|
||||
return;
|
||||
}
|
||||
|
||||
const userData = {
|
||||
login,
|
||||
name,
|
||||
email,
|
||||
role,
|
||||
auth_type,
|
||||
groups: groups || '[]',
|
||||
description
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(`/admin/users/${userId}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(userData)
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Пользователь успешно обновлен!');
|
||||
closeEditUserModal();
|
||||
loadUsers();
|
||||
loadDashboardStats();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка обновления пользователя');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка обновления пользователя');
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteUser(userId) {
|
||||
if (userId === currentUser.id) {
|
||||
alert('Нельзя удалить самого себя');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!confirm('Вы уверены, что хотите удалить этого пользователя?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/admin/users/${userId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Пользователь успешно удален!');
|
||||
loadUsers();
|
||||
loadDashboardStats();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка удаления пользователя');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка удаления пользователя');
|
||||
}
|
||||
}
|
||||
|
||||
function formatDateTime(dateTimeString) {
|
||||
if (!dateTimeString) return '';
|
||||
const date = new Date(dateTimeString);
|
||||
return date.toLocaleString('ru-RU');
|
||||
}
|
||||
|
||||
function formatDate(dateString) {
|
||||
if (!dateString) return '';
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('ru-RU');
|
||||
}
|
||||
|
||||
function showError(elementId, message) {
|
||||
const element = document.getElementById(elementId);
|
||||
if (element) {
|
||||
element.innerHTML = `<tr><td colspan="9" class="error">${message}</td></tr>`;
|
||||
}
|
||||
}
|
||||
|
||||
// Автоматическое обновление статистики каждые 30 секунд
|
||||
setInterval(() => {
|
||||
if (document.getElementById('admin-dashboard').classList.contains('active')) {
|
||||
loadDashboardStats();
|
||||
}
|
||||
let currentUser = null;
|
||||
let users = [];
|
||||
let filteredUsers = [];
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
checkAuth();
|
||||
setupEventListeners();
|
||||
});
|
||||
|
||||
async function checkAuth() {
|
||||
try {
|
||||
const response = await fetch('/api/user');
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
currentUser = data.user;
|
||||
|
||||
if (currentUser.role !== 'admin') {
|
||||
window.location.href = '/';
|
||||
return;
|
||||
}
|
||||
|
||||
showAdminInterface();
|
||||
} else {
|
||||
showLoginInterface();
|
||||
}
|
||||
} catch (error) {
|
||||
showLoginInterface();
|
||||
}
|
||||
}
|
||||
|
||||
function showLoginInterface() {
|
||||
document.getElementById('login-modal').style.display = 'block';
|
||||
document.querySelector('.admin-container').style.display = 'none';
|
||||
}
|
||||
|
||||
function showAdminInterface() {
|
||||
document.getElementById('login-modal').style.display = 'none';
|
||||
document.querySelector('.admin-container').style.display = 'block';
|
||||
|
||||
let userInfo = `Администратор: ${currentUser.name}`;
|
||||
if (currentUser.auth_type === 'ldap') {
|
||||
userInfo += ` (LDAP)`;
|
||||
}
|
||||
|
||||
document.getElementById('current-user').textContent = userInfo;
|
||||
|
||||
loadUsers();
|
||||
loadDashboardStats();
|
||||
}
|
||||
|
||||
function setupEventListeners() {
|
||||
document.getElementById('login-form').addEventListener('submit', login);
|
||||
document.getElementById('edit-user-form').addEventListener('submit', updateUser);
|
||||
}
|
||||
|
||||
async function login(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const login = document.getElementById('login').value;
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ login, password })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
currentUser = data.user;
|
||||
|
||||
if (currentUser.role !== 'admin') {
|
||||
window.location.href = '/';
|
||||
return;
|
||||
}
|
||||
|
||||
showAdminInterface();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка входа');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка подключения к серверу');
|
||||
}
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
try {
|
||||
await fetch('/api/logout', { method: 'POST' });
|
||||
currentUser = null;
|
||||
showLoginInterface();
|
||||
} catch (error) {
|
||||
console.error('Ошибка выхода:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function showAdminSection(sectionName) {
|
||||
document.querySelectorAll('.admin-tab').forEach(tab => {
|
||||
tab.classList.remove('active');
|
||||
});
|
||||
|
||||
document.querySelectorAll('.admin-section').forEach(section => {
|
||||
section.classList.remove('active');
|
||||
});
|
||||
|
||||
document.querySelector(`.admin-tab[onclick="showAdminSection('${sectionName}')"]`).classList.add('active');
|
||||
document.getElementById(`admin-${sectionName}`).classList.add('active');
|
||||
|
||||
if (sectionName === 'users') {
|
||||
loadUsers();
|
||||
} else if (sectionName === 'dashboard') {
|
||||
loadDashboardStats();
|
||||
}
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
try {
|
||||
const response = await fetch('/admin/users');
|
||||
if (!response.ok) {
|
||||
throw new Error('Ошибка загрузки пользователей');
|
||||
}
|
||||
users = await response.json();
|
||||
filteredUsers = [...users];
|
||||
renderUsersTable();
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки пользователей:', error);
|
||||
showError('users-table-body', 'Ошибка загрузки пользователей');
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDashboardStats() {
|
||||
try {
|
||||
const response = await fetch('/admin/stats');
|
||||
if (!response.ok) {
|
||||
throw new Error('Ошибка загрузки статистики');
|
||||
}
|
||||
|
||||
const stats = await response.json();
|
||||
updateStatsUI(stats);
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки статистики:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function updateStatsUI(stats) {
|
||||
// Задачи
|
||||
document.getElementById('total-tasks').textContent = stats.totalTasks;
|
||||
document.getElementById('active-tasks').textContent = stats.activeTasks;
|
||||
document.getElementById('closed-tasks').textContent = stats.closedTasks;
|
||||
document.getElementById('deleted-tasks').textContent = stats.deletedTasks;
|
||||
|
||||
// Процент активных задач
|
||||
if (stats.totalTasks > 0) {
|
||||
const activePercentage = Math.round((stats.activeTasks / stats.totalTasks) * 100);
|
||||
document.getElementById('active-tasks-bar').style.width = `${activePercentage}%`;
|
||||
}
|
||||
|
||||
// Назначения
|
||||
document.getElementById('total-assignments').textContent = stats.totalAssignments;
|
||||
document.getElementById('assigned-count').textContent = stats.assignedCount;
|
||||
document.getElementById('in-progress-count').textContent = stats.inProgressCount;
|
||||
document.getElementById('completed-count').textContent = stats.completedCount;
|
||||
document.getElementById('overdue-count').textContent = stats.overdueCount;
|
||||
document.getElementById('rework-count').textContent = stats.reworkCount;
|
||||
|
||||
// Пользователи
|
||||
document.getElementById('total-users').textContent = stats.totalUsers;
|
||||
document.getElementById('admin-users').textContent = stats.adminUsers;
|
||||
document.getElementById('teacher-users').textContent = stats.teacherUsers;
|
||||
document.getElementById('ldap-users').textContent = stats.ldapUsers;
|
||||
document.getElementById('local-users').textContent = stats.localUsers;
|
||||
|
||||
// Файлы
|
||||
document.getElementById('total-files').textContent = stats.totalFiles;
|
||||
const fileSizeMB = (stats.totalFilesSize / 1024 / 1024).toFixed(2);
|
||||
document.getElementById('total-files-size').textContent = `${fileSizeMB} MB`;
|
||||
|
||||
}
|
||||
|
||||
function searchUsers() {
|
||||
const search = document.getElementById('user-search').value.toLowerCase();
|
||||
filteredUsers = users.filter(user =>
|
||||
user.login.toLowerCase().includes(search) ||
|
||||
user.name.toLowerCase().includes(search) ||
|
||||
user.email.toLowerCase().includes(search) ||
|
||||
user.role.toLowerCase().includes(search) ||
|
||||
user.auth_type.toLowerCase().includes(search)
|
||||
);
|
||||
renderUsersTable();
|
||||
}
|
||||
|
||||
function renderUsersTable() {
|
||||
const tbody = document.getElementById('users-table-body');
|
||||
|
||||
if (!filteredUsers || filteredUsers.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="9" class="loading">Пользователи не найдены</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
tbody.innerHTML = filteredUsers.map(user => `
|
||||
<tr>
|
||||
<td>${user.id}</td>
|
||||
<td>
|
||||
${user.login}
|
||||
${user.auth_type === 'ldap' ? '<span class="ldap-badge">LDAP</span>' : ''}
|
||||
</td>
|
||||
<td>${user.name}</td>
|
||||
<td>${user.email}</td>
|
||||
<td>
|
||||
${user.role === 'admin' ? 'Администратор' : 'Учитель'}
|
||||
${user.role === 'admin' ? '<span class="admin-badge">ADMIN</span>' : ''}
|
||||
</td>
|
||||
<td>${user.auth_type === 'ldap' ? 'LDAP' : 'Локальная'}</td>
|
||||
<td>${formatDate(user.created_at)}</td>
|
||||
<td>${user.last_login ? formatDateTime(user.last_login) : 'Никогда'}</td>
|
||||
<td class="user-actions">
|
||||
<button class="edit-btn" onclick="openEditUserModal(${user.id})" title="Редактировать">✏️</button>
|
||||
<button class="delete-btn" onclick="deleteUser(${user.id})" title="Удалить" ${user.id === currentUser.id ? 'disabled' : ''}>🗑️</button>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
async function openEditUserModal(userId) {
|
||||
try {
|
||||
const response = await fetch(`/admin/users/${userId}`);
|
||||
if (!response.ok) {
|
||||
throw new Error('Ошибка загрузки пользователя');
|
||||
}
|
||||
|
||||
const user = await response.json();
|
||||
|
||||
document.getElementById('edit-user-id').value = user.id;
|
||||
document.getElementById('edit-login').value = user.login;
|
||||
document.getElementById('edit-name').value = user.name;
|
||||
document.getElementById('edit-email').value = user.email;
|
||||
document.getElementById('edit-role').value = user.role;
|
||||
document.getElementById('edit-auth-type').value = user.auth_type;
|
||||
document.getElementById('edit-groups').value = user.groups || '[]';
|
||||
document.getElementById('edit-description').value = user.description || '';
|
||||
|
||||
document.getElementById('edit-user-modal').style.display = 'block';
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка загрузки пользователя');
|
||||
}
|
||||
}
|
||||
|
||||
function closeEditUserModal() {
|
||||
document.getElementById('edit-user-modal').style.display = 'none';
|
||||
}
|
||||
|
||||
async function updateUser(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const userId = document.getElementById('edit-user-id').value;
|
||||
const login = document.getElementById('edit-login').value;
|
||||
const name = document.getElementById('edit-name').value;
|
||||
const email = document.getElementById('edit-email').value;
|
||||
const role = document.getElementById('edit-role').value;
|
||||
const auth_type = document.getElementById('edit-auth-type').value;
|
||||
const groups = document.getElementById('edit-groups').value;
|
||||
const description = document.getElementById('edit-description').value;
|
||||
|
||||
if (!login || !name || !email) {
|
||||
alert('Заполните обязательные поля');
|
||||
return;
|
||||
}
|
||||
|
||||
const userData = {
|
||||
login,
|
||||
name,
|
||||
email,
|
||||
role,
|
||||
auth_type,
|
||||
groups: groups || '[]',
|
||||
description
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(`/admin/users/${userId}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(userData)
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Пользователь успешно обновлен!');
|
||||
closeEditUserModal();
|
||||
loadUsers();
|
||||
loadDashboardStats();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка обновления пользователя');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка обновления пользователя');
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteUser(userId) {
|
||||
if (userId === currentUser.id) {
|
||||
alert('Нельзя удалить самого себя');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!confirm('Вы уверены, что хотите удалить этого пользователя?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/admin/users/${userId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Пользователь успешно удален!');
|
||||
loadUsers();
|
||||
loadDashboardStats();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка удаления пользователя');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка удаления пользователя');
|
||||
}
|
||||
}
|
||||
|
||||
function formatDateTime(dateTimeString) {
|
||||
if (!dateTimeString) return '';
|
||||
const date = new Date(dateTimeString);
|
||||
return date.toLocaleString('ru-RU');
|
||||
}
|
||||
|
||||
function formatDate(dateString) {
|
||||
if (!dateString) return '';
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('ru-RU');
|
||||
}
|
||||
|
||||
function showError(elementId, message) {
|
||||
const element = document.getElementById(elementId);
|
||||
if (element) {
|
||||
element.innerHTML = `<tr><td colspan="9" class="error">${message}</td></tr>`;
|
||||
}
|
||||
}
|
||||
|
||||
// Автоматическое обновление статистики каждые 30 секунд
|
||||
setInterval(() => {
|
||||
if (document.getElementById('admin-dashboard').classList.contains('active')) {
|
||||
loadDashboardStats();
|
||||
}
|
||||
}, 30000);
|
||||
@@ -1,462 +1,462 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>School CRM - Административная панель</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<style>
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
||||
border-left: 4px solid #3498db;
|
||||
}
|
||||
|
||||
.stat-card.task-stat {
|
||||
border-left-color: #3498db;
|
||||
}
|
||||
|
||||
.stat-card.user-stat {
|
||||
border-left-color: #2ecc71;
|
||||
}
|
||||
|
||||
.stat-card.file-stat {
|
||||
border-left-color: #9b59b6;
|
||||
}
|
||||
|
||||
.stat-card.status-stat {
|
||||
border-left-color: #f39c12;
|
||||
}
|
||||
|
||||
.stat-card h3 {
|
||||
margin: 0 0 15px 0;
|
||||
color: #495057;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 2.5rem;
|
||||
font-weight: 700;
|
||||
color: #2c3e50;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.stat-desc {
|
||||
color: #6c757d;
|
||||
font-size: 0.9rem;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.stat-subitems {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.stat-subitem {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 5px 0;
|
||||
border-bottom: 1px solid #f1f1f1;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.stat-subitem:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.stat-subitem .label {
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.stat-subitem .value {
|
||||
font-weight: 600;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
.recent-tasks {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.recent-tasks h3 {
|
||||
margin: 0 0 15px 0;
|
||||
color: #495057;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.task-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
border-bottom: 1px solid #e9ecef;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.task-item:hover {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.task-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.task-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.task-title {
|
||||
font-weight: 600;
|
||||
color: #2c3e50;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.task-meta {
|
||||
font-size: 0.85rem;
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.task-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.view-task-btn {
|
||||
padding: 6px 12px;
|
||||
background: #3498db;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 0.85rem;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.view-task-btn:hover {
|
||||
background: #2980b9;
|
||||
}
|
||||
|
||||
.percentage-bar {
|
||||
height: 6px;
|
||||
background: #e9ecef;
|
||||
border-radius: 3px;
|
||||
margin-top: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.percentage-fill {
|
||||
height: 100%;
|
||||
background: #3498db;
|
||||
border-radius: 3px;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.users-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.users-table th,
|
||||
.users-table td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.users-table th {
|
||||
background: #f8f9fa;
|
||||
font-weight: 600;
|
||||
color: #495057;
|
||||
}
|
||||
|
||||
.users-table tr:hover {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.user-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.ldap-badge {
|
||||
background: #3498db;
|
||||
color: white;
|
||||
padding: 3px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.75rem;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.admin-badge {
|
||||
background: #e74c3c;
|
||||
color: white;
|
||||
padding: 3px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.75rem;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-row .form-group {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.modal-lg {
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.search-container {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.search-container input {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.file-size {
|
||||
font-size: 1.2rem;
|
||||
color: #2c3e50;
|
||||
margin-top: 5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="login-modal" class="modal">
|
||||
<div class="modal-content">
|
||||
<h2>Вход в School CRM</h2>
|
||||
<form id="login-form">
|
||||
<div class="form-group">
|
||||
<label for="login">Логин:</label>
|
||||
<input type="text" id="login" name="login" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Пароль:</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit">Войти</button>
|
||||
</form>
|
||||
<div class="test-users">
|
||||
<h3>Тестовые пользователи:</h3>
|
||||
<ul>
|
||||
<li><strong>admin</strong> / admin123 (Администратор)</li>
|
||||
<li><strong>teacher</strong> / teacher123</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-container">
|
||||
<div class="admin-header">
|
||||
<h1>Административная панель</h1>
|
||||
<div class="user-info">
|
||||
<span id="current-user"></span>
|
||||
<button onclick="window.location.href = '/'">Назад к задачам</button>
|
||||
<button onclick="logout()">Выйти</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-tabs">
|
||||
<button class="admin-tab active" onclick="showAdminSection('dashboard')">Дашборд</button>
|
||||
<button class="admin-tab" onclick="showAdminSection('users')">Пользователи</button>
|
||||
<button class="admin-tab" onclick="showAdminSection('dashboard')">test</button>
|
||||
</div>
|
||||
|
||||
<div id="admin-dashboard" class="admin-section active">
|
||||
<h2>Статистика системы</h2>
|
||||
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card task-stat">
|
||||
<h3>Задачи</h3>
|
||||
<div class="stat-value" id="total-tasks">0</div>
|
||||
<div class="stat-desc">Всего задач в системе</div>
|
||||
<div class="percentage-bar">
|
||||
<div class="percentage-fill" id="active-tasks-bar" style="width: 0%"></div>
|
||||
</div>
|
||||
<div class="stat-subitems">
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Активные:</span>
|
||||
<span class="value" id="active-tasks">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Закрытые:</span>
|
||||
<span class="value" id="closed-tasks">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Удаленные:</span>
|
||||
<span class="value" id="deleted-tasks">0</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card status-stat">
|
||||
<h3>Статусы назначений</h3>
|
||||
<div class="stat-value" id="total-assignments">0</div>
|
||||
<div class="stat-desc">Всего назначений</div>
|
||||
<div class="stat-subitems">
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Назначено:</span>
|
||||
<span class="value" id="assigned-count">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">В работе:</span>
|
||||
<span class="value" id="in-progress-count">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Выполнено:</span>
|
||||
<span class="value" id="completed-count">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Просрочено:</span>
|
||||
<span class="value" id="overdue-count">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">На доработке:</span>
|
||||
<span class="value" id="rework-count">0</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card user-stat">
|
||||
<h3>Пользователи</h3>
|
||||
<div class="stat-value" id="total-users">0</div>
|
||||
<div class="stat-desc">Зарегистрировано пользователей</div>
|
||||
<div class="stat-subitems">
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Администраторы:</span>
|
||||
<span class="value" id="admin-users">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Учителя:</span>
|
||||
<span class="value" id="teacher-users">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">LDAP:</span>
|
||||
<span class="value" id="ldap-users">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Локальные:</span>
|
||||
<span class="value" id="local-users">0</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card file-stat">
|
||||
<h3>Файлы</h3>
|
||||
<div class="stat-value" id="total-files">0</div>
|
||||
<div class="stat-desc">Всего загружено файлов</div>
|
||||
<div class="file-size" id="total-files-size">0 MB</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="admin-users-section" class="admin-section">
|
||||
<h2>Управление пользователями</h2>
|
||||
|
||||
<div class="search-container">
|
||||
<input type="text" id="user-search" placeholder="Поиск пользователей по логину, имени или email..." oninput="searchUsers()">
|
||||
<button onclick="loadUsers()">Сбросить</button>
|
||||
</div>
|
||||
|
||||
<table class="users-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Логин</th>
|
||||
<th>Имя</th>
|
||||
<th>Email</th>
|
||||
<th>Роль</th>
|
||||
<th>Тип</th>
|
||||
<th>Дата создания</th>
|
||||
<th>Последний вход</th>
|
||||
<th>Действия</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="users-table-body">
|
||||
<tr>
|
||||
<td colspan="9" class="loading">Загрузка пользователей...</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="edit-user-modal" class="modal">
|
||||
<div class="modal-content modal-lg">
|
||||
<span class="close" onclick="closeEditUserModal()">×</span>
|
||||
<h3>Редактировать пользователя</h3>
|
||||
<form id="edit-user-form">
|
||||
<input type="hidden" id="edit-user-id">
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="edit-login">Логин *</label>
|
||||
<input type="text" id="edit-login" name="login" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="edit-name">Имя *</label>
|
||||
<input type="text" id="edit-name" name="name" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="edit-email">Email *</label>
|
||||
<input type="email" id="edit-email" name="email" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="edit-role">Роль</label>
|
||||
<select id="edit-role" name="role">
|
||||
<option value="teacher">Учитель</option>
|
||||
<option value="admin">Администратор</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="edit-auth-type">Тип авторизации</label>
|
||||
<select id="edit-auth-type" name="auth_type">
|
||||
<option value="local">Локальная</option>
|
||||
<option value="ldap">LDAP</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="edit-groups">Группы (JSON)</label>
|
||||
<input type="text" id="edit-groups" name="groups" placeholder='["group1", "group2"]'>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="edit-description">Описание</label>
|
||||
<textarea id="edit-description" name="description" rows="3"></textarea>
|
||||
</div>
|
||||
|
||||
<button type="submit">Сохранить изменения</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="admin-script.js"></script>
|
||||
</body>
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>School CRM - Административная панель</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<style>
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
||||
border-left: 4px solid #3498db;
|
||||
}
|
||||
|
||||
.stat-card.task-stat {
|
||||
border-left-color: #3498db;
|
||||
}
|
||||
|
||||
.stat-card.user-stat {
|
||||
border-left-color: #2ecc71;
|
||||
}
|
||||
|
||||
.stat-card.file-stat {
|
||||
border-left-color: #9b59b6;
|
||||
}
|
||||
|
||||
.stat-card.status-stat {
|
||||
border-left-color: #f39c12;
|
||||
}
|
||||
|
||||
.stat-card h3 {
|
||||
margin: 0 0 15px 0;
|
||||
color: #495057;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 2.5rem;
|
||||
font-weight: 700;
|
||||
color: #2c3e50;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.stat-desc {
|
||||
color: #6c757d;
|
||||
font-size: 0.9rem;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.stat-subitems {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.stat-subitem {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 5px 0;
|
||||
border-bottom: 1px solid #f1f1f1;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.stat-subitem:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.stat-subitem .label {
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.stat-subitem .value {
|
||||
font-weight: 600;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
.recent-tasks {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.recent-tasks h3 {
|
||||
margin: 0 0 15px 0;
|
||||
color: #495057;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.task-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
border-bottom: 1px solid #e9ecef;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.task-item:hover {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.task-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.task-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.task-title {
|
||||
font-weight: 600;
|
||||
color: #2c3e50;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.task-meta {
|
||||
font-size: 0.85rem;
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.task-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.view-task-btn {
|
||||
padding: 6px 12px;
|
||||
background: #3498db;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 0.85rem;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.view-task-btn:hover {
|
||||
background: #2980b9;
|
||||
}
|
||||
|
||||
.percentage-bar {
|
||||
height: 6px;
|
||||
background: #e9ecef;
|
||||
border-radius: 3px;
|
||||
margin-top: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.percentage-fill {
|
||||
height: 100%;
|
||||
background: #3498db;
|
||||
border-radius: 3px;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.users-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.users-table th,
|
||||
.users-table td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.users-table th {
|
||||
background: #f8f9fa;
|
||||
font-weight: 600;
|
||||
color: #495057;
|
||||
}
|
||||
|
||||
.users-table tr:hover {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.user-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.ldap-badge {
|
||||
background: #3498db;
|
||||
color: white;
|
||||
padding: 3px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.75rem;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.admin-badge {
|
||||
background: #e74c3c;
|
||||
color: white;
|
||||
padding: 3px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.75rem;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-row .form-group {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.modal-lg {
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.search-container {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.search-container input {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.file-size {
|
||||
font-size: 1.2rem;
|
||||
color: #2c3e50;
|
||||
margin-top: 5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="login-modal" class="modal">
|
||||
<div class="modal-content">
|
||||
<h2>Вход в School CRM</h2>
|
||||
<form id="login-form">
|
||||
<div class="form-group">
|
||||
<label for="login">Логин:</label>
|
||||
<input type="text" id="login" name="login" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Пароль:</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit">Войти</button>
|
||||
</form>
|
||||
<div class="test-users">
|
||||
<h3>Тестовые пользователи:</h3>
|
||||
<ul>
|
||||
<li><strong>admin</strong> / admin123 (Администратор)</li>
|
||||
<li><strong>teacher</strong> / teacher123</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-container">
|
||||
<div class="admin-header">
|
||||
<h1>Административная панель</h1>
|
||||
<div class="user-info">
|
||||
<span id="current-user"></span>
|
||||
<button onclick="window.location.href = '/'">Назад к задачам</button>
|
||||
<button onclick="logout()">Выйти</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-tabs">
|
||||
<button class="admin-tab active" onclick="showAdminSection('dashboard')">Дашборд</button>
|
||||
<button class="admin-tab" onclick="showAdminSection('users')">Пользователи</button>
|
||||
<button class="admin-tab" onclick="showAdminSection('dashboard')">test</button>
|
||||
</div>
|
||||
|
||||
<div id="admin-dashboard" class="admin-section active">
|
||||
<h2>Статистика системы</h2>
|
||||
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card task-stat">
|
||||
<h3>Задачи</h3>
|
||||
<div class="stat-value" id="total-tasks">0</div>
|
||||
<div class="stat-desc">Всего задач в системе</div>
|
||||
<div class="percentage-bar">
|
||||
<div class="percentage-fill" id="active-tasks-bar" style="width: 0%"></div>
|
||||
</div>
|
||||
<div class="stat-subitems">
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Активные:</span>
|
||||
<span class="value" id="active-tasks">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Закрытые:</span>
|
||||
<span class="value" id="closed-tasks">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Удаленные:</span>
|
||||
<span class="value" id="deleted-tasks">0</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card status-stat">
|
||||
<h3>Статусы назначений</h3>
|
||||
<div class="stat-value" id="total-assignments">0</div>
|
||||
<div class="stat-desc">Всего назначений</div>
|
||||
<div class="stat-subitems">
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Назначено:</span>
|
||||
<span class="value" id="assigned-count">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">В работе:</span>
|
||||
<span class="value" id="in-progress-count">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Выполнено:</span>
|
||||
<span class="value" id="completed-count">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Просрочено:</span>
|
||||
<span class="value" id="overdue-count">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">На доработке:</span>
|
||||
<span class="value" id="rework-count">0</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card user-stat">
|
||||
<h3>Пользователи</h3>
|
||||
<div class="stat-value" id="total-users">0</div>
|
||||
<div class="stat-desc">Зарегистрировано пользователей</div>
|
||||
<div class="stat-subitems">
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Администраторы:</span>
|
||||
<span class="value" id="admin-users">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Учителя:</span>
|
||||
<span class="value" id="teacher-users">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">LDAP:</span>
|
||||
<span class="value" id="ldap-users">0</span>
|
||||
</div>
|
||||
<div class="stat-subitem">
|
||||
<span class="label">Локальные:</span>
|
||||
<span class="value" id="local-users">0</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card file-stat">
|
||||
<h3>Файлы</h3>
|
||||
<div class="stat-value" id="total-files">0</div>
|
||||
<div class="stat-desc">Всего загружено файлов</div>
|
||||
<div class="file-size" id="total-files-size">0 MB</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="admin-users-section" class="admin-section">
|
||||
<h2>Управление пользователями</h2>
|
||||
|
||||
<div class="search-container">
|
||||
<input type="text" id="user-search" placeholder="Поиск пользователей по логину, имени или email..." oninput="searchUsers()">
|
||||
<button onclick="loadUsers()">Сбросить</button>
|
||||
</div>
|
||||
|
||||
<table class="users-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Логин</th>
|
||||
<th>Имя</th>
|
||||
<th>Email</th>
|
||||
<th>Роль</th>
|
||||
<th>Тип</th>
|
||||
<th>Дата создания</th>
|
||||
<th>Последний вход</th>
|
||||
<th>Действия</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="users-table-body">
|
||||
<tr>
|
||||
<td colspan="9" class="loading">Загрузка пользователей...</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="edit-user-modal" class="modal">
|
||||
<div class="modal-content modal-lg">
|
||||
<span class="close" onclick="closeEditUserModal()">×</span>
|
||||
<h3>Редактировать пользователя</h3>
|
||||
<form id="edit-user-form">
|
||||
<input type="hidden" id="edit-user-id">
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="edit-login">Логин *</label>
|
||||
<input type="text" id="edit-login" name="login" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="edit-name">Имя *</label>
|
||||
<input type="text" id="edit-name" name="name" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="edit-email">Email *</label>
|
||||
<input type="email" id="edit-email" name="email" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="edit-role">Роль</label>
|
||||
<select id="edit-role" name="role">
|
||||
<option value="teacher">Учитель</option>
|
||||
<option value="admin">Администратор</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="edit-auth-type">Тип авторизации</label>
|
||||
<select id="edit-auth-type" name="auth_type">
|
||||
<option value="local">Локальная</option>
|
||||
<option value="ldap">LDAP</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="edit-groups">Группы (JSON)</label>
|
||||
<input type="text" id="edit-groups" name="groups" placeholder='["group1", "group2"]'>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="edit-description">Описание</label>
|
||||
<textarea id="edit-description" name="description" rows="3"></textarea>
|
||||
</div>
|
||||
|
||||
<button type="submit">Сохранить изменения</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="admin-script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -41,6 +41,7 @@
|
||||
<button onclick="showSection('tasks')">Задачи</button>
|
||||
<button onclick="showSection('create-task')">Создать задачу</button>
|
||||
<button onclick="showTasksWithoutDate()" id="tasks-no-date-btn">Задачи без срока</button>
|
||||
<button onclick="showKanbanSection()" class="nav-btn">📋 Канбан</button>
|
||||
<button onclick="showSection('logs')">Лог активности</button>
|
||||
<button onclick="window.location.href = '/admin'" style="background: linear-gradient(135deg, #e74c3c, #c0392b);">Админ-панель</button>
|
||||
</nav>
|
||||
@@ -234,7 +235,16 @@
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="kanban-section" class="section kanban-section">
|
||||
<div class="section-header">
|
||||
<h2>📋 Канбан-доска</h2>
|
||||
<p>Перетаскивайте задачи между колонками для изменения статуса</p>
|
||||
</div>
|
||||
|
||||
<div id="kanban-board" class="kanban-board">
|
||||
<div class="loading">Загрузка Канбан-доски...</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
400
public/script.js
400
public/script.js
@@ -5,6 +5,9 @@ let filteredUsers = [];
|
||||
let expandedTasks = new Set();
|
||||
let showingTasksWithoutDate = false;
|
||||
|
||||
let kanbanTasks = [];
|
||||
let kanbanDays = 14;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
checkAuth();
|
||||
setupEventListeners();
|
||||
@@ -59,6 +62,7 @@ function showMainInterface() {
|
||||
loadTasks();
|
||||
loadActivityLogs();
|
||||
showSection('tasks');
|
||||
loadKanbanTasks();
|
||||
|
||||
showingTasksWithoutDate = false;
|
||||
const btn = document.getElementById('tasks-no-date-btn');
|
||||
@@ -127,6 +131,9 @@ function showSection(sectionName) {
|
||||
} else if (sectionName === 'logs') {
|
||||
loadActivityLogs();
|
||||
}
|
||||
if (sectionName === 'kanban') {
|
||||
loadKanbanTasks();
|
||||
}
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
@@ -161,6 +168,355 @@ function populateFilterDropdowns() {
|
||||
});
|
||||
}
|
||||
|
||||
function showKanbanSection() {
|
||||
showSection('kanban');
|
||||
}
|
||||
|
||||
async function loadKanbanTasks() {
|
||||
try {
|
||||
const daysSelect = document.getElementById('kanban-days');
|
||||
const filterSelect = document.getElementById('kanban-filter');
|
||||
|
||||
// Если есть выбор в интерфейсе - используем его, иначе - значение по умолчанию
|
||||
if (daysSelect) {
|
||||
kanbanDays = parseInt(daysSelect.value) || 14;
|
||||
} else {
|
||||
kanbanDays = 14;
|
||||
}
|
||||
|
||||
let filter = 'all';
|
||||
if (filterSelect) {
|
||||
filter = filterSelect.value;
|
||||
}
|
||||
|
||||
const response = await fetch(`/api/kanban-tasks?days=${kanbanDays}&filter=${filter}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Ошибка сервера: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
kanbanTasks = data.tasks || [];
|
||||
renderKanban(data.filter);
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки задач для Канбана:', error);
|
||||
document.getElementById('kanban-board').innerHTML = `
|
||||
<div class="error-message">
|
||||
❌ Ошибка загрузки Канбана: ${error.message}
|
||||
<button onclick="loadKanbanTasks()" class="retry-btn">Повторить</button>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
function renderKanban() {
|
||||
const container = document.getElementById('kanban-board');
|
||||
|
||||
// Группируем задачи по статусам
|
||||
const columns = {
|
||||
'unassigned': { title: 'Не назначены', tasks: [], color: '#95a5a6' },
|
||||
'assigned': { title: 'Назначены', tasks: [], color: '#e74c3c' },
|
||||
'in_progress': { title: 'В работе', tasks: [], color: '#f39c12' },
|
||||
'rework': { title: 'На доработке', tasks: [], color: '#f1c40f' },
|
||||
'overdue': { title: 'Просрочены', tasks: [], color: '#c0392b' },
|
||||
'completed': { title: 'Выполнены', tasks: [], color: '#2ecc71' }
|
||||
};
|
||||
|
||||
// Распределяем задачи по колонкам
|
||||
kanbanTasks.forEach(task => {
|
||||
const status = task.kanbanStatus || 'unassigned';
|
||||
if (columns[status]) {
|
||||
columns[status].tasks.push(task);
|
||||
}
|
||||
});
|
||||
|
||||
// Рендерим доску
|
||||
container.innerHTML = `
|
||||
<div class="kanban-controls">
|
||||
<div class="kanban-period">
|
||||
<label>Период просмотра:</label>
|
||||
<select id="kanban-days" onchange="loadKanbanTasks()">
|
||||
${[1, 2, 3, 4, 5, 6, 7, 14].map(days =>
|
||||
`<option value="${days}" ${days === kanbanDays ? 'selected' : ''}>${days} ${getDayWord(days)}</option>`
|
||||
).join('')}
|
||||
</select>
|
||||
</div>
|
||||
<div class="kanban-stats">
|
||||
<span>Всего задач: ${kanbanTasks.length}</span>
|
||||
<button onclick="loadKanbanTasks()" class="refresh-btn">🔄 Обновить</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="kanban-columns">
|
||||
${Object.entries(columns).map(([status, column]) => `
|
||||
<div class="kanban-column" data-status="${status}">
|
||||
<div class="kanban-column-header" style="background: ${column.color}">
|
||||
<h3>${column.title}</h3>
|
||||
<span class="kanban-count">${column.tasks.length}</span>
|
||||
</div>
|
||||
<div class="kanban-column-body" id="kanban-column-${status}">
|
||||
${renderKanbanCards(column.tasks)}
|
||||
</div>
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Делаем колонки перетаскиваемыми
|
||||
makeKanbanDraggable();
|
||||
}
|
||||
function renderKanbanCards(tasks, filter) {
|
||||
if (tasks.length === 0) {
|
||||
return '<div class="kanban-empty">Нет задач</div>';
|
||||
}
|
||||
|
||||
return tasks.map(task => {
|
||||
// Определяем иконку роли
|
||||
let roleIcon = '';
|
||||
let roleTitle = '';
|
||||
|
||||
if (task.userRole === 'creator') {
|
||||
roleIcon = '👤';
|
||||
roleTitle = 'Вы поставили эту задачу';
|
||||
} else if (task.userRole === 'assignee') {
|
||||
roleIcon = '🎯';
|
||||
roleTitle = 'Вам поставили эту задачу';
|
||||
}
|
||||
|
||||
// Исправление: безопасное получение имени пользователя
|
||||
const userName = task.assignments && task.assignments.length > 0 && task.assignments[0]?.user_name
|
||||
? task.assignments[0].user_name
|
||||
: 'Неизвестно';
|
||||
|
||||
// Исправление: безопасное получение первого символа имени
|
||||
const userInitial = userName && userName.length > 0 ? userName.charAt(0) : '?';
|
||||
|
||||
return `
|
||||
<div class="kanban-card" draggable="true" data-task-id="${task.id}">
|
||||
<div class="kanban-card-header">
|
||||
<div class="kanban-task-id">#${task.id}</div>
|
||||
<div class="kanban-task-role" title="${roleTitle}">${roleIcon}</div>
|
||||
<div class="kanban-task-actions">
|
||||
<button onclick="openKanbanTask(${task.id})" title="Открыть">👁️</button>
|
||||
<button onclick="copyKanbanTask(${task.id})" title="Копировать">📋</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="kanban-task-title" onclick="openKanbanTask(${task.id})">
|
||||
${task.title || 'Без названия'}
|
||||
</div>
|
||||
<div class="kanban-task-info">
|
||||
<div class="kanban-deadline">
|
||||
${task.due_date ? `<span class="kanban-date">📅 ${formatDate(task.due_date)}</span>` : '<span class="kanban-no-date">Без срока</span>'}
|
||||
</div>
|
||||
<div class="kanban-assignees">
|
||||
${task.assignments && task.assignments.length > 0 ?
|
||||
task.assignments.slice(0, 3).map(a => {
|
||||
// Исправление: безопасное получение имени исполнителя
|
||||
const assigneeName = a.user_name || 'Неизвестно';
|
||||
const assigneeInitial = assigneeName && assigneeName.length > 0 ? assigneeName.charAt(0) : '?';
|
||||
return `<span class="kanban-assignee" title="${assigneeName}">${assigneeInitial}</span>`;
|
||||
}).join('') :
|
||||
'<span class="kanban-no-assignee">👤</span>'
|
||||
}
|
||||
${task.assignments && task.assignments.length > 3 ?
|
||||
`<span class="kanban-more-assignees">+${task.assignments.length - 3}</span>` : ''
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="kanban-task-footer">
|
||||
<span class="kanban-creator">👤 ${task.creator_name || 'Неизвестно'}</span>
|
||||
${task.files && task.files.length > 0 ?
|
||||
`<span class="kanban-files">📎 ${task.files.length}</span>` : ''
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
function renderKanban(filter = 'all') {
|
||||
const container = document.getElementById('kanban-board');
|
||||
|
||||
// Группируем задачи по статусам (убрали 'unassigned')
|
||||
const columns = {
|
||||
'assigned': { title: 'Назначены', tasks: [], color: '#e74c3c' },
|
||||
'in_progress': { title: 'В работе', tasks: [], color: '#f39c12' },
|
||||
'rework': { title: 'На доработке', tasks: [], color: '#f1c40f' },
|
||||
'overdue': { title: 'Просрочены', tasks: [], color: '#c0392b' },
|
||||
'completed': { title: 'Выполнены', tasks: [], color: '#2ecc71' }
|
||||
};
|
||||
|
||||
// Распределяем задачи по колонкам
|
||||
kanbanTasks.forEach(task => {
|
||||
const status = task.kanbanStatus || 'assigned';
|
||||
// Преобразуем 'unassigned' в 'assigned'
|
||||
const actualStatus = status === 'unassigned' ? 'assigned' : status;
|
||||
|
||||
if (columns[actualStatus]) {
|
||||
columns[actualStatus].tasks.push(task);
|
||||
} else {
|
||||
// Если статус не найден, добавляем в 'assigned'
|
||||
columns['assigned'].tasks.push(task);
|
||||
}
|
||||
});
|
||||
|
||||
// Статистика по фильтру
|
||||
let filterTitle = 'Все задачи';
|
||||
if (filter === 'created') filterTitle = 'Задачи, которые я поставил';
|
||||
if (filter === 'assigned') filterTitle = 'Задачи, которые мне поставили';
|
||||
|
||||
container.innerHTML = `
|
||||
<div class="kanban-controls">
|
||||
<div class="kanban-filters">
|
||||
<div class="kanban-period">
|
||||
<label>Период просмотра:</label>
|
||||
<select id="kanban-days" onchange="loadKanbanTasks()">
|
||||
${[1, 2, 3, 4, 5, 6, 7, 14, 30, 62].map(days =>
|
||||
`<option value="${days}" ${days === kanbanDays ? 'selected' : ''}>${days} ${getDayWord(days)}</option>`
|
||||
).join('')}
|
||||
</select>
|
||||
</div>
|
||||
<div class="kanban-filter-type">
|
||||
<label>Показать:</label>
|
||||
<select id="kanban-filter" onchange="loadKanbanTasks()">
|
||||
<option value="all" ${filter === 'all' ? 'selected' : ''}>Все задачи</option>
|
||||
<option value="created" ${filter === 'created' ? 'selected' : ''}>Я поставил</option>
|
||||
<option value="assigned" ${filter === 'assigned' ? 'selected' : ''}>Мне поставили</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="kanban-stats">
|
||||
<span class="filter-title">${filterTitle}</span>
|
||||
<span class="task-count">Всего задач: ${kanbanTasks.length}</span>
|
||||
<button onclick="loadKanbanTasks()" class="refresh-btn">🔄 Обновить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="kanban-columns">
|
||||
${Object.entries(columns).map(([status, column]) => `
|
||||
<div class="kanban-column" data-status="${status}" ${status === 'overdue' || status === 'assigned' ? 'ondragover="return false" ondrop="return false"' : ''}>
|
||||
<div class="kanban-column-header" style="background: ${column.color}">
|
||||
<h3>${column.title}</h3>
|
||||
<span class="kanban-count">${column.tasks.length}</span>
|
||||
</div>
|
||||
<div class="kanban-column-body" id="kanban-column-${status}"
|
||||
${status === 'overdue' || status === 'assigned' ? 'style="opacity: 0.6; cursor: not-allowed;"' : ''}>
|
||||
${renderKanbanCards(column.tasks, filter)}
|
||||
</div>
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Делаем колонки перетаскиваемыми (кроме 'overdue' и 'assigned')
|
||||
makeKanbanDraggable();
|
||||
}
|
||||
|
||||
function getDayWord(days) {
|
||||
if (days === 1) return 'день';
|
||||
if (days >= 2 && days <= 4) return 'дня';
|
||||
return 'дней';
|
||||
}
|
||||
|
||||
function makeKanbanDraggable() {
|
||||
const cards = document.querySelectorAll('.kanban-card');
|
||||
const columns = document.querySelectorAll('.kanban-column-body:not([style*="opacity: 0.6"])');
|
||||
|
||||
cards.forEach(card => {
|
||||
card.addEventListener('dragstart', (e) => {
|
||||
e.dataTransfer.setData('text/plain', card.dataset.taskId);
|
||||
card.classList.add('dragging');
|
||||
});
|
||||
|
||||
card.addEventListener('dragend', () => {
|
||||
card.classList.remove('dragging');
|
||||
});
|
||||
});
|
||||
|
||||
columns.forEach(column => {
|
||||
const status = column.parentElement.dataset.status;
|
||||
|
||||
// Запрещаем перетаскивание в 'overdue' и 'assigned'
|
||||
if (status === 'overdue' || status === 'assigned') {
|
||||
return;
|
||||
}
|
||||
|
||||
column.addEventListener('dragover', (e) => {
|
||||
e.preventDefault();
|
||||
const draggingCard = document.querySelector('.dragging');
|
||||
if (draggingCard) {
|
||||
column.appendChild(draggingCard);
|
||||
}
|
||||
});
|
||||
|
||||
column.addEventListener('drop', async (e) => {
|
||||
e.preventDefault();
|
||||
const taskId = e.dataTransfer.getData('text/plain');
|
||||
const newStatus = column.parentElement.dataset.status;
|
||||
|
||||
if (taskId) {
|
||||
try {
|
||||
// Запрещаем установку статуса 'overdue' и 'assigned'
|
||||
if (newStatus === 'overdue' || newStatus === 'assigned') {
|
||||
alert('Невозможно изменить статус задачи на "Просрочены" или "Назначены" через Канбан');
|
||||
// Возвращаем задачу в исходное положение
|
||||
loadKanbanTasks();
|
||||
return;
|
||||
}
|
||||
|
||||
// Обновляем статус на сервере
|
||||
const response = await fetch(`/api/kanban-tasks/${taskId}/status`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ status: newStatus })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
// Перезагружаем Канбан
|
||||
loadKanbanTasks();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(`Ошибка обновления статуса: ${error.error || 'Неизвестная ошибка'}`);
|
||||
// Возвращаем задачу в исходное положение
|
||||
loadKanbanTasks();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка обновления статуса:', error);
|
||||
alert('Ошибка обновления статуса');
|
||||
loadKanbanTasks();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function openKanbanTask(taskId) {
|
||||
// Находим задачу и открываем её в основном интерфейсе
|
||||
const task = kanbanTasks.find(t => t.id == taskId);
|
||||
if (task) {
|
||||
showSection('tasks');
|
||||
// Прокручиваем к задаче
|
||||
setTimeout(() => {
|
||||
const taskElement = document.querySelector(`.task-card[data-task-id="${taskId}"]`);
|
||||
if (taskElement) {
|
||||
taskElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
// Раскрываем задачу если она свернута
|
||||
if (!expandedTasks.has(taskId)) {
|
||||
toggleTask(taskId);
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
||||
function copyKanbanTask(taskId) {
|
||||
openCopyModal(taskId);
|
||||
}
|
||||
|
||||
function formatDate(dateString) {
|
||||
if (!dateString) return '';
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('ru-RU');
|
||||
}
|
||||
function filterUsers() {
|
||||
const search = document.getElementById('user-search').value.toLowerCase();
|
||||
filteredUsers = users.filter(user =>
|
||||
@@ -1081,7 +1437,18 @@ function getUserRoleInTask(task) {
|
||||
if (!currentUser) return 'Нет доступа';
|
||||
|
||||
if (currentUser.role === 'admin') return 'Администратор';
|
||||
if (parseInt(task.created_by) === currentUser.id) return 'Заказчик';
|
||||
|
||||
if (parseInt(task.created_by) === currentUser.id) {
|
||||
if (task.assignments && task.assignments.length > 0) {
|
||||
const assignedToOthers = task.assignments.some(assignment =>
|
||||
parseInt(assignment.user_id) !== currentUser.id
|
||||
);
|
||||
if (assignedToOthers) {
|
||||
return 'Создатель (только просмотр)';
|
||||
}
|
||||
}
|
||||
return 'Создатель';
|
||||
}
|
||||
|
||||
if (task.assignments) {
|
||||
const isExecutor = task.assignments.some(assignment =>
|
||||
@@ -1105,8 +1472,37 @@ function getRoleBadgeClass(role) {
|
||||
function canUserEditTask(task) {
|
||||
if (!currentUser) return false;
|
||||
|
||||
// Администратор может всё
|
||||
if (currentUser.role === 'admin') return true;
|
||||
if (parseInt(task.created_by) === currentUser.id) return true;
|
||||
|
||||
// Создатель может редактировать свою задачу
|
||||
if (parseInt(task.created_by) === currentUser.id) {
|
||||
// Но если задача уже назначена другим пользователям,
|
||||
// создатель может только просматривать
|
||||
if (task.assignments && task.assignments.length > 0) {
|
||||
// Проверяем, назначена ли задача другим пользователям (не только себе)
|
||||
const assignedToOthers = task.assignments.some(assignment =>
|
||||
parseInt(assignment.user_id) !== currentUser.id
|
||||
);
|
||||
|
||||
if (assignedToOthers) {
|
||||
// Создатель может только просматривать и закрывать задачу
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Исполнитель может менять только свой статус
|
||||
if (task.assignments) {
|
||||
const isExecutor = task.assignments.some(assignment =>
|
||||
parseInt(assignment.user_id) === currentUser.id
|
||||
);
|
||||
if (isExecutor) {
|
||||
// Исполнитель может менять только статус
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
389
public/style.css
389
public/style.css
@@ -1822,4 +1822,393 @@ button.reopen-btn:hover {
|
||||
|
||||
.assignment:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
/* Добавить в стили */
|
||||
.kanban-section {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.kanban-board {
|
||||
background: #f5f5f5;
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
min-height: 70vh;
|
||||
}
|
||||
|
||||
.kanban-controls {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
padding: 15px;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.kanban-period {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.kanban-period label {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.kanban-period select {
|
||||
padding: 8px 15px;
|
||||
border: 2px solid #3498db;
|
||||
border-radius: 5px;
|
||||
background: white;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.kanban-stats {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.kanban-stats span {
|
||||
font-weight: bold;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
.refresh-btn {
|
||||
padding: 8px 15px;
|
||||
background: #3498db;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.refresh-btn:hover {
|
||||
background: #2980b9;
|
||||
}
|
||||
|
||||
.kanban-columns {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: 20px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.kanban-column {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
||||
min-height: 500px;
|
||||
}
|
||||
|
||||
.kanban-column-header {
|
||||
padding: 15px;
|
||||
color: white;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.kanban-column-header h3 {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.kanban-count {
|
||||
background: rgba(255,255,255,0.3);
|
||||
padding: 3px 10px;
|
||||
border-radius: 20px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.kanban-column-body {
|
||||
padding: 15px;
|
||||
min-height: 450px;
|
||||
max-height: 600px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.kanban-empty {
|
||||
text-align: center;
|
||||
padding: 40px 20px;
|
||||
color: #95a5a6;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.kanban-card {
|
||||
background: white;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 6px;
|
||||
padding: 15px;
|
||||
margin-bottom: 15px;
|
||||
cursor: move;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
.kanban-card:hover {
|
||||
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
||||
transform: translateY(-2px);
|
||||
border-color: #3498db;
|
||||
}
|
||||
|
||||
.kanban-card.dragging {
|
||||
opacity: 0.5;
|
||||
transform: rotate(5deg);
|
||||
}
|
||||
|
||||
.kanban-card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.kanban-task-id {
|
||||
font-size: 12px;
|
||||
color: #7f8c8d;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.kanban-task-actions {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.kanban-task-actions button {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.kanban-task-actions button:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.kanban-task-title {
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
cursor: pointer;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
.kanban-task-title:hover {
|
||||
color: #3498db;
|
||||
}
|
||||
|
||||
.kanban-task-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.kanban-deadline {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.kanban-date {
|
||||
color: #e74c3c;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.kanban-no-date {
|
||||
color: #95a5a6;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.kanban-assignees {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.kanban-assignee {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 50%;
|
||||
background: #3498db;
|
||||
color: white;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 10px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.kanban-no-assignee {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.kanban-more-assignees {
|
||||
font-size: 10px;
|
||||
color: #7f8c8d;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.kanban-task-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 11px;
|
||||
color: #7f8c8d;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
padding-top: 8px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.kanban-creator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.kanban-files {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
/* Адаптивность */
|
||||
@media (max-width: 1200px) {
|
||||
.kanban-columns {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.kanban-columns {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.kanban-controls {
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
align-items: stretch;
|
||||
}
|
||||
}
|
||||
.error-message {
|
||||
background: #ffebee;
|
||||
border: 1px solid #f44336;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
color: #c62828;
|
||||
margin: 20px;
|
||||
}
|
||||
|
||||
.retry-btn {
|
||||
background: #4CAF50;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
margin-top: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.retry-btn:hover {
|
||||
background: #45a049;
|
||||
}
|
||||
.kanban-filters {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 20px;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
padding: 15px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.kanban-period, .kanban-filter-type {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.kanban-period label, .kanban-filter-type label {
|
||||
font-size: 12px;
|
||||
color: #6c757d;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.kanban-period select, .kanban-filter-type select {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #dee2e6;
|
||||
border-radius: 4px;
|
||||
background: white;
|
||||
font-size: 14px;
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
.kanban-stats {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.filter-title {
|
||||
font-weight: 600;
|
||||
color: #495057;
|
||||
background: #e9ecef;
|
||||
padding: 6px 12px;
|
||||
border-radius: 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.task-count {
|
||||
color: #6c757d;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.refresh-btn {
|
||||
background: #6c757d;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 16px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.refresh-btn:hover {
|
||||
background: #5a6268;
|
||||
}
|
||||
|
||||
.kanban-task-role {
|
||||
font-size: 16px;
|
||||
cursor: help;
|
||||
margin: 0 5px;
|
||||
}
|
||||
.kanban-column[data-status="overdue"] .kanban-column-body,
|
||||
.kanban-column[data-status="assigned"] .kanban-column-body {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed !important;
|
||||
}
|
||||
|
||||
.kanban-column[data-status="overdue"] .kanban-card,
|
||||
.kanban-column[data-status="assigned"] .kanban-card {
|
||||
cursor: not-allowed !important;
|
||||
}
|
||||
|
||||
.kanban-column[data-status="overdue"] .kanban-card:hover,
|
||||
.kanban-column[data-status="assigned"] .kanban-card:hover {
|
||||
transform: none !important;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
|
||||
}
|
||||
Reference in New Issue
Block a user