aktiiviset haut muokkauksen parannus

This commit is contained in:
Tontze
2026-06-28 13:45:43 +03:00
parent a3939a173f
commit 830410b1ac
5 changed files with 100 additions and 33 deletions
+74 -30
View File
@@ -118,6 +118,8 @@
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
let muokattavaIndex = null;
function rullaaLokiAlas() {
const lokit = ['loki-sisalto', 'skripti-loki'];
lokit.forEach(id => {
@@ -167,7 +169,9 @@
}).join('');
const iList = document.getElementById('indexer-lista');
iList.innerHTML = (data.indeksorit || []).map((idx, i) => `<li class="list-group-item d-flex justify-content-between py-1">${idx}<button onclick="poistaIndexer(${i})" class="btn btn-danger btn-sm py-0">Poista</button></li>`).join('');
iList.innerHTML = (data.indeksorit || []).map((idx, i) =>
`<li class="list-group-item d-flex justify-content-between py-1">${idx}<button onclick="poistaIndexer(${i})" class="btn btn-danger btn-sm py-0">Poista</button></li>`
).join('');
document.getElementById('skripti-loki').innerText = data.loki_skripti;
document.getElementById('cfg-url').value = data.asetukset.jackett_url || '';
@@ -181,6 +185,32 @@
});
}
function muokkaaKohdetta(i) {
fetch('/status')
.then(res => res.json())
.then(data => {
const kohde = data.hakukohteet[i];
muokattavaIndex = i;
document.getElementById('haku-sana').value = kohde.jackett_haku;
document.getElementById('haku-kansio').value = kohde.kohdekansio;
[0, 1, 2, 3, 4, 5, 6].forEach(p => {
const cb = document.getElementById('pv-' + p);
if (cb) cb.checked = kohde.paivat.includes(p);
});
document.querySelector('#lisaa-form button[type="submit"]').textContent = 'Päivitä haku';
window.scrollTo({ top: 0, behavior: 'smooth' });
});
}
function resetLomake() {
muokattavaIndex = null;
document.getElementById('lisaa-form').reset();
document.querySelector('#lisaa-form button[type="submit"]').textContent = 'Lisää';
}
function poistaHist(riviTeksti) {
if(confirm("Poistetaanko tämä rivi historiasta?")) {
fetch('/poista_historiarivi', {
@@ -194,46 +224,60 @@
function lisaaIndexer() { const val = document.getElementById('uusi-indexer').value; if(!val) return; fetch('/status').then(r => r.json()).then(d => { let l = d.indeksorit || []; l.push(val); fetch('/paivita_indeksorit', {method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({indeksorit:l})}).then(() => paivitaNakyma()); }); }
function poistaIndexer(i) { fetch('/status').then(r => r.json()).then(d => { let l = d.indeksorit; l.splice(i, 1); fetch('/paivita_indeksorit', {method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({indeksorit:l})}).then(() => paivitaNakyma()); }); }
function poistaKohde(i) { fetch(`/poista_kohde/${i}`, {method:'DELETE'}).then(() => paivitaNakyma()); }
document.getElementById('lisaa-form').addEventListener('submit', (e) => {
e.preventDefault();
const paivat = [0,1,2,3,4,5,6].filter(i => document.getElementById('pv-'+i).checked);
fetch('/lisaa_kohde', {
const payload = {
jackett_haku: document.getElementById('haku-sana').value,
regex_suodatin: document.getElementById('haku-regex').value,
kohdekansio: document.getElementById('haku-kansio').value,
paivat: paivat
};
if (muokattavaIndex !== null) {
fetch(`/paivita_kohde/${muokattavaIndex}`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(payload)
}).then(() => {
resetLomake();
paivitaNakyma();
});
} else {
fetch('/lisaa_kohde', {
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify(payload)
}).then(() => {
resetLomake();
paivitaNakyma();
});
}
});
document.getElementById('asetukset-form').addEventListener('submit', (e) => {
e.preventDefault();
fetch('/tallenna_asetukset', {
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({
jackett_haku: document.getElementById('haku-sana').value,
regex_suodatin: document.getElementById('haku-regex').value,
kohdekansio: document.getElementById('haku-kansio').value,
paivat: paivat
jackett_url:document.getElementById('cfg-url').value,
jackett_api_key:document.getElementById('cfg-apikey').value,
qbit_url:document.getElementById('cfg-qbiturl').value,
qbit_user:document.getElementById('cfg-qbituser').value,
qbit_pass:document.getElementById('cfg-qbitpass').value,
haku_vali:document.getElementById('cfg-interval').value
})
}).then(() => { e.target.reset(); paivitaNakyma(); });
}).then(() => paivitaNakyma());
});
document.getElementById('asetukset-form').addEventListener('submit', (e) => { e.preventDefault(); fetch('/tallenna_asetukset', {method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({jackett_url:document.getElementById('cfg-url').value, jackett_api_key:document.getElementById('cfg-apikey').value, qbit_url:document.getElementById('cfg-qbiturl').value, qbit_user:document.getElementById('cfg-qbituser').value, qbit_pass:document.getElementById('cfg-qbitpass').value, haku_vali:document.getElementById('cfg-interval').value})}).then(() => paivitaNakyma()); });
document.getElementById('suorita-haku-btn').addEventListener('click', () => fetch('/suorita_haku', {method:'POST'}));
document.getElementById('tyhjenna-loki-btn').addEventListener('click', () => fetch('/tyhjenna_loki', {method:'POST'}).then(() => paivitaNakyma()));
paivitaNakyma(); setInterval(paivitaNakyma, 5000);
function muokkaaKohdetta(i) {
fetch('/status')
.then(res => res.json())
.then(data => {
const kohde = data.hakukohteet[i];
// Täytetään lomake hakukohteen tiedoilla
document.getElementById('haku-sana').value = kohde.jackett_haku;
document.getElementById('haku-kansio').value = kohde.kohdekansio;
// Päivitetään checkboxit
[0, 1, 2, 3, 4, 5, 6].forEach(p => {
const cb = document.getElementById('pv-' + p);
if (cb) cb.checked = kohde.paivat.includes(p);
});
// Vieritetään sivu takaisin ylös lomakkeeseen
window.scrollTo(0, 0);
});
}
paivitaNakyma();
setInterval(paivitaNakyma, 5000);
</script>
</body>
</html>