Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
Fix CSS and Insert function to search previous journals stored in github database
  • Loading branch information
folk-digital authored Jul 2, 2024
1 parent dee9c77 commit 0e77257
Showing 1 changed file with 64 additions and 3 deletions.
67 changes: 64 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
padding: 5px;
margin: 5px;
border: 1px solid gray;
&:first-child {
text-align: center
& p:first-child {
text-align: center;
a {
background-color: bisque;
}
Expand All @@ -45,13 +45,33 @@
</style>

<script>

(async () => {
dodf = await fetch("https://dodf.df.gov.br/index/jornal-json").then(r => r.json())
document.getElementById('termos').value = "Políticas Públicas e Gestão Governamental"
document.getElementById("btnSearch").click()

journals = await fetch('https://api.github.com/repos/folk-digital/dodf/contents/data')
.then(r => r.json())
.then(j => j.filter(e => e.name.endsWith('.json')))
.then(f => f.map(e => e.path))
journals.forEach(path => document.getElementById('journals').insertAdjacentHTML('beforeend',`<option selected=true value="${path}">${path.split('/')[1]}</option>`))
})();

var checkbox_alljournals = document.getElementById('alljournals');

checkbox_alljournals.addEventListener('change', function() {
if (this.checked) {
console.log("Checkbox is checked..");
queryJournals = [...document.querySelectorAll('#journals option:checked')].map(o => o.value)
console.log(queryJournals)
} else {
console.log("Checkbox is not checked..");
}
});



function searchDODF() {
const txt = document.getElementById('termos').value

Expand Down Expand Up @@ -84,6 +104,47 @@
alert("Insira os TERMOS da pesquisa!")
}

}

function searchDODFPrev() {
const txt = document.getElementById('termos').value

if (txt !== "") {
document.getElementById("resultado").innerHTML = ""
for (const [idx, url] of queryJournals.entries()) {
const dodf = await fetch(url).then(r => r.json());
// console.log(`Received Todo ${idx+1}:`, todo);
let counter = 0
Object.values(dodf.json.INFO)
.forEach(sessao => Object.values(sessao)
.forEach(org => Object.values(org.documentos)
.forEach(doc => {
if (doc.texto.includes(txt)) {
counter++
doc.texto.replaceAll(txt, `<span style="background-color: yellow;">${txt}</span>`)
// console.log(doc.texto)
document.getElementById('resultado').insertAdjacentHTML('beforeend', `
<article>
<p><a href="https://${dodf.json.linkJornal}" target="blank_">${dodf.json.tituloSangria}</a></p>
${doc.texto}
</article>`)
}
})))
if (counter == 0) {
document.querySelector("#NadaPesquisado p").innerText = "Nenhum resultado encontrado!"
} else {
document.body.innerHTML = document.body.innerHTML.replaceAll(txt, `<span style="background-color: yellow;">${txt}</span>`)
console.log(`${dodf.json.tituloSangria} => ${counter} resultados encontrados!`)
}
}

console.log('Finished!');
} else {
console.log("Input VAZIO!")
document.querySelector("#NadaPesquisado p").innerText = "Input VAZIO!"
alert("Insira os TERMOS da pesquisa!")
}

}
</script>

Expand Down

0 comments on commit 0e77257

Please sign in to comment.