Skip to content

Commit

Permalink
aggiunto funzionalità di ricerca a gestione classi e aule
Browse files Browse the repository at this point in the history
  • Loading branch information
nkoexe committed Jul 16, 2024
1 parent 682d9ec commit 119aecb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
24 changes: 23 additions & 1 deletion sostituzioni/view/static/scripts/gestione_impostazioni/aule.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const aula_template = `<div class="aula">
<button class="material-symbols-rounded pulsante-conferma-modifiche-dato hidden">check_circle</button>
</div>`

const ui_cerca_aula = document.querySelector("#cerca-aula-input")
const ui_lista_aule = document.querySelector("#lista-aule")
let lista_selezioni_piano = []
let lista_tag_piani = new Set()
Expand All @@ -28,7 +29,6 @@ function crea_elemento(aula) {
input_numero_aula.value = aula[0]
input_numero_aula.oninput = () => modificato(aula[0])
const input_piano_aula = element.querySelector(".input-piano")
// input_piano_aula.value = aula[1]
input_piano_aula.oninput = () => modificato(aula[0])

element.querySelector(".pulsante-elimina-dato").onclick = () => ui_elimina_aula(aula[0])
Expand All @@ -55,6 +55,28 @@ aule.forEach(aula => {
lista_selezioni_piano.push(selezione_piano)
})

function cerca_aula() {
let query = ui_cerca_aula.value.toLowerCase()

if (query == "") {
ui_lista_aule.querySelectorAll(".opzione-aula").forEach(element => {
element.classList.remove("hidden")
})
return
}

ui_lista_aule.querySelectorAll(".opzione-aula").forEach(element => {
const aula = element.querySelector(".input-numero-aula").value.toLowerCase()
const piano = element.querySelector(".input-piano").value.toLowerCase()
if ((aula + " " + piano).includes(query) || (piano + " " + aula).includes(query)) {
element.classList.remove("hidden")
} else {
element.classList.add("hidden")
}
})
}


function modificato(numero_aula) {
const element = Array.from(document.querySelectorAll(".opzione-aula"))
.find(element => element.dataset.numero_aula === numero_aula)
Expand Down
24 changes: 24 additions & 0 deletions sostituzioni/view/static/scripts/gestione_impostazioni/classi.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const classe_template = `<div class="classe">
<button class="material-symbols-rounded pulsante-conferma-modifiche-dato hidden">check_circle</button>
</div>`

const ui_cerca_classe = document.querySelector("#cerca-classe-input")
const ui_lista_classi = document.querySelector("#lista-classi")

function crea_elemento(classe) {
Expand Down Expand Up @@ -53,6 +54,29 @@ classi.forEach(classe => {
}
})

function cerca_classe() {
const query = document.querySelector("#cerca-classe-input").value.toLowerCase()

if (query == "") {
ui_lista_classi.querySelectorAll(".opzione-classe").forEach(element => {
element.classList.remove("hidden")
})
return
}

ui_lista_classi.querySelectorAll(".opzione-classe").forEach(element => {
const nome_classe = element.querySelector(".input-nome-classe").value.toLowerCase()
const nome_classe_nowhitespace = nome_classe.replace(/\s/g, "")
const aula = element.querySelector(".input-aula").value.toLowerCase()
if (nome_classe_nowhitespace.includes(query) || nome_classe.includes(query) || aula.startsWith(query)) {
element.classList.remove("hidden")
} else {
element.classList.add("hidden")
}
})
}


function modificato(nome_classe) {
const element = Array.from(document.querySelectorAll(".opzione-classe"))
.find(element => element.dataset.nome_classe === nome_classe)
Expand Down
4 changes: 4 additions & 0 deletions sostituzioni/view/templates/gestione_impostazioni/aule.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<div class="gestione-dati-nuovo-container">
<button class="pulsante gestione-dati-pulsante-nuovo" onclick="nuova_aula()"><span class="icon material-symbols-rounded">add</span><span>Aggiungi Aula</span></button>
</div>
<div id="cerca-aula-container" class="gestione-dati-cerca-container">
<input type="text" id="cerca-aula-input" placeholder="Cerca" oninput="cerca_aula()">
<button class="gestione-dati-pulsante-cerca" onclick="cerca_aula()"><span class="icon material-symbols-rounded">search</span></button>
</div>
</div>
<div id="lista-aule" class="gestione-dati-lista"></div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions sostituzioni/view/templates/gestione_impostazioni/classi.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<div class="gestione-dati-nuovo-container">
<button class="pulsante gestione-dati-pulsante-nuovo" onclick="nuova_classe()"><span class="icon material-symbols-rounded">add</span><span>Aggiungi Classe</span></button>
</div>
<div id="cerca-classe-container" class="gestione-dati-cerca-container">
<input type="text" id="cerca-classe-input" placeholder="Cerca" oninput="cerca_classe()">
<button class="gestione-dati-pulsante-cerca" onclick="cerca_classe()"><span class="icon material-symbols-rounded">search</span></button>
</div>
</div>
<div id="lista-classi" class="gestione-dati-lista"></div>
</div>
Expand Down

0 comments on commit 119aecb

Please sign in to comment.