feat: add support for later forecasts and implement force update functionality for rules

This commit is contained in:
Giuseppe Raffa
2026-04-16 08:14:10 +02:00
parent c0be21a718
commit edd7226966
8 changed files with 481 additions and 20 deletions

View File

@@ -18,6 +18,7 @@
<h1>Rulesets</h1>
<div class="rs-type-picker" id="typePicker">
<button class="active" data-type="weather">Weather</button>
<button data-type="laterforecasts">Forecasts</button>
<button data-type="data">Data</button>
<button data-type="logs">Logs</button>
</div>
@@ -39,6 +40,7 @@
</select>
</div>
<div class="rs-toolbar-right">
<button class="rs-force-btn" id="forceUpdateBtn">Forza Update Sensori</button>
<button class="rs-new-btn" id="newRuleBtn">+ Nuova Rule</button>
</div>
</div>
@@ -136,6 +138,12 @@ const ITEM_SCHEMA = {
{ key: 'name', label: 'Nome', cls: 'wide' },
{ key: 'unit', label: 'Unita', cls: 'narrow' },
],
laterforecasts: [
{ key: 'group_name', label: 'Gruppo', cls: 'medium' },
{ key: 'ref', label: 'Ref', cls: 'medium' },
{ key: 'name', label: 'Nome', cls: 'wide' },
{ key: 'unit', label: 'Unita', cls: 'narrow' },
],
data: [
{ key: 'category', label: 'Categoria', cls: 'medium' },
{ key: 'path', label: 'Path', cls: 'wide' },
@@ -149,7 +157,7 @@ const ITEM_SCHEMA = {
],
};
const HAS_DESC = { weather: true, data: false, logs: true };
const HAS_DESC = { weather: true, laterforecasts: true, data: false, logs: true };
// ========== API helpers ==========
@@ -583,6 +591,30 @@ function flash(text, elId = 'savingIndicator') {
setTimeout(() => el.classList.remove('visible'), 1500);
}
// ========== Force Update ==========
document.getElementById('forceUpdateBtn').onclick = async () => {
const btn = document.getElementById('forceUpdateBtn');
btn.disabled = true;
btn.textContent = 'Invio in corso...';
try {
const res = await api('POST', '/rules/force-update');
btn.textContent = `Inviato a ${res.sensors || 0} sensori`;
flash('Update inviato');
setTimeout(() => {
btn.textContent = 'Forza Update Sensori';
btn.disabled = false;
}, 3000);
} catch (err) {
console.error('Error force-updating:', err);
btn.textContent = 'Errore!';
setTimeout(() => {
btn.textContent = 'Forza Update Sensori';
btn.disabled = false;
}, 3000);
}
};
// ========== Init ==========
document.addEventListener('DOMContentLoaded', () => loadRules());

View File

@@ -135,6 +135,33 @@
background-position: right 10px center;
}
/* Force Update button */
.rs-force-btn {
padding: 8px 20px;
border: 1px solid #f59e0b;
border-radius: 10px;
background: #fffbeb;
color: #b45309;
font-size: 0.85rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
font-family: inherit;
}
.rs-force-btn:hover:not(:disabled) {
background: #fef3c7;
border-color: #d97706;
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
}
.rs-force-btn:disabled {
opacity: 0.7;
cursor: not-allowed;
transform: none;
}
.rs-new-btn {
padding: 8px 20px;
border: none;