upload files
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>
|
||||
@@ -427,10 +427,10 @@ function renderTasks() {
|
||||
|
||||
<div class="task-assignments">
|
||||
<strong>Исполнители:</strong>
|
||||
${task.assignments && task.assignments.length > 0 ?
|
||||
task.assignments.map(assignment => renderAssignment(assignment, task.id, canEdit)).join('') :
|
||||
'<div>Не назначены</div>'
|
||||
}
|
||||
${task.assignments && task.assignments.length > 0 ?
|
||||
renderAssignmentList(task.assignments, task.id, canEdit) :
|
||||
'<div>Не назначены</div>'
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="task-meta">
|
||||
@@ -443,7 +443,61 @@ function renderTasks() {
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
function renderAssignmentList(assignments, taskId, canEdit) {
|
||||
if (!assignments || assignments.length === 0) {
|
||||
return '<div>Не назначены</div>';
|
||||
}
|
||||
|
||||
// Создаем контейнер с возможностью фильтрации
|
||||
return `
|
||||
<div class="assignments-container">
|
||||
<div class="assignments-filter">
|
||||
<input type="text"
|
||||
class="assignment-filter-input"
|
||||
placeholder="Поиск исполнителя..."
|
||||
data-task-id="${taskId}"
|
||||
oninput="filterAssignments(${taskId})">
|
||||
<span class="filter-count" id="filter-count-${taskId}">${assignments.length} исполнителей</span>
|
||||
</div>
|
||||
<div class="assignments-scroll-container" id="assignments-${taskId}">
|
||||
${assignments.map(assignment => renderAssignment(assignment, taskId, canEdit)).join('')}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// Функция для фильтрации исполнителей в конкретной задаче
|
||||
function filterAssignments(taskId) {
|
||||
const filterInput = document.querySelector(`.assignment-filter-input[data-task-id="${taskId}"]`);
|
||||
const scrollContainer = document.getElementById(`assignments-${taskId}`);
|
||||
const filterCount = document.getElementById(`filter-count-${taskId}`);
|
||||
|
||||
if (!filterInput || !scrollContainer) return;
|
||||
|
||||
const searchTerm = filterInput.value.toLowerCase();
|
||||
const assignments = scrollContainer.querySelectorAll('.assignment');
|
||||
|
||||
let visibleCount = 0;
|
||||
|
||||
assignments.forEach(assignment => {
|
||||
const userName = assignment.querySelector('strong')?.textContent?.toLowerCase() || '';
|
||||
const userLogin = assignment.querySelector('small')?.textContent?.toLowerCase() || '';
|
||||
|
||||
const isVisible = userName.includes(searchTerm) ||
|
||||
userLogin.includes(searchTerm) ||
|
||||
searchTerm === '';
|
||||
|
||||
assignment.style.display = isVisible ? '' : 'none';
|
||||
|
||||
if (isVisible) {
|
||||
visibleCount++;
|
||||
}
|
||||
});
|
||||
|
||||
if (filterCount) {
|
||||
filterCount.textContent = `${visibleCount} из ${assignments.length} исполнителей`;
|
||||
}
|
||||
}
|
||||
function toggleTask(taskId) {
|
||||
if (expandedTasks.has(taskId)) {
|
||||
expandedTasks.delete(taskId);
|
||||
|
||||
@@ -1734,4 +1734,92 @@ button.reopen-btn:hover {
|
||||
.file-name {
|
||||
font-size: 0.65rem;
|
||||
}
|
||||
}
|
||||
/* Добавьте эти стили в style.css */
|
||||
|
||||
.assignments-container {
|
||||
margin-top: 10px;
|
||||
border: 1px solid #e1e5e9;
|
||||
border-radius: 8px;
|
||||
padding: 10px;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.assignments-filter {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 10px;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 1px solid #e1e5e9;
|
||||
}
|
||||
|
||||
.assignment-filter-input {
|
||||
flex: 1;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.assignment-filter-input:focus {
|
||||
outline: none;
|
||||
border-color: #3498db;
|
||||
box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
|
||||
}
|
||||
|
||||
.filter-count {
|
||||
font-size: 12px;
|
||||
color: #6c757d;
|
||||
background: #e9ecef;
|
||||
padding: 2px 8px;
|
||||
border-radius: 12px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.assignments-scroll-container {
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
/* Стили для скроллбара */
|
||||
.assignments-scroll-container::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
|
||||
.assignments-scroll-container::-webkit-scrollbar-track {
|
||||
background: #f1f1f1;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.assignments-scroll-container::-webkit-scrollbar-thumb {
|
||||
background: #c1c1c1;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.assignments-scroll-container::-webkit-scrollbar-thumb:hover {
|
||||
background: #a8a8a8;
|
||||
}
|
||||
|
||||
/* Стили для отдельных исполнителей */
|
||||
.assignment {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
padding: 8px;
|
||||
margin-bottom: 8px;
|
||||
background: white;
|
||||
border: 1px solid #e9ecef;
|
||||
border-radius: 6px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.assignment:hover {
|
||||
background: #f8f9fa;
|
||||
border-color: #dee2e6;
|
||||
}
|
||||
|
||||
.assignment:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
Reference in New Issue
Block a user