0.1.6s
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
header { display: flex; align-items: center; background-color: var(--bg-header); padding: 10px 20px; border-bottom: 1px solid var(--border-color); gap: 15px; flex-wrap: wrap; }
|
||||
.logo { font-weight: bold; font-size: 18px; color: white; text-decoration: none; }
|
||||
.analytics { color: #88bece; text-decoration: none; font-size: 12px; }
|
||||
.tasks { color: #88bece; text-decoration: none; font-size: 12px; }
|
||||
|
||||
.search-wrapper { flex-grow: 1; max-width: 400px; position: relative; }
|
||||
.search-wrapper input { width: 100%; background-color: var(--bg-input); border: 1px solid var(--border-color); color: white; padding: 6px 10px; border-radius: 3px; outline: none; }
|
||||
@@ -66,6 +67,7 @@
|
||||
<!--
|
||||
<a class="analytics" href="/analytics">📊 Analytics</a>
|
||||
-->
|
||||
<a class="tasks" href="/task">⚙️ Tasks</a>
|
||||
<div class="search-wrapper">
|
||||
<input type="text" id="searchInput" placeholder="Search tags...">
|
||||
<ul id="autocompleteList" class="autocomplete-list"></ul>
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Tasks - LocalBooru</title>
|
||||
<style>
|
||||
:root { --bg-main: #1e1e1e; --bg-header: #252525; --bg-panel: #222; --bg-box: #2a2a2a; --bg-input: #333; --text-main: #eee; --text-muted: #aaa; --border-color: #444; --link-color: #4da8da; --color-g: #4caf50; --color-s: #ff9800; --color-q: #ffeb3b; --color-e: #f44336; }
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body { background-color: var(--bg-main); color: var(--text-main); font-family: sans-serif; font-size: 13px; }
|
||||
|
||||
/* Header Styles */
|
||||
header { display: flex; align-items: center; background-color: var(--bg-header); padding: 10px 20px; border-bottom: 1px solid var(--border-color); gap: 15px; flex-wrap: wrap; }
|
||||
.logo { font-weight: bold; font-size: 18px; color: white; text-decoration: none; }
|
||||
.nav-link { color: var(--link-color); text-decoration: none; font-size: 12px; font-weight: bold;}
|
||||
|
||||
/* Search Autocomplete Styles */
|
||||
.search-wrapper { flex-grow: 1; max-width: 400px; position: relative; }
|
||||
.search-wrapper input { width: 100%; background-color: var(--bg-input); border: 1px solid var(--border-color); color: white; padding: 6px 10px; border-radius: 3px; outline: none; }
|
||||
.autocomplete-list { position: absolute; top: 100%; left: 0; right: 0; background-color: var(--bg-box); border: 1px solid var(--border-color); border-radius: 3px; margin-top: 4px; list-style: none; z-index: 1000; max-height: 250px; overflow-y: auto; box-shadow: 0 4px 10px rgba(0,0,0,0.5); display: none; }
|
||||
.autocomplete-item { padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; border-bottom: 1px solid #333; }
|
||||
.autocomplete-item:hover { background-color: var(--bg-input); }
|
||||
.autocomplete-count { color: var(--text-muted); font-size: 12px; }
|
||||
|
||||
/* Main Content & Tasks Styles */
|
||||
main { padding: 20px; max-width: 1000px; margin: 0 auto; }
|
||||
h1 { font-size: 20px; margin-bottom: 20px; color: white; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; }
|
||||
|
||||
.task-list { display: flex; flex-direction: column; gap: 15px; }
|
||||
|
||||
.task-card { background-color: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 4px; padding: 15px 20px; display: flex; justify-content: space-between; align-items: center; gap: 20px; transition: background-color 0.2s; }
|
||||
.task-card:hover { background-color: var(--bg-box); }
|
||||
|
||||
.task-info h3 { font-size: 16px; color: var(--link-color); margin-bottom: 5px; }
|
||||
.task-info p { color: var(--text-muted); font-size: 13px; line-height: 1.4; }
|
||||
|
||||
.task-actions { display: flex; align-items: center; gap: 15px; min-width: 200px; justify-content: flex-end; }
|
||||
|
||||
.btn { background-color: var(--bg-input); border: 1px solid var(--border-color); color: white; padding: 8px 16px; border-radius: 3px; cursor: pointer; font-weight: bold; transition: all 0.2s; }
|
||||
.btn:hover:not(:disabled) { background-color: #444; border-color: #555; }
|
||||
.btn:active:not(:disabled) { background-color: #222; }
|
||||
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
|
||||
.task-status { font-weight: bold; font-size: 13px; min-width: 90px; text-align: right; }
|
||||
.status-success { color: var(--color-g); }
|
||||
.status-error { color: var(--color-e); }
|
||||
|
||||
@media (max-width: 700px) {
|
||||
header { flex-wrap: wrap; }
|
||||
.search-wrapper { order: 3; min-width: 100%; margin-top: 10px;}
|
||||
.task-card { flex-direction: column; align-items: flex-start; }
|
||||
.task-actions { justify-content: flex-start; width: 100%; margin-top: 10px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<a href="/" class="logo">LocalBooru</a>
|
||||
<div class="search-wrapper">
|
||||
<input type="text" id="searchInput" placeholder="Search tags...">
|
||||
<ul id="autocompleteList" class="autocomplete-list"></ul>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<h1>System Tasks</h1>
|
||||
|
||||
<div class="task-list">
|
||||
|
||||
<!-- ЗАДАЧА 1: Пересчёт аналитики -->
|
||||
<div class="task-card">
|
||||
<div class="task-info">
|
||||
<h3>Пересчёт аналитики</h3>
|
||||
<p>Обновляет статистику (количество файлов, занимаемое место). Рекомендуется запускать после массового добавления или удаления постов.</p>
|
||||
</div>
|
||||
<div class="task-actions">
|
||||
<span class="task-status"></span>
|
||||
<button class="btn" onclick="executeTask('analytic', this)">Запустить</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ШАБЛОН ДЛЯ БУДУЩИХ ЗАДАЧ (просто скопируйте блок ниже и измените 'task_name') -->
|
||||
<!--
|
||||
<div class="task-card">
|
||||
<div class="task-info">
|
||||
<h3>Новая задача</h3>
|
||||
<p>Описание новой задачи.</p>
|
||||
</div>
|
||||
<div class="task-actions">
|
||||
<span class="task-status"></span>
|
||||
<button class="btn" onclick="executeTask('new_task_name', this)">Запустить</button>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
// === ЛОГИКА ЗАДАЧ ===
|
||||
async function executeTask(taskName, btn) {
|
||||
const statusSpan = btn.previousElementSibling;
|
||||
|
||||
// Состояние загрузки
|
||||
btn.disabled = true;
|
||||
btn.innerText = "Выполнение...";
|
||||
statusSpan.innerText = "В процессе ⏳";
|
||||
statusSpan.className = "task-status"; // сброс классов успеха/ошибки
|
||||
|
||||
try {
|
||||
// Отправляем POST запрос на API
|
||||
const response = await fetch('/api', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: "task",
|
||||
task: taskName
|
||||
})
|
||||
});
|
||||
|
||||
// Обработка ответа (200 - успех, 500+ - ошибка)
|
||||
if (response.ok) {
|
||||
statusSpan.innerText = "Успешно ✔";
|
||||
statusSpan.classList.add('status-success');
|
||||
} else {
|
||||
statusSpan.innerText = `Ошибка (${response.status}) ✖`;
|
||||
statusSpan.classList.add('status-error');
|
||||
}
|
||||
} catch (error) {
|
||||
// Ошибка сети или сервер недоступен
|
||||
statusSpan.innerText = "Сбой сети ✖";
|
||||
statusSpan.classList.add('status-error');
|
||||
console.error("Task execution error:", error);
|
||||
} finally {
|
||||
// Возвращаем кнопку в исходное состояние
|
||||
btn.disabled = false;
|
||||
btn.innerText = "Запустить";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// === ЛОГИКА ПОИСКА (оставлена из предыдущей версии) ===
|
||||
const searchInput = document.getElementById('searchInput');
|
||||
const list = document.getElementById('autocompleteList');
|
||||
let debounceTimer;
|
||||
|
||||
searchInput.addEventListener('input', () => {
|
||||
clearTimeout(debounceTimer);
|
||||
const words = searchInput.value.split(' ');
|
||||
const currentWord = words[words.length - 1];
|
||||
if (currentWord.length < 2) { list.style.display = 'none'; return; }
|
||||
|
||||
debounceTimer = setTimeout(async () => {
|
||||
const req = { type: "autocomplete", q: currentWord };
|
||||
const data = await mockAutocompleteAPI(req);
|
||||
|
||||
if (data.length === 0) { list.style.display = 'none'; return; }
|
||||
|
||||
list.innerHTML = data.map(item => `<li class="autocomplete-item" data-tag="${item.tag}"><span>${item.tag}</span><span class="autocomplete-count">${item.count}</span></li>`).join('');
|
||||
list.style.display = 'block';
|
||||
|
||||
list.querySelectorAll('.autocomplete-item').forEach(li => {
|
||||
li.addEventListener('click', () => {
|
||||
words[words.length - 1] = li.getAttribute('data-tag');
|
||||
searchInput.value = words.join(' ') + ' ';
|
||||
list.style.display = 'none';
|
||||
searchInput.focus();
|
||||
});
|
||||
});
|
||||
}, 200);
|
||||
});
|
||||
|
||||
document.addEventListener('click', (e) => { if (e.target !== searchInput && e.target !== list) list.style.display = 'none'; });
|
||||
searchInput.addEventListener('keypress', (e) => { if(e.key === 'Enter') window.location.href = `index.html?query=${searchInput.value.trim()}`; });
|
||||
|
||||
// Заглушка для поиска (оставьте или замените на ваш fetch)
|
||||
function mockAutocompleteAPI(req) { return new Promise(res => { const db = [{tag: "long_hair", count: 8184}, {tag: "1girl", count: 11061}]; res(db.filter(t => t.tag.includes(req.q.toLowerCase()))); }); }
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user