250 lines
6.8 KiB
HTML
250 lines
6.8 KiB
HTML
{% extends "base.html" %}
|
||
|
||
{% block content %}
|
||
<h2>Управление пользователями</h2>
|
||
|
||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||
{% if messages %}
|
||
{% for category, message in messages %}
|
||
<div class="alert alert-{{ category }}">{{ message }}</div>
|
||
{% endfor %}
|
||
{% endif %}
|
||
{% endwith %}
|
||
|
||
<div class="filters">
|
||
<h3>Фильтры и сортировка</h3>
|
||
<div class="filter-bar">
|
||
<label>Сортировка:</label>
|
||
<select onchange="window.location.href='?sort='+this.value+'&role={{ role }}'">
|
||
<option value="newest" {% if sort == 'newest' %}selected{% endif %}>Новые сначала</option>
|
||
<option value="oldest" {% if sort == 'oldest' %}selected{% endif %}>Старые сначала</option>
|
||
<option value="name_asc" {% if sort == 'name_asc' %}selected{% endif %}>Имя (А-Я)</option>
|
||
<option value="name_desc" {% if sort == 'name_desc' %}selected{% endif %}>Имя (Я-А)</option>
|
||
</select>
|
||
|
||
<label>Роль:</label>
|
||
<select onchange="window.location.href='?sort={{ sort }}&role='+this.value">
|
||
<option value="all" {% if role == 'all' %}selected{% endif %}>Все</option>
|
||
<option value="admin" {% if role == 'admin' %}selected{% endif %}>Администраторы</option>
|
||
<option value="user" {% if role == 'user' %}selected{% endif %}>Пользователи</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="admin-table">
|
||
<table>
|
||
<thead>
|
||
<tr>
|
||
<th>ID</th>
|
||
<th>Имя пользователя</th>
|
||
<th>Email</th>
|
||
<th>Роль</th>
|
||
<th>Дата регистрации</th>
|
||
<th>Действия</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{% for user in users %}
|
||
<tr>
|
||
<td>{{ user.id }}</td>
|
||
<td><strong>{{ user.username }}</strong></td>
|
||
<td>{{ user.email or '-' }}</td>
|
||
<td>
|
||
<span class="role-badge role-{{ user.role }}">
|
||
{% if user.role == 'admin' %}👑 Администратор
|
||
{% else %}👤 Пользователь
|
||
{% endif %}
|
||
</span>
|
||
</td>
|
||
<td>{{ user.created_at[:16] }}</td>
|
||
<td>
|
||
{% if user.role != 'admin' %}
|
||
<form method="POST" action="{{ url_for('make_admin', user_id=user.id) }}?sort={{ sort }}&role={{ role }}" style="display: inline;">
|
||
<button type="submit" class="btn btn-warning btn-sm">👑 Сделать админом</button>
|
||
</form>
|
||
{% endif %}
|
||
<form method="POST" action="{{ url_for('delete_user', user_id=user.id) }}?sort={{ sort }}&role={{ role }}" style="display: inline;" onsubmit="return confirm('Удалить пользователя {{ user.username }}? Все его заказы и отзывы также будут удалены.')">
|
||
<button type="submit" class="btn btn-danger btn-sm">🗑️ Удалить</button>
|
||
</form>
|
||
</td>
|
||
</tr>
|
||
{% endfor %}
|
||
</tbody>
|
||
</table>
|
||
|
||
{% if not users %}
|
||
<div class="empty-state">
|
||
<p>Нет пользователей для отображения</p>
|
||
</div>
|
||
{% endif %}
|
||
</div>
|
||
|
||
<style>
|
||
.filters {
|
||
background: white;
|
||
padding: 1rem;
|
||
margin-bottom: 1rem;
|
||
border-radius: 8px;
|
||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||
}
|
||
|
||
.filters h3 {
|
||
margin-top: 0;
|
||
margin-bottom: 1rem;
|
||
color: #4a2c2c;
|
||
font-size: 1.2rem;
|
||
}
|
||
|
||
.filter-bar {
|
||
display: flex;
|
||
gap: 1.5rem;
|
||
flex-wrap: wrap;
|
||
align-items: center;
|
||
}
|
||
|
||
.filter-bar label {
|
||
font-weight: bold;
|
||
color: #4a2c2c;
|
||
}
|
||
|
||
.filter-bar select {
|
||
padding: 0.5rem;
|
||
border: 1px solid #ddd;
|
||
border-radius: 4px;
|
||
font-size: 0.9rem;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.admin-table {
|
||
overflow-x: auto;
|
||
background: white;
|
||
border-radius: 8px;
|
||
padding: 1rem;
|
||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||
}
|
||
|
||
.admin-table table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
}
|
||
|
||
.admin-table th,
|
||
.admin-table td {
|
||
padding: 0.75rem;
|
||
text-align: left;
|
||
border-bottom: 1px solid #ddd;
|
||
}
|
||
|
||
.admin-table th {
|
||
background-color: #4a2c2c;
|
||
color: white;
|
||
font-weight: bold;
|
||
}
|
||
|
||
.admin-table tr:hover {
|
||
background-color: #f5f5f5;
|
||
}
|
||
|
||
.role-badge {
|
||
display: inline-block;
|
||
padding: 0.25rem 0.5rem;
|
||
border-radius: 4px;
|
||
font-size: 0.85rem;
|
||
font-weight: bold;
|
||
}
|
||
|
||
.role-admin {
|
||
background-color: #dc3545;
|
||
color: white;
|
||
}
|
||
|
||
.role-user {
|
||
background-color: #28a745;
|
||
color: white;
|
||
}
|
||
|
||
.btn-sm {
|
||
padding: 0.25rem 0.5rem;
|
||
font-size: 0.85rem;
|
||
display: inline-block;
|
||
margin: 0.25rem;
|
||
text-decoration: none;
|
||
border: none;
|
||
border-radius: 4px;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.btn-warning {
|
||
background-color: #ffc107;
|
||
color: #333;
|
||
}
|
||
|
||
.btn-warning:hover {
|
||
background-color: #e0a800;
|
||
}
|
||
|
||
.btn-danger {
|
||
background-color: #dc3545;
|
||
color: white;
|
||
}
|
||
|
||
.btn-danger:hover {
|
||
background-color: #c82333;
|
||
}
|
||
|
||
.empty-state {
|
||
text-align: center;
|
||
padding: 3rem;
|
||
color: #666;
|
||
}
|
||
|
||
.alert {
|
||
padding: 0.75rem;
|
||
margin-bottom: 1rem;
|
||
border-radius: 4px;
|
||
}
|
||
|
||
.alert-success {
|
||
background-color: #d4edda;
|
||
color: #155724;
|
||
border: 1px solid #c3e6cb;
|
||
}
|
||
|
||
.alert-danger {
|
||
background-color: #f8d7da;
|
||
color: #721c24;
|
||
border: 1px solid #f5c6cb;
|
||
}
|
||
|
||
.alert-warning {
|
||
background-color: #fff3cd;
|
||
color: #856404;
|
||
border: 1px solid #ffeeba;
|
||
}
|
||
|
||
@media (max-width: 768px) {
|
||
.filter-bar {
|
||
flex-direction: column;
|
||
align-items: flex-start;
|
||
gap: 0.5rem;
|
||
}
|
||
|
||
.filter-bar select {
|
||
width: 100%;
|
||
}
|
||
|
||
.admin-table th,
|
||
.admin-table td {
|
||
padding: 0.5rem;
|
||
font-size: 0.85rem;
|
||
}
|
||
|
||
.btn-sm {
|
||
display: block;
|
||
width: 100%;
|
||
margin: 0.25rem 0;
|
||
}
|
||
}
|
||
</style>
|
||
{% endblock %}
|