Files
oldmarketcustomserver/templates/reviews.html
drel 9eca006d8a succ
succ
2025-10-18 03:11:05 +03:00

305 lines
9.8 KiB
HTML

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Управление отзывами - OldMarket Admin</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background: #f5f5f5;
}
.sidebar {
width: 250px;
background: #2c3e50;
color: white;
height: 100vh;
position: fixed;
padding: 20px;
}
.sidebar h2 {
margin-bottom: 30px;
text-align: center;
}
.sidebar .user-info {
background: #34495e;
padding: 10px;
border-radius: 5px;
margin-bottom: 20px;
text-align: center;
}
.sidebar ul {
list-style: none;
}
.sidebar li {
margin: 15px 0;
}
.sidebar a {
color: white;
text-decoration: none;
padding: 10px;
display: block;
border-radius: 5px;
transition: background 0.3s;
}
.sidebar a:hover {
background: #34495e;
}
.content {
margin-left: 250px;
padding: 40px;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
}
.btn {
background: #3498db;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
text-decoration: none;
display: inline-block;
}
.btn:hover {
background: #2980b9;
}
.btn-danger {
background: #e74c3c;
}
.btn-danger:hover {
background: #c0392b;
}
.btn-success {
background: #27ae60;
}
.btn-success:hover {
background: #219a52;
}
table {
width: 100%;
background: white;
border-collapse: collapse;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background: #34495e;
color: white;
}
tr:hover {
background: #f5f5f5;
}
.rating {
color: #f39c12;
font-weight: bold;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.5);
z-index: 1000;
}
.modal-content {
background: white;
margin: 50px auto;
padding: 30px;
width: 80%;
max-width: 600px;
border-radius: 10px;
max-height: 80vh;
overflow-y: auto;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input, textarea, select {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
.comment-preview {
max-height: 60px;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<div class="sidebar">
<h2>OldMarket Admin</h2>
<div class="user-info">
Вы вошли как: <strong>{{ username }}</strong>
</div>
<ul>
<li><a href="/admin">Дашборд</a></li>
<li><a href="/admin/apps">Управление приложениями</a></li>
<li><a href="/admin/reviews">Управление отзывами</a></li>
<li><a href="/api/apps" target="_blank">API приложений</a></li>
<li><a href="/admin/logout">Выйти</a></li>
</ul>
</div>
<div class="content">
<div class="header">
<h1>Управление отзывами</h1>
<button class="btn" onclick="showAddReviewForm()">Добавить отзыв</button>
</div>
<table>
<thead>
<tr>
<th>ID</th>
<th>Пользователь</th>
<th>Приложение</th>
<th>Рейтинг</th>
<th>Комментарий</th>
<th>Дата</th>
<th>Действия</th>
</tr>
</thead>
<tbody>
{% for review in reviews %}
<tr>
<td>{{ review.id }}</td>
<td>{{ review.username }}</td>
<td>
{% if app_names[review.app_id] %}
{{ app_names[review.app_id] }} (ID: {{ review.app_id }})
{% else %}
ID: {{ review.app_id }}
{% endif %}
</td>
<td class="rating">{{ '★' * review.rating }}{{ '☆' * (5 - review.rating) }}</td>
<td class="comment-preview" title="{{ review.comment }}">
{{ review.comment[:50] }}{% if review.comment|length > 50 %}...{% endif %}
</td>
<td>{{ review.created_at }}</td>
<td>
<button class="btn btn-danger" onclick="deleteReview({{ review.id }})">Удалить</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Модальное окно для добавления отзыва -->
<div id="addReviewModal" class="modal">
<div class="modal-content">
<h2>Добавить отзыв</h2>
<form id="addReviewForm" enctype="multipart/form-data">
<div class="form-group">
<label>Приложение:</label>
<select name="app_id" required>
<option value="">Выберите приложение</option>
{% for app in apps %}
<option value="{{ app.id }}">{{ app.name }} (ID: {{ app.id }})</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label>Имя пользователя:</label>
<input type="text" name="username" required>
</div>
<div class="form-group">
<label>Рейтинг (1-5):</label>
<select name="rating" required>
<option value="5">★★★★★ (5)</option>
<option value="4">★★★★☆ (4)</option>
<option value="3">★★★☆☆ (3)</option>
<option value="2">★★☆☆☆ (2)</option>
<option value="1">★☆☆☆☆ (1)</option>
</select>
</div>
<div class="form-group">
<label>Комментарий:</label>
<textarea name="comment" rows="4"></textarea>
</div>
<div class="form-group">
<label>Аватар (опционально):</label>
<input type="file" name="avatar" accept="image/*">
</div>
<div class="form-group">
<button type="submit" class="btn">Добавить отзыв</button>
<button type="button" class="btn" onclick="hideAddReviewForm()">Отмена</button>
</div>
</form>
</div>
</div>
<script>
function showAddReviewForm() {
document.getElementById('addReviewModal').style.display = 'block';
}
function hideAddReviewForm() {
document.getElementById('addReviewModal').style.display = 'none';
}
async function deleteReview(reviewId) {
if (confirm('Вы уверены, что хотите удалить этот отзыв?')) {
try {
const response = await fetch(`/api/admin/reviews/${reviewId}`, {
method: 'DELETE'
});
const result = await response.json();
alert(result.message);
location.reload();
} catch (error) {
alert('Ошибка при удалении: ' + error);
}
}
}
document.getElementById('addReviewForm').addEventListener('submit', async function(e) {
e.preventDefault();
const formData = new FormData(this);
try {
const response = await fetch('/api/admin/reviews', {
method: 'POST',
body: formData
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.detail || 'Ошибка сервера');
}
const result = await response.json();
alert(result.message);
hideAddReviewForm();
location.reload();
} catch (error) {
console.error('Error:', error);
alert('Ошибка при добавлении: ' + error.message);
}
});
</script>
</body>
</html>