chore: initial commit — CS2 Simulator

This commit is contained in:
2026-07-05 10:40:00 +00:00
commit c268557997
40 changed files with 824236 additions and 0 deletions
+361
View File
@@ -0,0 +1,361 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}Админ-панель{% endblock %} — CS2 Simulator</title>
<link rel="stylesheet" href="/static/css/style.css">
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
background: #0b0c10;
color: #e8e8e8;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
min-height: 100vh;
display: flex;
}
/* ─── Sidebar ─── */
.admin-sidebar {
width: 240px;
min-height: 100vh;
background: linear-gradient(180deg, #111216 0%, #0d0e12 100%);
border-right: 1px solid rgba(255,255,255,0.04);
display: flex;
flex-direction: column;
position: sticky; top: 0; height: 100vh;
flex-shrink: 0;
}
.admin-sidebar .sb-brand {
padding: 1.25rem 1.25rem 0.75rem;
font-size: 1rem;
font-weight: 700;
letter-spacing: 0.02em;
display: flex; align-items: center; gap: 0.5rem;
border-bottom: 1px solid rgba(255,255,255,0.04);
}
.admin-sidebar .sb-brand span { color: #f59e0b; }
.admin-sidebar .sb-nav {
flex: 1; padding: 0.75rem 0;
display: flex; flex-direction: column; gap: 0.15rem;
}
.admin-sidebar .sb-nav a {
display: flex; align-items: center; gap: 0.65rem;
padding: 0.65rem 1.25rem;
font-size: 0.85rem;
color: rgba(255,255,255,0.55);
text-decoration: none;
transition: all 0.15s;
border-left: 2px solid transparent;
font-weight: 450;
}
.admin-sidebar .sb-nav a:hover {
color: rgba(255,255,255,0.85);
background: rgba(255,255,255,0.03);
}
.admin-sidebar .sb-nav a.active {
color: #f59e0b;
background: rgba(245,158,11,0.06);
border-left-color: #f59e0b;
}
.admin-sidebar .sb-nav a .sb-icon { font-size: 1rem; width: 20px; text-align: center; }
.admin-sidebar .sb-footer {
padding: 0.75rem 1.25rem;
border-top: 1px solid rgba(255,255,255,0.04);
font-size: 0.75rem;
color: rgba(255,255,255,0.3);
}
.admin-sidebar .sb-footer a {
color: rgba(255,255,255,0.5);
text-decoration: none;
display: flex; align-items: center; gap: 0.4rem;
}
.admin-sidebar .sb-footer a:hover { color: #f59e0b; }
/* ─── Main area ─── */
.admin-main {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
}
.admin-topbar {
display: flex; align-items: center; justify-content: space-between;
padding: 0.85rem 1.5rem;
background: rgba(17,18,22,0.8);
backdrop-filter: blur(8px);
border-bottom: 1px solid rgba(255,255,255,0.04);
position: sticky; top: 0; z-index: 10;
}
.admin-topbar .at-title {
font-size: 1rem; font-weight: 600;
display: flex; align-items: center; gap: 0.5rem;
}
.admin-topbar .at-title .at-sub {
font-size: 0.75rem; color: rgba(255,255,255,0.35);
font-weight: 400;
}
.admin-topbar .at-actions { display: flex; align-items: center; gap: 0.75rem; }
.admin-topbar .at-actions .at-back {
color: rgba(255,255,255,0.5); text-decoration: none;
font-size: 0.8rem; display: flex; align-items: center; gap: 0.3rem;
transition: color 0.15s;
}
.admin-topbar .at-actions .at-back:hover { color: #f59e0b; }
.admin-topbar .at-actions .at-user {
color: rgba(255,255,255,0.5); font-size: 0.8rem;
display: flex; align-items: center; gap: 0.3rem;
}
.admin-content {
flex: 1;
padding: 1.5rem;
overflow-y: auto;
}
/* ─── Cards ─── */
.a-card {
background: rgba(17,18,22,0.6);
border: 1px solid rgba(255,255,255,0.05);
border-radius: 12px;
padding: 1.25rem;
margin-bottom: 1.25rem;
}
.a-card-header {
display: flex; align-items: center; justify-content: space-between;
margin-bottom: 1rem;
font-size: 0.85rem; font-weight: 600;
color: rgba(255,255,255,0.7);
}
/* ─── Stats grid ─── */
.a-stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
gap: 1rem;
margin-bottom: 1.5rem;
}
.a-stat {
background: rgba(17,18,22,0.6);
border: 1px solid rgba(255,255,255,0.05);
border-radius: 12px;
padding: 1.25rem;
display: flex; flex-direction: column; gap: 0.25rem;
position: relative; overflow: hidden;
}
.a-stat .as-label {
font-size: 0.7rem; text-transform: uppercase;
letter-spacing: 0.06em;
color: rgba(255,255,255,0.35);
}
.a-stat .as-value {
font-size: 1.8rem; font-weight: 700;
line-height: 1.1;
}
.a-stat .as-bar {
position: absolute; bottom: 0; left: 0; height: 2px;
border-radius: 0 2px 0 0;
transition: width 0.6s ease;
}
.a-stat .as-sub {
font-size: 0.75rem; color: rgba(255,255,255,0.35);
}
/* ─── Tables ─── */
.a-table-wrap {
overflow-x: auto;
border: 1px solid rgba(255,255,255,0.05);
border-radius: 10px;
}
.a-table {
width: 100%;
border-collapse: collapse;
font-size: 0.82rem;
}
.a-table th {
text-align: left;
padding: 0.7rem 0.9rem;
font-weight: 600;
font-size: 0.7rem;
text-transform: uppercase;
letter-spacing: 0.05em;
color: rgba(255,255,255,0.35);
background: rgba(0,0,0,0.2);
border-bottom: 1px solid rgba(255,255,255,0.04);
}
.a-table td {
padding: 0.65rem 0.9rem;
border-bottom: 1px solid rgba(255,255,255,0.03);
vertical-align: middle;
}
.a-table tr:last-child td { border-bottom: none; }
.a-table tr:hover td { background: rgba(255,255,255,0.02); }
.a-table .td-actions {
display: flex; gap: 0.35rem;
flex-wrap: wrap;
}
/* ─── Buttons ─── */
.a-btn {
display: inline-flex; align-items: center; gap: 0.35rem;
padding: 0.45rem 0.9rem;
border: 1px solid rgba(255,255,255,0.08);
border-radius: 7px;
font-size: 0.78rem;
font-weight: 500;
cursor: pointer;
transition: all 0.15s;
background: rgba(255,255,255,0.04);
color: rgba(255,255,255,0.7);
text-decoration: none;
line-height: 1.3;
white-space: nowrap;
}
.a-btn:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.15); color: #fff; }
.a-btn-primary {
background: rgba(245,158,11,0.12);
border-color: rgba(245,158,11,0.2);
color: #f59e0b;
}
.a-btn-primary:hover { background: rgba(245,158,11,0.2); border-color: #f59e0b; }
.a-btn-danger {
background: rgba(239,68,68,0.1);
border-color: rgba(239,68,68,0.15);
color: #ef4444;
}
.a-btn-danger:hover { background: rgba(239,68,68,0.2); border-color: #ef4444; }
.a-btn-success {
background: rgba(34,197,94,0.1);
border-color: rgba(34,197,94,0.15);
color: #22c55e;
}
.a-btn-success:hover { background: rgba(34,197,94,0.2); border-color: #22c55e; }
.a-btn-sm { padding: 0.3rem 0.55rem; font-size: 0.7rem; }
.a-btn:disabled { opacity: 0.4; cursor: not-allowed; }
/* ─── Form inputs ─── */
.a-input {
background: rgba(0,0,0,0.3);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 7px;
padding: 0.5rem 0.75rem;
color: #e8e8e8;
font-size: 0.82rem;
outline: none;
transition: border-color 0.15s;
width: 100%;
}
.a-input:focus { border-color: rgba(245,158,11,0.4); }
.a-input-sm { padding: 0.35rem 0.5rem; font-size: 0.78rem; }
.a-label {
display: block;
font-size: 0.75rem;
font-weight: 600;
color: rgba(255,255,255,0.5);
margin-bottom: 0.35rem;
}
/* ─── Badge ─── */
.a-badge {
display: inline-flex;
padding: 0.15rem 0.45rem;
border-radius: 4px;
font-size: 0.7rem;
font-weight: 600;
}
.a-badge-admin { background: rgba(245,158,11,0.12); color: #f59e0b; }
.a-badge-user { background: rgba(59,130,246,0.12); color: #60a5fa; }
.a-badge-banned { background: rgba(239,68,68,0.12); color: #ef4444; }
/* ─── Modal ─── */
.a-overlay {
position: fixed; inset: 0;
background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
z-index: 100; display: none; align-items: center; justify-content: center;
padding: 1rem;
}
.a-overlay.open { display: flex; }
.a-modal {
background: #16171d;
border: 1px solid rgba(255,255,255,0.06);
border-radius: 16px;
padding: 1.5rem;
max-width: 460px; width: 100%;
box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.a-modal-title {
font-size: 1rem; font-weight: 600; margin-bottom: 1rem;
}
.a-modal-actions {
display: flex; gap: 0.5rem; margin-top: 1rem;
justify-content: flex-end;
}
/* ─── Grid helpers ─── */
.a-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.a-row > * { flex: 1; min-width: 0; }
.a-gap-sm { gap: 0.5rem; }
.a-mt { margin-top: 1rem; }
.a-mb { margin-bottom: 1rem; }
.a-flex { display: flex; align-items: center; gap: 0.5rem; }
/* ─── Empty state ─── */
.a-empty {
text-align: center; padding: 3rem 1rem;
color: rgba(255,255,255,0.3);
}
.a-empty .a-empty-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
@media(max-width:768px){
.admin-sidebar { width: 56px; }
.admin-sidebar .sb-brand span,
.admin-sidebar .sb-nav a span:not(.sb-icon),
.admin-sidebar .sb-footer span { display: none; }
.admin-sidebar .sb-nav a { justify-content: center; padding: 0.65rem; }
.admin-sidebar .sb-footer a { justify-content: center; }
}
{% block extra_styles %}{% endblock %}
</style>
</head>
<body>
<div class="admin-sidebar">
<div class="sb-brand">
<span style="font-size:1.2rem"></span>
<span>CS2 <span>Admin</span></span>
</div>
<nav class="sb-nav">
<a href="/admin" class="{% block nav_dashboard %}{% endblock %}">
<span class="sb-icon">📊</span> <span>Дашборд</span>
</a>
<a href="/admin/users" class="{% block nav_users %}{% endblock %}">
<span class="sb-icon">👥</span> <span>Пользователи</span>
</a>
<a href="/admin/cases" class="{% block nav_cases %}{% endblock %}">
<span class="sb-icon">📦</span> <span>Кейсы</span>
</a>
</nav>
<div class="sb-footer">
<a href="/">&larr; <span>На сайт</span></a>
</div>
</div>
<div class="admin-main">
<div class="admin-topbar">
<div class="at-title">
{% block page_title %}Панель управления{% endblock %}
</div>
<div class="at-actions">
{% block top_actions %}{% endblock %}
</div>
</div>
<div class="admin-content">
{% block content %}{% endblock %}
</div>
</div>
{% block modals %}{% endblock %}
{% block scripts %}{% endblock %}
</body>
</html>
+361
View File
@@ -0,0 +1,361 @@
{% extends "admin/base.html" %}
{% block title %}Кейсы — Админ-панель{% endblock %}
{% block nav_cases %}active{% endblock %}
{% block page_title %}📦 Управление кейсами{% endblock %}
{% block top_actions %}
<button class="a-btn a-btn-primary" onclick="openCreateCaseModal()"> Создать кейс</button>
{% endblock %}
{% block content %}
<div class="a-card">
<div class="a-card-header">📂 Секции главной страницы</div>
<div id="mainpageSections">
{% for section in mainpage %}
<div class="a-card" style="margin-bottom:0.75rem;padding:1rem" data-tab="{{ section.tab }}">
<div class="a-flex" style="justify-content:space-between">
<strong style="font-size:0.9rem">{{ section.tab }}</strong>
<div class="td-actions">
<button class="a-btn a-btn-sm" onclick="openAddCaseModal('{{ section.tab }}')"> Добавить кейс</button>
<button class="a-btn a-btn-danger a-btn-sm" onclick="deleteSection('{{ section.tab }}')"></button>
</div>
</div>
<div class="a-flex" style="flex-wrap:wrap;gap:0.5rem;margin-top:0.5rem">
{% for case_name in section.cases %}
<span style="background:rgba(255,255,255,0.04);border-radius:6px;padding:0.2rem 0.5rem;font-size:0.78rem;display:flex;align-items:center;gap:0.3rem">
🎲 {{ case_name }}
<span onclick="removeCaseFromSection('{{ section.tab }}','{{ case_name }}')" style="cursor:pointer;color:#ef4444;font-size:0.7rem"></span>
</span>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
<button class="a-btn a-mt" onclick="openAddSectionModal()"> Добавить секцию</button>
</div>
<div class="a-card">
<div class="a-card-header">🎲 Все кейсы</div>
<div class="a-table-wrap">
<table class="a-table">
<thead><tr><th>Название</th><th>Цена</th><th>Тип</th><th>Предметов</th><th></th></tr></thead>
<tbody>
{% for c in cases %}
<tr>
<td><strong>{{ c.name }}</strong></td>
<td>{{ c.price_open }} ₽</td>
<td style="font-size:0.75rem">{{ c.display_name|default('') }}</td>
<td>{{ c.items_count }}</td>
<td class="td-actions">
<button class="a-btn a-btn-sm" onclick="openEditCaseModal('{{ c.name }}')">✏️</button>
<button class="a-btn a-btn-danger a-btn-sm" onclick="deleteCase('{{ c.name }}')">🗑️</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}
{% block modals %}
<!-- Create/Edit Case Modal -->
<div class="a-overlay" id="caseModal">
<div class="a-modal" style="max-width:600px">
<div class="a-modal-title" id="caseModalTitle">🎲 Создать кейс</div>
<input type="hidden" id="editCaseName">
<div class="a-row a-gap-sm">
<div class="a-mb" style="flex:1">
<label class="a-label">Название кейса (ID)</label>
<input type="text" id="caseNameInput" class="a-input" placeholder="my_case">
</div>
<div class="a-mb" style="flex:1">
<label class="a-label">Отображаемое название</label>
<input type="text" id="caseDisplayName" class="a-input" placeholder="Мой кейс">
</div>
</div>
<div class="a-row a-gap-sm">
<div class="a-mb" style="flex:1">
<label class="a-label">Цена открытия</label>
<input type="number" id="casePrice" class="a-input" value="250">
</div>
<div class="a-mb" style="flex:1">
<label class="a-label">Ссылка на изображение</label>
<input type="text" id="caseImage" class="a-input" placeholder="/static/cases/default.png">
</div>
</div>
<div class="a-mb">
<label class="a-label">Описание (необязательно)</label>
<input type="text" id="caseDescription" class="a-input" placeholder="Описание кейса...">
</div>
<div class="a-card" style="background:rgba(0,0,0,0.2);padding:0.75rem">
<div class="a-card-header" style="margin-bottom:0.5rem">📋 Предметы кейса</div>
<div id="caseItemsList"></div>
<div class="a-flex a-mt" style="flex-wrap:wrap">
<input type="text" id="caseItemSearch" class="a-input a-input-sm" style="flex:1;min-width:120px" placeholder="Поиск предмета..." oninput="searchCaseItems()">
<button class="a-btn a-btn-sm" onclick="openAllItemsModal()">📦 Все предметы</button>
</div>
</div>
<div class="a-modal-actions">
<button class="a-btn" onclick="closeModal('caseModal')">Отмена</button>
<button class="a-btn a-btn-primary" id="saveCaseBtn" onclick="saveCase()">💾 Сохранить</button>
</div>
</div>
</div>
<!-- All items browser modal -->
<div class="a-overlay" id="allItemsModal">
<div class="a-modal" style="max-width:700px;max-height:80vh;display:flex;flex-direction:column">
<div class="a-modal-title">📦 Все предметы</div>
<input type="text" id="allItemsSearch" class="a-input a-input-sm a-mb" placeholder="Поиск..." oninput="searchAllItems()">
<div id="allItemsGrid" style="flex:1;overflow-y:auto;display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:0.5rem"></div>
</div>
</div>
<!-- Add case to section modal -->
<div class="a-overlay" id="addCaseModal">
<div class="a-modal" style="max-width:400px">
<div class="a-modal-title">➕ Добавить кейс в секцию</div>
<p style="font-size:0.82rem;color:rgba(255,255,255,0.5);margin-bottom:0.75rem">Секция: <strong id="addCaseSectionName"></strong></p>
<div class="a-mb">
<label class="a-label">Выберите кейс</label>
<select id="addCaseSelect" class="a-input"></select>
</div>
<div class="a-modal-actions">
<button class="a-btn" onclick="closeModal('addCaseModal')">Отмена</button>
<button class="a-btn a-btn-primary" onclick="confirmAddCase()">Добавить</button>
</div>
</div>
</div>
<!-- Add section modal -->
<div class="a-overlay" id="addSectionModal">
<div class="a-modal" style="max-width:400px">
<div class="a-modal-title"> Новая секция</div>
<div class="a-mb">
<label class="a-label">Название вкладки</label>
<input type="text" id="newSectionName" class="a-input" placeholder="Новая коллекция">
</div>
<div class="a-modal-actions">
<button class="a-btn" onclick="closeModal('addSectionModal')">Отмена</button>
<button class="a-btn a-btn-primary" onclick="confirmAddSection()">Создать</button>
</div>
</div>
</div>
{% endblock %}
{% block extra_styles %}
<style>
.ci-item { display:flex; align-items:center; gap:0.5rem; padding:0.35rem 0; border-bottom:1px solid rgba(255,255,255,0.03); font-size:0.78rem; }
.ci-item img { width:32px; height:24px; object-fit:contain; }
.ci-item .ci-info { flex:1; }
.ci-item .ci-rarity { font-size:0.65rem; color:rgba(255,255,255,0.35); }
.all-item-card { background:rgba(0,0,0,0.15); border-radius:6px; padding:0.35rem; cursor:pointer; text-align:center; font-size:0.7rem; transition:all 0.15s; border:1px solid transparent; }
.all-item-card:hover { border-color:rgba(245,158,11,0.3); background:rgba(245,158,11,0.05); }
.all-item-card img { width:100%; height:40px; object-fit:contain; }
</style>
{% endblock %}
{% block scripts %}
<script>
let currentCaseItems = [];
let editingCaseName = null;
// ─── Modals ──────────────────────────────────────────────────────────────────
function closeModal(id) { document.getElementById(id).classList.remove('open'); }
function openModal(id) { document.getElementById(id).classList.add('open'); }
// ─── Load page data ──────────────────────────────────────────────────────────
let allCasesList = [];
document.addEventListener('DOMContentLoaded', async () => {
const r = await fetch('/admin/api/cases/list');
const d = await r.json();
allCasesList = d.cases || [];
});
// ─── Create / Edit Case ──────────────────────────────────────────────────────
function openCreateCaseModal() {
editingCaseName = null;
document.getElementById('caseModalTitle').textContent = '🎲 Создать кейс';
document.getElementById('saveCaseBtn').textContent = '💾 Создать';
document.getElementById('editCaseName').value = '';
document.getElementById('caseNameInput').value = '';
document.getElementById('caseDisplayName').value = '';
document.getElementById('casePrice').value = '250';
document.getElementById('caseImage').value = '';
document.getElementById('caseDescription').value = '';
currentCaseItems = [];
renderCaseItems();
openModal('caseModal');
}
function openEditCaseModal(caseName) {
editingCaseName = caseName;
document.getElementById('caseModalTitle').textContent = '✏️ Редактировать кейс';
document.getElementById('saveCaseBtn').textContent = '💾 Сохранить';
document.getElementById('editCaseName').value = caseName;
const cfg = {{ cases_config|tojson }};
const c = cfg[caseName] || {};
document.getElementById('caseNameInput').value = caseName;
document.getElementById('caseDisplayName').value = c.display_name || '';
document.getElementById('casePrice').value = c.price_open || 250;
document.getElementById('caseImage').value = c.image_url || '';
document.getElementById('caseDescription').value = c.description || '';
currentCaseItems = (c.items || []).filter(i => typeof i === 'object');
renderCaseItems();
openModal('caseModal');
}
function renderCaseItems() {
const div = document.getElementById('caseItemsList');
div.innerHTML = currentCaseItems.map((item, i) => `
<div class="ci-item">
<img src="${item.image_url || '/static/placeholder.png'}" onerror="this.src='/static/placeholder.png'">
<div class="ci-info">
<div>${item.market_hash_name || item.name || '???'}</div>
<div class="ci-rarity">${item.rarity || ''}${item.weapon || ''}</div>
</div>
<button class="a-btn a-btn-danger a-btn-sm" onclick="removeCaseItem(${i})">✕</button>
</div>
`).join('');
}
function removeCaseItem(idx) {
currentCaseItems.splice(idx, 1);
renderCaseItems();
}
function addCaseItem(item) {
if (currentCaseItems.some(i => (i.market_hash_name || i.name) === (item.market_hash_name || item.name))) return;
currentCaseItems.push(item);
renderCaseItems();
}
async function searchCaseItems() {
const q = document.getElementById('caseItemSearch').value;
if (q.length < 2) return;
const r = await fetch(`/admin/api/items/search?q=${encodeURIComponent(q)}`);
const items = await r.json();
// show as dropdown
let html = '<div style="margin-top:0.5rem;max-height:200px;overflow-y:auto">';
items.forEach(item => {
html += `<div class="ci-item" style="cursor:pointer" onclick="addCaseItem(${JSON.stringify(item).replace(/"/g,'&quot;')})">
<img src="${item.image_url || '/static/placeholder.png'}" onerror="this.src='/static/placeholder.png'">
<div class="ci-info"><div>${item.name}</div><div class="ci-rarity">${item.rarity}${item.price_rub||0} ₽</div></div>
</div>`;
});
html += '</div>';
const existing = document.getElementById('caseItemSearchResults');
if (!existing) {
const d = document.createElement('div'); d.id = 'caseItemSearchResults';
document.getElementById('caseItemSearch').parentNode.appendChild(d);
}
document.getElementById('caseItemSearchResults').innerHTML = html;
}
async function saveCase() {
const name = document.getElementById('caseNameInput').value.trim();
if (!name) { alert('Введите название кейса'); return; }
const fd = new FormData();
fd.append('case_name', name);
fd.append('display_name', document.getElementById('caseDisplayName').value);
fd.append('price_open', document.getElementById('casePrice').value);
fd.append('image_url', document.getElementById('caseImage').value);
fd.append('description', document.getElementById('caseDescription').value);
fd.append('items_json', JSON.stringify(currentCaseItems));
const isEdit = editingCaseName !== null && editingCaseName !== name;
const url = isEdit
? `/admin/api/cases/update/${encodeURIComponent(editingCaseName)}`
: '/admin/api/cases/create';
const r = await fetch(url, { method:'POST', body:fd });
const d = await r.json();
if (d.success) { window.location.reload(); }
else alert(d.error || 'Ошибка');
}
async function deleteCase(name) {
if (!confirm(`Удалить кейс "${name}"?`)) return;
const fd = new FormData(); fd.append('case_name', name);
const r = await fetch(`/admin/api/cases/delete/${encodeURIComponent(name)}`, { method:'POST', body:fd });
const d = await r.json();
if (d.success) window.location.reload();
else alert(d.error);
}
// ─── All Items Browser ───────────────────────────────────────────────────────
async function openAllItemsModal() {
openModal('allItemsModal');
document.getElementById('allItemsSearch').value = '';
await searchAllItems();
}
async function searchAllItems() {
const q = document.getElementById('allItemsSearch').value;
const r = await fetch(`/admin/api/items/search?q=${encodeURIComponent(q)}&limit=200`);
const items = await r.json();
document.getElementById('allItemsGrid').innerHTML = items.map(item => `
<div class="all-item-card" onclick="addCaseItemFromAll(${JSON.stringify(item).replace(/"/g,'&quot;')})">
<img src="${item.image_url || '/static/placeholder.png'}" onerror="this.src='/static/placeholder.png'">
<div style="margin-top:0.2rem;line-height:1.15">${item.name}</div>
<div style="font-size:0.6rem;color:rgba(255,255,255,0.35)">${item.rarity}</div>
</div>
`).join('');
}
function addCaseItemFromAll(item) {
addCaseItem(item);
closeModal('allItemsModal');
}
// ─── Mainpage Sections ───────────────────────────────────────────────────────
function openAddSectionModal() {
document.getElementById('newSectionName').value = '';
openModal('addSectionModal');
}
async function confirmAddSection() {
const name = document.getElementById('newSectionName').value.trim();
if (!name) return;
const fd = new FormData(); fd.append('tab', name);
const r = await fetch('/admin/api/mainpage/section/add', { method:'POST', body:fd });
const d = await r.json();
if (d.success) window.location.reload();
else alert(d.error);
}
async function deleteSection(tab) {
if (!confirm(`Удалить секцию "${tab}"?`)) return;
const fd = new FormData(); fd.append('tab', tab);
const r = await fetch('/admin/api/mainpage/section/delete', { method:'POST', body:fd });
const d = await r.json();
if (d.success) window.location.reload();
else alert(d.error);
}
function openAddCaseModal(tab) {
document.getElementById('addCaseSectionName').textContent = tab;
const sel = document.getElementById('addCaseSelect');
sel.innerHTML = allCasesList.map(c => `<option value="${c}">${c}</option>`).join('');
sel.dataset.tab = tab;
openModal('addCaseModal');
}
async function confirmAddCase() {
const tab = document.getElementById('addCaseSelect').dataset.tab;
const caseName = document.getElementById('addCaseSelect').value;
const fd = new FormData();
fd.append('tab', tab);
fd.append('case_name', caseName);
const r = await fetch('/admin/api/mainpage/section/add-case', { method:'POST', body:fd });
const d = await r.json();
if (d.success) window.location.reload();
else alert(d.error);
}
async function removeCaseFromSection(tab, caseName) {
if (!confirm(`Убрать "${caseName}" из "${tab}"?`)) return;
const fd = new FormData();
fd.append('tab', tab);
fd.append('case_name', caseName);
const r = await fetch('/admin/api/mainpage/section/remove-case', { method:'POST', body:fd });
const d = await r.json();
if (d.success) window.location.reload();
else alert(d.error);
}
</script>
{% endblock %}
+57
View File
@@ -0,0 +1,57 @@
{% extends "admin/base.html" %}
{% block title %}Дашборд — Админ-панель{% endblock %}
{% block nav_dashboard %}active{% endblock %}
{% block page_title %}📊 Дашборд{% endblock %}
{% block content %}
<div class="a-stats">
<div class="a-stat">
<div class="as-label">Пользователей</div>
<div class="as-value">{{ total_users }}</div>
<div class="as-bar" style="width:60%;background:#f59e0b"></div>
</div>
<div class="a-stat">
<div class="as-label">Открыто кейсов</div>
<div class="as-value">{{ total_openings }}</div>
<div class="as-bar" style="width:45%;background:#60a5fa"></div>
</div>
<div class="a-stat">
<div class="as-label">Проведено контрактов</div>
<div class="as-value">{{ total_contracts }}</div>
<div class="as-bar" style="width:30%;background:#a78bfa"></div>
</div>
<div class="a-stat">
<div class="as-label">Предметов в БД</div>
<div class="as-value">{{ total_items }}</div>
<div class="as-bar" style="width:75%;background:#f472b6"></div>
</div>
<div class="a-stat">
<div class="as-label">Общий баланс</div>
<div class="as-value">{{ "%.0f"|format(total_balance) }} ₽</div>
<div class="as-bar" style="width:40%;background:#34d399"></div>
</div>
<div class="a-stat">
<div class="as-label">Средний РПУ</div>
<div class="as-value">{{ avg_rpu }}%</div>
<div class="as-bar" style="width:{{ avg_rpu }}%;background:#fbbf24"></div>
</div>
</div>
<div class="a-row a-mb">
<div class="a-card" style="flex:1">
<div class="a-card-header">🎲 RPU Overview</div>
{% if rpu_count > 0 %}
<div class="a-row a-gap-sm a-mb" style="text-align:center;justify-content:space-around">
<div><div class="as-value" style="font-size:1.2rem">{{ rpu_count }}</div><div class="as-label" style="font-size:0.7rem">Всего записей</div></div>
<div><div class="as-value" style="font-size:1.2rem">{{ "%.1f"|format(avg_rpu) }}%</div><div class="as-label" style="font-size:0.7rem">Средний уровень</div></div>
<div><div class="as-value" style="font-size:1.2rem" style="color:#22c55e">{{ lucky_count }}</div><div class="as-label" style="font-size:0.7rem">🍀 Везучих</div></div>
<div><div class="as-value" style="font-size:1.2rem" style="color:#f59e0b">{{ normal_count }}</div><div class="as-label" style="font-size:0.7rem">📊 Обычных</div></div>
<div><div class="as-value" style="font-size:1.2rem" style="color:#ef4444">{{ unlucky_count }}</div><div class="as-label" style="font-size:0.7rem">🌧️ Невезучих</div></div>
<div><div class="as-value" style="font-size:1.2rem">{{ "%.0f"|format(total_spent) }} ₽</div><div class="as-label" style="font-size:0.7rem">Потрачено всего</div></div>
</div>
{% else %}
<div class="a-empty"><div class="a-empty-icon">📭</div>Нет данных RPU</div>
{% endif %}
</div>
</div>
{% endblock %}
+294
View File
@@ -0,0 +1,294 @@
{% extends "admin/base.html" %}
{% block title %}{{ target_user.username }} — Админ-панель{% endblock %}
{% block nav_users %}active{% endblock %}
{% block page_title %}
👤 {{ target_user.username }}
{% if target_user.is_admin %}<span class="a-badge a-badge-admin" style="margin-left:0.5rem">Админ</span>{% endif %}
{% if target_user.is_banned %}<span class="a-badge a-badge-banned" style="margin-left:0.5rem">Забанен</span>{% endif %}
{% endblock %}
{% block top_actions %}
<a href="/admin/users" class="at-back">&larr; Назад</a>
{% endblock %}
{% block content %}
<div class="a-stats" style="grid-template-columns:repeat(4,1fr)">
<div class="a-stat">
<div class="as-label">Баланс</div>
<div class="as-value">{{ "%.0f"|format(target_user.balance) }} ₽</div>
</div>
<div class="a-stat">
<div class="as-label">Предметов</div>
<div class="as-value">{{ inventory|length }}</div>
</div>
<div class="a-stat">
<div class="as-label">Открытий кейсов</div>
<div class="as-value">{{ total_openings }}</div>
</div>
<div class="a-stat">
<div class="as-label">Контрактов</div>
<div class="as-value">{{ total_contracts }}</div>
</div>
</div>
<!-- RPU -->
<div class="a-card">
<div class="a-card-header">🎲 РПУ (Режим Персонального Угнетения)</div>
<div class="a-row a-gap-sm a-mb" id="rpuStats" style="justify-content:space-around;text-align:center">
<div><div class="as-value" style="font-size:1.4rem" id="rpuLevel">--</div><div class="as-label" style="font-size:0.7rem">Уровень</div></div>
<div><div class="as-value" style="font-size:1.4rem" id="rpuLuck">--</div><div class="as-label" style="font-size:0.7rem">Множитель</div></div>
<div><div class="as-value" style="font-size:1.4rem" id="rpuSpent">--</div><div class="as-label" style="font-size:0.7rem">Потрачено</div></div>
<div><div class="as-value" style="font-size:1.4rem" id="rpuOpened">--</div><div class="as-label" style="font-size:0.7rem">Открыто</div></div>
<div><div class="as-value" style="font-size:1.4rem" id="rpuAutoStatus">--</div><div class="as-label" style="font-size:0.7rem">Авто</div></div>
</div>
<div class="a-flex" style="flex-wrap:wrap">
<button class="a-btn a-btn-primary" onclick="openRPUModal()">⚙️ Настроить</button>
<button class="a-btn" style="border-color:#10b981;color:#10b981" onclick="setRPUPreset('lucky')">🍀 Везучий</button>
<button class="a-btn" style="border-color:#f59e0b;color:#f59e0b" onclick="setRPUPreset('normal')">📊 Обычный</button>
<button class="a-btn" style="border-color:#ef4444;color:#ef4444" onclick="setRPUPreset('unlucky')">🌧️ Невезучий</button>
<button class="a-btn a-btn-danger" onclick="setRPUPreset('very_unlucky')">💀 Проклятый</button>
</div>
</div>
<!-- Действия -->
<div class="a-card">
<div class="a-card-header">🔧 Действия</div>
<div class="a-flex" style="flex-wrap:wrap">
<button class="a-btn a-btn-primary" onclick="openBalanceModal()">💰 Баланс</button>
<button class="a-btn" onclick="openGiveItemModal()">🎁 Выдать предмет</button>
{% if target_user.id != user.id %}
<button class="a-btn" onclick="toggleAdmin()">{{ "👑 Снять админа" if target_user.is_admin else "👑 Сделать админом" }}</button>
{% endif %}
<button class="a-btn {{ 'a-btn-danger' if not target_user.is_banned else 'a-btn-success' }}" onclick="toggleBan()">
{{ "🔨 Забанить" if not target_user.is_banned else "✅ Разбанить" }}
</button>
</div>
</div>
<!-- Инвентарь -->
<div class="a-card">
<div class="a-card-header">🎒 Инвентарь (последние 50)</div>
<div class="a-table-wrap">
<table class="a-table">
<thead><tr><th>ID</th><th>Название</th><th>Редкость</th><th>Float</th><th></th></tr></thead>
<tbody>
{% for item in inventory %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.market_hash_name[:35] }}{{'…' if item.market_hash_name|length > 35}}</td>
<td>{{ item.rarity }}</td>
<td>{{ "%.4f"|format(item.float_value) }}</td>
<td class="td-actions">
<button class="a-btn a-btn-danger a-btn-sm" onclick="deleteItem({{ item.id }})">🗑️</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}
{% block modals %}
<!-- Баланс -->
<div class="a-overlay" id="balanceModal">
<div class="a-modal">
<div class="a-modal-title">💰 Изменить баланс</div>
<p style="font-size:0.85rem;color:rgba(255,255,255,0.5);margin-bottom:1rem">
Текущий: <strong style="color:#f59e0b">{{ "%.2f"|format(target_user.balance) }} ₽</strong>
</p>
<div class="a-mb">
<label class="a-label">Сумма</label>
<input type="number" id="balanceAmount" class="a-input" min="0" step="100" value="1000">
</div>
<div class="a-mb">
<label class="a-label">Операция</label>
<select id="balanceOperation" class="a-input">
<option value="add"> Добавить</option>
<option value="remove"> Снять</option>
<option value="set">🎯 Установить</option>
</select>
</div>
<div class="a-modal-actions">
<button class="a-btn" onclick="closeModal('balanceModal')">Отмена</button>
<button class="a-btn a-btn-primary" onclick="updateBalance()">Применить</button>
</div>
</div>
</div>
<!-- Выдать предмет -->
<div class="a-overlay" id="giveItemModal">
<div class="a-modal" style="max-width:560px">
<div class="a-modal-title">🎁 Выдать предмет</div>
<div class="a-mb">
<label class="a-label">Поиск</label>
<input type="text" id="itemSearchInput" class="a-input" placeholder="Введите название..." oninput="searchItems()">
</div>
<div id="itemSearchResults" style="max-height:300px;overflow-y:auto"></div>
<div class="a-modal-actions">
<button class="a-btn" onclick="closeModal('giveItemModal')">Закрыть</button>
</div>
</div>
</div>
<!-- RPU -->
<div class="a-overlay" id="rpuModal">
<div class="a-modal" style="max-width:500px">
<div class="a-modal-title">⚙️ Настройка РПУ</div>
<div id="rpuSliders" class="a-mb"></div>
<div class="a-mb">
<label class="a-label" style="display:flex;align-items:center;gap:0.5rem;cursor:pointer">
<input type="checkbox" id="rpuAutoAdjust"> 🔄 Автоматическая подкрутка
</label>
</div>
<div class="a-modal-actions">
<button class="a-btn" onclick="closeModal('rpuModal')">Отмена</button>
<button class="a-btn a-btn-primary" onclick="saveRPU()">Сохранить</button>
</div>
</div>
</div>
{% endblock %}
{% block extra_styles %}
<style>
.slider-group { margin-bottom: 0.75rem; }
.slider-group label { display:flex; justify-content:space-between; font-size:0.78rem; color:rgba(255,255,255,0.6); margin-bottom:0.2rem; }
.slider-group input[type=range] { width:100%; accent-color:#f59e0b; }
#itemSearchResults > div {
display:flex; align-items:center; gap:0.75rem;
padding:0.5rem; border-bottom:1px solid rgba(255,255,255,0.04);
}
#itemSearchResults > div img { width:40px; height:32px; object-fit:contain; }
#itemSearchResults > div .ir-info { flex:1; }
#itemSearchResults > div .ir-info .ir-name { font-size:0.82rem; }
#itemSearchResults > div .ir-info .ir-meta { font-size:0.7rem; color:rgba(255,255,255,0.35); }
</style>
{% endblock %}
{% block scripts %}
<script>
const userId = {{ target_user.id }};
let currentRPU = null;
function closeModal(id) { document.getElementById(id).classList.remove('open'); }
function openModal(id) { document.getElementById(id).classList.add('open'); }
// ====== BALANCE ======
function openBalanceModal() { openModal('balanceModal'); }
async function updateBalance() {
const fd = new FormData();
fd.append('amount', document.getElementById('balanceAmount').value);
fd.append('operation', document.getElementById('balanceOperation').value);
const res = await fetch(`/admin/api/user/${userId}/balance`, { method:'POST', body:fd });
const d = await res.json();
if (d.success) { alert(d.message); window.location.reload(); }
else alert(d.error);
}
// ====== GIVE ITEM ======
function openGiveItemModal() { openModal('giveItemModal'); searchItems(); }
async function searchItems() {
const q = document.getElementById('itemSearchInput').value;
const res = await fetch(`/admin/api/items/search?q=${encodeURIComponent(q)}`);
const items = await res.json();
document.getElementById('itemSearchResults').innerHTML = items.map(item => `
<div>
<img src="${item.image_url || '/static/placeholder.png'}" onerror="this.src='/static/placeholder.png'">
<div class="ir-info">
<div class="ir-name">${item.name}</div>
<div class="ir-meta">${item.rarity}${item.price_rub || 0} ₽</div>
</div>
<button class="a-btn a-btn-primary a-btn-sm" onclick="giveItem(${item.id})">Выдать</button>
</div>
`).join('');
}
async function giveItem(itemId) {
const fd = new FormData(); fd.append('item_id', itemId);
const res = await fetch(`/admin/api/user/${userId}/give-item`, { method:'POST', body:fd });
const d = await res.json();
if (d.success) { alert(d.message); closeModal('giveItemModal'); window.location.reload(); }
else alert(d.error);
}
// ====== DELETE ITEM ======
async function deleteItem(invId) {
if (!confirm('Удалить предмет?')) return;
const res = await fetch(`/admin/api/user/${userId}/delete-item/${invId}`, { method:'POST' });
const d = await res.json();
if (d.success) window.location.reload();
else alert(d.error);
}
// ====== TOGGLE ADMIN / BAN ======
async function toggleAdmin() {
if (!confirm('Изменить статус админа?')) return;
const res = await fetch(`/admin/api/user/${userId}/toggle-admin`, { method:'POST' });
const d = await res.json();
if (d.success) window.location.reload(); else alert(d.error);
}
async function toggleBan() {
if (!confirm('{{ "Забанить" if not target_user.is_banned else "Разбанить" }}?')) return;
const res = await fetch(`/admin/api/user/${userId}/toggle-ban`, { method:'POST' });
const d = await res.json();
if (d.success) window.location.reload(); else alert(d.error);
}
// ====== RPU ======
async function loadRPU() {
try {
const res = await fetch(`/admin/api/user/${userId}/rpu`);
const d = await res.json();
currentRPU = d;
const lv = Math.round(d.rpu_level);
document.getElementById('rpuLevel').textContent = lv + '%';
document.getElementById('rpuLevel').style.color = lv < 40 ? '#22c55e' : lv > 60 ? '#ef4444' : '#f59e0b';
document.getElementById('rpuLuck').textContent = d.luck_multiplier.toFixed(2) + 'x';
document.getElementById('rpuSpent').textContent = Math.round(d.stats.total_spent).toLocaleString() + ' ₽';
document.getElementById('rpuOpened').textContent = d.stats.total_opened.toLocaleString();
document.getElementById('rpuAutoStatus').textContent = d.auto_adjust ? '✅' : '❌';
} catch(_) {}
}
function openRPUModal() {
const sliders = document.getElementById('rpuSliders');
const rarities = [
['consumer','Consumer Grade'],['industrial','Industrial Grade'],
['mil_spec','Mil-Spec'],['restricted','Restricted'],
['classified','Classified'],['covert','Covert'],['rare_special','Rare Special']
];
let html = '';
rarities.forEach(([k,l]) => {
const v = currentRPU?.multipliers[k] || 1.0;
html += `<div class="slider-group"><label><span>${l}</span><span id="rp_${k}_v">${v.toFixed(2)}x</span></label>
<input type="range" id="rp_${k}" min="0.1" max="3.0" step="0.05" value="${v}"
oninput="document.getElementById('rp_${k}_v').textContent=this.value+'x'"></div>`;
});
const lv = currentRPU?.luck_multiplier || 1.0;
html += `<div class="slider-group"><label><span>🍀 Общая удача</span><span id="rp_luck_v">${lv.toFixed(2)}x</span></label>
<input type="range" id="rp_luck" min="0.1" max="3.0" step="0.05" value="${lv}"
oninput="document.getElementById('rp_luck_v').textContent=this.value+'x'"></div>`;
sliders.innerHTML = html;
document.getElementById('rpuAutoAdjust').checked = currentRPU?.auto_adjust || false;
openModal('rpuModal');
}
async function saveRPU() {
const fd = new FormData();
['consumer','industrial','mil_spec','restricted','classified','covert','rare_special'].forEach(k => fd.append(k, document.getElementById('rp_'+k).value));
fd.append('luck', document.getElementById('rp_luck').value);
fd.append('auto_adjust', document.getElementById('rpuAutoAdjust').checked);
const res = await fetch(`/admin/api/user/${userId}/rpu/update`, { method:'POST', body:fd });
const d = await res.json();
if (d.success) { alert(d.message); closeModal('rpuModal'); loadRPU(); }
else alert(d.error);
}
async function setRPUPreset(preset) {
const names = { lucky:'🍀 Везучий', normal:'📊 Обычный', unlucky:'🌧️ Невезучий', very_unlucky:'💀 Проклятый' };
if (!confirm('Применить "'+names[preset]+'"?')) return;
const fd = new FormData(); fd.append('preset', preset);
const res = await fetch(`/admin/api/user/${userId}/rpu/preset`, { method:'POST', body:fd });
const d = await res.json();
if (d.success) { alert(d.message); loadRPU(); } else alert(d.error);
}
document.addEventListener('DOMContentLoaded', loadRPU);
</script>
{% endblock %}
+72
View File
@@ -0,0 +1,72 @@
{% extends "admin/base.html" %}
{% block title %}Пользователи — Админ-панель{% endblock %}
{% block nav_users %}active{% endblock %}
{% block page_title %}👥 Пользователи{% endblock %}
{% block top_actions %}
<div class="a-flex">
<input type="text" id="userSearch" class="a-input a-input-sm" style="width:200px" placeholder="Поиск по имени..." value="{{ search or '' }}">
<button class="a-btn a-btn-primary" onclick="searchUsers()">🔍 Найти</button>
</div>
{% endblock %}
{% block content %}
{% if users %}
<div class="a-table-wrap">
<table class="a-table">
<thead>
<tr>
<th>ID</th>
<th>Имя</th>
<th>Баланс</th>
<th>Статус</th>
<th>Кейсов</th>
<th>Контрактов</th>
<th>Достижений</th>
<th></th>
</tr>
</thead>
<tbody>
{% for u in users %}
<tr>
<td>{{ u.id }}</td>
<td>
<a href="/admin/user/{{ u.id }}" style="color:#f59e0b;text-decoration:none;font-weight:500">
{{ u.username }}
</a>
</td>
<td>{{ "%.0f"|format(u.balance) }} ₽</td>
<td>
{% if u.is_admin %}<span class="a-badge a-badge-admin">Админ</span>{% endif %}
{% if u.is_banned %}<span class="a-badge a-badge-banned">Забанен</span>{% endif %}
{% if not u.is_admin and not u.is_banned %}<span class="a-badge a-badge-user">Игрок</span>{% endif %}
</td>
<td>{{ u.case_openings|default(0) }}</td>
<td>{{ u.contracts|default(0) }}</td>
<td>{{ u.achievements|default(0) }}</td>
<td class="td-actions">
<a href="/admin/user/{{ u.id }}" class="a-btn a-btn-sm">✏️</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="a-empty">
<div class="a-empty-icon">📭</div>
<h3>Пользователи не найдены</h3>
</div>
{% endif %}
{% endblock %}
{% block scripts %}
<script>
function searchUsers() {
const q = document.getElementById('userSearch').value.trim();
window.location.href = '/admin/users' + (q ? '?search=' + encodeURIComponent(q) : '');
}
document.getElementById('userSearch').addEventListener('keydown', e => {
if (e.key === 'Enter') searchUsers();
});
</script>
{% endblock %}