feat: add goal calculator tab
This commit is contained in:
1 parent
b948331b72
commit
a72e86f8c1
1 file changed
+29
-5
+29
-5
@@ -72,6 +72,7 @@
|
|||||||
<button class="active" data-mode="coaching">Прокачка ЛУ/ЗУ</button>
|
<button class="active" data-mode="coaching">Прокачка ЛУ/ЗУ</button>
|
||||||
<button data-mode="training">Тренировка</button>
|
<button data-mode="training">Тренировка</button>
|
||||||
<button data-mode="inspection">Осмотры</button>
|
<button data-mode="inspection">Осмотры</button>
|
||||||
|
<button data-mode="goal">Калькулятор цели</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<section class="panel">
|
<section class="panel">
|
||||||
@@ -120,8 +121,19 @@
|
|||||||
<textarea name="resources" placeholder="+2 вьюнок +1 паук"></textarea></label>
|
<textarea name="resources" placeholder="+2 вьюнок +1 паук"></textarea></label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<label class="wide">Скриншоты отчёта<input id="screenshots" type="file" accept="image/*" multiple><span class="muted">Можно выбрать несколько фотографий. Они будут загружены на img.nyan404.ru.</span></label>
|
<div id="goal" class="grid mode hidden">
|
||||||
<div class="actions"><button class="primary" type="submit">Подготовить сообщение</button><button type="button" id="copy" disabled>Скопировать</button></div>
|
<p class="wide muted">Посчитайте прогресс без заполнения отчёта: укажите текущие и целевые баллы, а также длительность одного захода.</p>
|
||||||
|
<label>Текущие баллы<input name="current_points" type="number" min="0" step="0.01" value="0"></label>
|
||||||
|
<label>Целевые баллы<input name="target_points" type="number" min="0" step="0.01" value="25"></label>
|
||||||
|
<label>Минут в одном заходе<input name="minutes_per_session" type="number" min="1" value="20"></label>
|
||||||
|
<label>Навык<select name="skill"><option>ЛУ</option><option>ЗУ</option></select></label>
|
||||||
|
<label>Статус котёнка<select name="kitten_independence"><option value="самостоятельно">самостоятельный</option><option value="несамостоятельно">несамостоятельный</option></select></label>
|
||||||
|
<label>Количество котят<input name="kitten_count" type="number" min="1" value="1"></label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label id="reportAttachments" class="wide">Скриншоты отчёта<input id="screenshots" type="file" accept="image/*" multiple><span class="muted">Можно выбрать несколько фотографий. Они будут загружены на img.nyan404.ru.</span></label>
|
||||||
|
<div id="reportActions" class="actions"><button class="primary" type="submit">Подготовить сообщение</button><button type="button" id="copy" disabled>Скопировать</button></div>
|
||||||
|
<div id="goalActions" class="actions hidden"><button class="primary" type="submit">Рассчитать цель</button><button type="button" id="goalCopy" disabled>Скопировать</button></div>
|
||||||
</form>
|
</form>
|
||||||
<div id="profileSection" class="panel hidden" style="margin-top: 16px;">
|
<div id="profileSection" class="panel hidden" style="margin-top: 16px;">
|
||||||
<strong>Ваш профиль</strong>
|
<strong>Ваш профиль</strong>
|
||||||
@@ -191,7 +203,11 @@
|
|||||||
const message = document.querySelector('#message');
|
const message = document.querySelector('#message');
|
||||||
const summary = document.querySelector('#summary');
|
const summary = document.querySelector('#summary');
|
||||||
const copy = document.querySelector('#copy');
|
const copy = document.querySelector('#copy');
|
||||||
|
const goalCopy = document.querySelector('#goalCopy');
|
||||||
const screenshots = document.querySelector('#screenshots');
|
const screenshots = document.querySelector('#screenshots');
|
||||||
|
const reportAttachments = document.querySelector('#reportAttachments');
|
||||||
|
const reportActions = document.querySelector('#reportActions');
|
||||||
|
const goalActions = document.querySelector('#goalActions');
|
||||||
const bulkText = document.querySelector('#bulkText');
|
const bulkText = document.querySelector('#bulkText');
|
||||||
const bulkStatus = document.querySelector('#bulkStatus');
|
const bulkStatus = document.querySelector('#bulkStatus');
|
||||||
const bulk = document.querySelector('.bulk');
|
const bulk = document.querySelector('.bulk');
|
||||||
@@ -240,7 +256,11 @@
|
|||||||
mode = nextMode;
|
mode = nextMode;
|
||||||
document.querySelectorAll('[data-mode]').forEach(item => item.classList.toggle('active', item.dataset.mode === mode));
|
document.querySelectorAll('[data-mode]').forEach(item => item.classList.toggle('active', item.dataset.mode === mode));
|
||||||
document.querySelectorAll('.mode').forEach(panel => panel.classList.toggle('hidden', panel.id !== mode));
|
document.querySelectorAll('.mode').forEach(panel => panel.classList.toggle('hidden', panel.id !== mode));
|
||||||
|
document.querySelectorAll('.mode').forEach(panel => panel.querySelectorAll('input, select, textarea').forEach(field => { field.disabled = panel.id !== mode; }));
|
||||||
bulk.classList.toggle('hidden', mode !== 'coaching');
|
bulk.classList.toggle('hidden', mode !== 'coaching');
|
||||||
|
reportAttachments.classList.toggle('hidden', mode === 'goal');
|
||||||
|
reportActions.classList.toggle('hidden', mode === 'goal');
|
||||||
|
goalActions.classList.toggle('hidden', mode !== 'goal');
|
||||||
if (mode !== 'coaching') bulkStatus.textContent = '';
|
if (mode !== 'coaching') bulkStatus.textContent = '';
|
||||||
error.textContent = '';
|
error.textContent = '';
|
||||||
}
|
}
|
||||||
@@ -312,7 +332,7 @@
|
|||||||
const data = {};
|
const data = {};
|
||||||
document.querySelectorAll(`#${mode} [name]`).forEach(field => { data[field.name] = field.value; });
|
document.querySelectorAll(`#${mode} [name]`).forEach(field => { data[field.name] = field.value; });
|
||||||
data.mode = mode;
|
data.mode = mode;
|
||||||
['escort_id', 'kitten_id', 'character_id', 'inspections'].forEach(key => { if (data[key] !== undefined && data[key] !== '') data[key] = Number(data[key]); });
|
['escort_id', 'kitten_id', 'character_id', 'inspections', 'current_points', 'target_points', 'minutes_per_session', 'kitten_count'].forEach(key => { if (data[key] !== undefined && data[key] !== '') data[key] = Number(data[key]); });
|
||||||
if (mode === 'inspection') {
|
if (mode === 'inspection') {
|
||||||
data.resources = (data.resources || '').split('\n').map(line => line.trim()).filter(Boolean).map(line => {
|
data.resources = (data.resources || '').split('\n').map(line => line.trim()).filter(Boolean).map(line => {
|
||||||
const match = line.match(/^\+\s*(\d+)\s+(.+)$/);
|
const match = line.match(/^\+\s*(\d+)\s+(.+)$/);
|
||||||
@@ -349,15 +369,18 @@
|
|||||||
if (statusError) throw new Error(statusError);
|
if (statusError) throw new Error(statusError);
|
||||||
}
|
}
|
||||||
const reportPayload = payload();
|
const reportPayload = payload();
|
||||||
reportPayload.attachments = await uploadScreenshots();
|
reportPayload.attachments = mode === 'goal' ? [] : await uploadScreenshots();
|
||||||
const response = await fetch('/api/calculate', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(reportPayload) });
|
const response = await fetch('/api/calculate', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(reportPayload) });
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (!response.ok) throw new Error(data.error || 'Ошибка калькулятора');
|
if (!response.ok) throw new Error(data.error || 'Ошибка калькулятора');
|
||||||
message.value = data.message; summary.textContent = data.result ? `Результат: ${JSON.stringify(data.result)}` : '';
|
message.value = data.message; summary.textContent = data.result ? `Результат: ${JSON.stringify(data.result)}` : '';
|
||||||
result.classList.remove('hidden'); copy.disabled = false;
|
result.classList.remove('hidden');
|
||||||
|
copy.disabled = mode === 'goal';
|
||||||
|
goalCopy.disabled = mode !== 'goal';
|
||||||
} catch (err) { error.textContent = err.message; }
|
} catch (err) { error.textContent = err.message; }
|
||||||
});
|
});
|
||||||
copy.addEventListener('click', async () => { await navigator.clipboard.writeText(message.value); copy.textContent = 'Скопировано'; setTimeout(() => copy.textContent = 'Скопировать', 1500); });
|
copy.addEventListener('click', async () => { await navigator.clipboard.writeText(message.value); copy.textContent = 'Скопировано'; setTimeout(() => copy.textContent = 'Скопировать', 1500); });
|
||||||
|
goalCopy.addEventListener('click', async () => { await navigator.clipboard.writeText(message.value); goalCopy.textContent = 'Скопировано'; setTimeout(() => goalCopy.textContent = 'Скопировать', 1500); });
|
||||||
|
|
||||||
const reportsSection = document.querySelector('#reportsSection');
|
const reportsSection = document.querySelector('#reportsSection');
|
||||||
const applicationsSection = document.querySelector('#applicationsSection');
|
const applicationsSection = document.querySelector('#applicationsSection');
|
||||||
@@ -464,6 +487,7 @@
|
|||||||
});
|
});
|
||||||
addApplicationFeather();
|
addApplicationFeather();
|
||||||
syncApplicationForm();
|
syncApplicationForm();
|
||||||
|
selectMode(mode);
|
||||||
setSection(new URLSearchParams(window.location.search).get('section') === 'applications' ? 'applications' : 'reports', false);
|
setSection(new URLSearchParams(window.location.search).get('section') === 'applications' ? 'applications' : 'reports', false);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in new issue
Block a user