Cambiando las opciones de fechas en buscador principal

master
vicsash 4 months ago
parent 3927234375
commit 31eed8f958

@ -200,6 +200,7 @@ public class BuscadorController {
@RequestParam(defaultValue = "") String secondaryOption, @RequestParam(defaultValue = "") String secondaryOption,
Model model) throws ParseException { Model model) throws ParseException {
System.out.println("Query: TEST " + query); System.out.println("Query: TEST " + query);
System.out.println("SecondaryOption: TEST " + secondaryOption);
String[] queryMultiWord = query.split(","); String[] queryMultiWord = query.split(",");
List<String> queryList = new ArrayList<>(); List<String> queryList = new ArrayList<>();
for (String queryForList : queryMultiWord) { for (String queryForList : queryMultiWord) {
@ -209,7 +210,7 @@ public class BuscadorController {
} }
} }
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50); List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
Page<Oferta> page = null; Page<Oferta> page;
if(queryMultiWord.length>1){ if(queryMultiWord.length>1){
page = ofertasService.getPageMultiWord(pageNum, size, sortField, sortDir, queryList, secondaryOption); page = ofertasService.getPageMultiWord(pageNum, size, sortField, sortDir, queryList, secondaryOption);

@ -28,18 +28,14 @@ import java.util.Set;
@Controller @Controller
public class UserController { public class UserController {
@Autowired @Autowired
private CicloService cicloService; private CicloService cicloService;
@Autowired @Autowired
private SkillService skillService; private SkillService skillService;
@Autowired @Autowired
private UsuarioService usuarioService; private UsuarioService usuarioService;
@Autowired @Autowired
private PasswordEncoder passwordEncoder; private PasswordEncoder passwordEncoder;
@Autowired @Autowired
private AlumnoService alumnoService; private AlumnoService alumnoService;
@ -122,20 +118,14 @@ public class UserController {
@GetMapping("/usuario/info") @GetMapping("/usuario/info")
public String showUserInfo(Model model, Authentication authentication) { public String showUserInfo(Model model, Authentication authentication) {
// Get the current user
String username = authentication.getName(); String username = authentication.getName();
Usuario usuario = usuarioService.findByLogInName(username); Usuario usuario = usuarioService.findByLogInName(username);
if(usuario.getRol().getId() ==1){ if(usuario.getRol().getId() ==1){
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "No tienes permisos para acceder a esta página"); throw new ResponseStatusException(HttpStatus.FORBIDDEN, "No tienes permisos para acceder a esta página");
} }
Alumno alumno = alumnoService.findByEmail(usuario.getEmail()); Alumno alumno = alumnoService.findByEmail(usuario.getEmail());
model.addAttribute("usuario", usuario); model.addAttribute("usuario", usuario);
model.addAttribute("alumno", alumno); model.addAttribute("alumno", alumno);
// Return the name of the view
return "user/info_user"; return "user/info_user";
} }
} }

@ -17,9 +17,8 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
import java.util.Collection; import java.text.SimpleDateFormat;
import java.util.List; import java.util.*;
import java.util.Set;
@Controller @Controller
@RequestMapping() @RequestMapping()
@ -132,4 +131,9 @@ public class OfertaController {
} }
} }
@GetMapping("api/distinct-years")
@ResponseBody
public List<Integer> getDistinctYears() {
return ofertaService.findDistinctYears();
}
} }

@ -52,17 +52,11 @@ public interface OfertaRepository extends JpaRepository<Oferta, Long> {
@Query("SELECT o FROM Oferta o WHERE o.nombre LIKE %:query%") @Query("SELECT o FROM Oferta o WHERE o.nombre LIKE %:query%")
Page<Oferta> findOfertaByNombre(String query, PageRequest of); Page<Oferta> findOfertaByNombre(String query, PageRequest of);
@Query("SELECT o FROM Oferta o WHERE o.fecha < :query")
Page<Oferta> findOfertaByFechaAntes(Date query, PageRequest of);
@Query("SELECT o FROM Oferta o WHERE o.fecha > :query")
Page<Oferta> findOfertaByFechaDespues(Date query, PageRequest of);
@Query("SELECT o FROM Oferta o WHERE o.sucursal.empresa.nombre LIKE %:query%") @Query("SELECT o FROM Oferta o WHERE o.sucursal.empresa.nombre LIKE %:query%")
Page<Oferta> findOfertaByEmpresa(@Param("query") String query, Pageable pageable); Page<Oferta> findOfertaByEmpresa(@Param("query") String query, Pageable pageable);
@Query(value = "SELECT * FROM ofertas o WHERE YEAR(o.fecha) = YEAR(:dateQuery)", nativeQuery = true) @Query(value = "SELECT * FROM ofertas o WHERE YEAR(o.fecha) = :yearQuery", nativeQuery = true)
Page<Oferta> findOfertaByFechaAnyo(@Param("dateQuery") Date dateQuery, Pageable pageable); Page<Oferta> findOfertaByFechaAnyo(@Param("yearQuery") Integer yearQuery, Pageable pageable);
@Query("SELECT o FROM Oferta o WHERE lower(o.nombre) IN :queryList") @Query("SELECT o FROM Oferta o WHERE lower(o.nombre) IN :queryList")
Page<Oferta> findOfertasByNombres(@Param("queryList") String queryList, Pageable pageable); Page<Oferta> findOfertasByNombres(@Param("queryList") String queryList, Pageable pageable);
@ -79,15 +73,12 @@ public interface OfertaRepository extends JpaRepository<Oferta, Long> {
@Query("SELECT o FROM Oferta o WHERE o.sucursal.empresa.nombre LIKE %:query%") @Query("SELECT o FROM Oferta o WHERE o.sucursal.empresa.nombre LIKE %:query%")
Collection<Oferta> ofertasByEmpresaCust(@Param("query") String query); Collection<Oferta> ofertasByEmpresaCust(@Param("query") String query);
@Query("SELECT o FROM Oferta o WHERE o.fecha < :query")
Collection<Oferta> ofertasByFechaAntesCust(@Param("query") Date query);
@Query("SELECT o FROM Oferta o WHERE o.fecha > :query")
Collection<Oferta> ofertasByFechaDespuesCust(@Param("query") Date query);
@Query("SELECT o FROM Oferta o JOIN o.skills s WHERE s.nombre LIKE %:query%") @Query("SELECT o FROM Oferta o JOIN o.skills s WHERE s.nombre LIKE %:query%")
Collection<Oferta> ofertasBySkillCust(@Param("query") String query); Collection<Oferta> ofertasBySkillCust(@Param("query") String query);
@Query(value = "SELECT * FROM ofertas o WHERE YEAR(o.fecha) = YEAR(:dateQuery)", nativeQuery = true) @Query(value = "SELECT * FROM ofertas o WHERE YEAR(o.fecha) = YEAR(:dateQuery)", nativeQuery = true)
Collection<? extends Oferta> ofertasByFechaAnyoCust(Date dateQuery); Collection<? extends Oferta> ofertasByFechaAnyoCust(Date dateQuery);
@Query(value = "SELECT DISTINCT YEAR(o.fecha) FROM ofertas o", nativeQuery = true)
List<Integer> findDistinctYears();
} }

@ -108,23 +108,19 @@ public class OfertaService implements IOferta {
} }
@Override @Override
public Page<Oferta> getPage(int pageNum, int size, String sortField, String sortDir, String query, String secondaryOption) throws ParseException { public Page<Oferta> getPage(int pageNum, int size, String sortField, String sortDir, String query, String secondaryOption) throws ParseException {
Date dateQuery = null; Integer yearQuery = null;
if(isDate(query)){ if(isYear(query)){
dateQuery = new SimpleDateFormat("yyyy-MM-dd").parse(query); yearQuery = Integer.parseInt(query);
System.out.println("Date query TEST: " + dateQuery); System.out.println("Year query TEST: " + yearQuery);
} }
if(secondaryOption.equalsIgnoreCase("Todo")){ if(secondaryOption.equalsIgnoreCase("Todo")){
return findAllPaginated(pageNum, size, sortField, sortDir); return findAllPaginated(pageNum, size, sortField, sortDir);
}else if (secondaryOption.equals("Skill")) { }else if (secondaryOption.equals("Skill")) {
return ofertaRepository.findOfertaBySkill(query, PageRequest.of(pageNum - 1, size, Sort.by(sortField).ascending())); return ofertaRepository.findOfertaBySkill(query, PageRequest.of(pageNum - 1, size, Sort.by(sortField).ascending()));
} else if(secondaryOption.equals("Nombre")) { } else if(secondaryOption.equals("Nombre")) {
return ofertaRepository.findOfertaByNombre(query, PageRequest.of(pageNum - 1, size, Sort.by(sortField).ascending())); return ofertaRepository.findOfertaByNombre(query, PageRequest.of(pageNum - 1, size, Sort.by(sortField).ascending()));
} else if(secondaryOption.equals("Fecha antes")) {
return ofertaRepository.findOfertaByFechaAntes(dateQuery, PageRequest.of(pageNum - 1, size, Sort.by(sortField).ascending()));
} else if(secondaryOption.equals("Fecha despues")) {
return ofertaRepository.findOfertaByFechaDespues(dateQuery, PageRequest.of(pageNum - 1, size, Sort.by(sortField).ascending()));
} else if(secondaryOption.equals("Año")) { } else if(secondaryOption.equals("Año")) {
return ofertaRepository.findOfertaByFechaAnyo(dateQuery, PageRequest.of(pageNum - 1, size, Sort.by(sortField).ascending())); return ofertaRepository.findOfertaByFechaAnyo(yearQuery, PageRequest.of(pageNum - 1, size, Sort.by(sortField).ascending()));
} else if(secondaryOption.equals("Empresa")) { } else if(secondaryOption.equals("Empresa")) {
return ofertaRepository.findOfertaByEmpresa(query, PageRequest.of(pageNum - 1, size, Sort.by(sortField).ascending())); return ofertaRepository.findOfertaByEmpresa(query, PageRequest.of(pageNum - 1, size, Sort.by(sortField).ascending()));
} else { } else {
@ -154,13 +150,12 @@ public class OfertaService implements IOferta {
return new PageImpl<>(allMatches.subList(start, end), PageRequest.of(pageNum - 1, size), allMatches.size()); return new PageImpl<>(allMatches.subList(start, end), PageRequest.of(pageNum - 1, size), allMatches.size());
} }
public boolean isDate(String query) { public boolean isYear(String query) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); // Adjust this to match the date format of your query
try { try {
Date date = formatter.parse(query); Integer.parseInt(query);
return true; // The query is a date return true;
} catch (ParseException e) { } catch (NumberFormatException e) {
return false; // The query is not a date return false;
} }
} }
@ -179,22 +174,7 @@ public class OfertaService implements IOferta {
listEmpPrime.addAll(ofertaRepository.ofertasByEmpresaCust(query)); listEmpPrime.addAll(ofertaRepository.ofertasByEmpresaCust(query));
} else if (secondaryOption.equals("Skill")) { } else if (secondaryOption.equals("Skill")) {
listEmpPrime.addAll(ofertaRepository.ofertasBySkillCust(query)); listEmpPrime.addAll(ofertaRepository.ofertasBySkillCust(query));
}else if(secondaryOption.equals("Fecha antes")){ }else if(secondaryOption.equals("Año")){
try {
Date dateQuery = new SimpleDateFormat("yyyy-MM-dd").parse(query);
listEmpPrime.addAll(ofertaRepository.ofertasByFechaAntesCust(dateQuery));
} catch (ParseException e) {
e.printStackTrace();
}
}else if(secondaryOption.equals("Fecha despues")){
try {
Date dateQuery = new SimpleDateFormat("yyyy-MM-dd").parse(query);
listEmpPrime.addAll(ofertaRepository.ofertasByFechaDespuesCust(dateQuery));
} catch (ParseException e) {
e.printStackTrace();
}
}else if(secondaryOption.equals("Año")){
try { try {
Date dateQuery = new SimpleDateFormat("yyyy-MM-dd").parse(query); Date dateQuery = new SimpleDateFormat("yyyy-MM-dd").parse(query);
listEmpPrime.addAll(ofertaRepository.ofertasByFechaAnyoCust(dateQuery)); listEmpPrime.addAll(ofertaRepository.ofertasByFechaAnyoCust(dateQuery));
@ -228,6 +208,7 @@ public class OfertaService implements IOferta {
} }
} }
} }
public List<Integer> findDistinctYears() {
return ofertaRepository.findDistinctYears();
}
} }

@ -47,9 +47,6 @@
justify-content: space-between; justify-content: space-between;
width: 100%; width: 100%;
} }
#date{
margin-top: 15px;
}
#user{ #user{
position: relative; position: relative;
margin-left: 50px; margin-left: 50px;
@ -120,14 +117,15 @@
<select id="secondaryDropdown"></select> <select id="secondaryDropdown"></select>
<input type="hidden" name="secondaryOption" id="hiddenSecondaryOption"> <input type="hidden" name="secondaryOption" id="hiddenSecondaryOption">
</div> </div>
<div id="date">
<input type="date" id="datePicker" name="query" style="display: none;"> <div id="yearDropdownContainer" style="display: none;">
<select id="yearDropdown"></select>
</div> </div>
</form> </form>
</div> </div>
<script> <script>
//MODAL
// Get the modal // Get the modal
var modal = document.getElementById("userModal"); var modal = document.getElementById("userModal");
// Get the button that opens the modal // Get the button that opens the modal
@ -225,80 +223,41 @@
} }
}); });
} }
$(document).ready(function() { $(document).ready(function() {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const userDeleted = urlParams.get('userDeleted'); const userDeleted = urlParams.get('userDeleted');
if (userDeleted === 'true') { if (userDeleted === 'true') {
alert('Usuario Borrado'); alert('Usuario Borrado');
userDeleted === 'false'; userDeleted === 'false';
} }
}); });
// Get reference to the date picker
var datePicker = document.getElementById('datePicker');
// Add an event listener to the date picker
datePicker.addEventListener('change', function() {
var searchBar = document.querySelector('input[name="query"]');
var secondaryOption = document.getElementById('secondaryDropdown').value;
// If the selected option is 'Fecha antes', 'Fecha despues', or 'Año', set the value of the search bar to the value of the date picker
if (['Fecha antes', 'Fecha despues', 'Año'].includes(secondaryOption)) {
searchBar.value = datePicker.value;
}
// Log the value of the search bar to the console
//console.log("Query: " + searchBar.value);
});
document.getElementById('searchForm').addEventListener('submit', function() { document.getElementById('searchForm').addEventListener('submit', function() {
var searchOption = document.getElementById('searchOption').value; var searchOption = document.getElementById('searchOption'); // Removed .value
var secondaryOption = document.getElementById('secondaryDropdown').value; var secondaryOption = document.getElementById('secondaryDropdown').value;
var datePicker = document.getElementById('datePicker');
var searchBar = document.querySelector('input[name="query"]');
// If the selected option is 'Fecha antes', 'Fecha despues', or 'Año', set the value of the search bar to the value of the date picker
if (['Fecha antes', 'Fecha despues', 'Año'].includes(secondaryOption)) {
searchBar.value = datePicker.value;
}
// Update the value of the hidden input field
document.getElementById('hiddenSecondaryOption').value = secondaryOption; document.getElementById('hiddenSecondaryOption').value = secondaryOption;
this.action = "/buscador/" + searchOption + "/page/1"; // Update the searchBar value to the selected year
if (secondaryOption === 'Año') {
searchBar.value = document.getElementById('yearDropdown').value;
console.log('searchBar.value after assignment: ', searchBar.value);
}
this.action = "/buscador/" + searchOption.value + "/page/1";
}); });
// Get references to the primary dropdown, the search bar, and the secondary dropdown
var primaryDropdown = document.getElementById('searchOption'); var primaryDropdown = document.getElementById('searchOption');
var searchBar = document.querySelector('input[name="query"]'); var searchBar = document.querySelector('input[name="query"]');
var secondaryDropdown = document.getElementById('secondaryDropdown'); var secondaryDropdown = document.getElementById('secondaryDropdown');
primaryDropdown.addEventListener('change', function() {
if (primaryDropdown.value === 'YourCondition') { // replace 'YourCondition' with the actual condition
secondaryDropdown.style.display = 'none';
} else {
secondaryDropdown.style.display = 'block';
}
});
secondaryDropdown.addEventListener('change', function() { secondaryDropdown.addEventListener('change', function() {
var datePicker = document.getElementById('datePicker'); if (secondaryDropdown.value === 'Todo') {
if (['Fecha antes', 'Fecha despues', 'Año'].includes(secondaryDropdown.value)) {
searchBar.value = '';
searchBar.disabled = true;
datePicker.style.display = 'block';
} else if (secondaryDropdown.value === 'Todo') {
searchBar.value = 'Todo'; searchBar.value = 'Todo';
searchBar.disabled = true; searchBar.disabled = true;
datePicker.style.display = 'none';
} else { } else {
searchBar.value = ''; searchBar.value = '';
searchBar.disabled = false; searchBar.disabled = false;
datePicker.style.display = 'none';
} }
}); });
primaryDropdown.addEventListener('change', function() { primaryDropdown.addEventListener('change', function() {
// Clear the secondary dropdown
secondaryDropdown.innerHTML = ''; secondaryDropdown.innerHTML = '';
// Determine what to add to the secondary dropdown based on the selected option of the primary dropdown // Determine what to add to the secondary dropdown based on the selected option of the primary dropdown
@ -314,7 +273,7 @@
options = ['Todo', 'Nombre', 'Empresa']; options = ['Todo', 'Nombre', 'Empresa'];
break; break;
case'ofertas': case'ofertas':
options = ['Todo', 'Nombre', 'Empresa','Fecha']; options = ['Todo', 'Nombre', 'Empresa','Año'];
break; break;
case'sucursales': case'sucursales':
options = ['Todo', 'Nombre', 'Empresa','Localidad']; options = ['Todo', 'Nombre', 'Empresa','Localidad'];
@ -338,50 +297,6 @@
//console.log("Primary dropdown value: " + primaryDropdown.value); // Add this line //console.log("Primary dropdown value: " + primaryDropdown.value); // Add this line
//console.log("Options to add to secondary dropdown: " + options); // Add this line //console.log("Options to add to secondary dropdown: " + options); // Add this line
// Add the new options to the secondary dropdown
for (var i = 0; i < options.length; i++) {
var option = document.createElement('option');
option.text = options[i];
secondaryDropdown.add(option);
}
});// Add an event listener to the primary dropdown
primaryDropdown.addEventListener('change', function() {
// Clear the secondary dropdown
secondaryDropdown.innerHTML = '';
// Determine what to add to the secondary dropdown based on the selected option of the primary dropdown
var options;
switch (primaryDropdown.value) {
case 'empresas':
options = ['Todo', 'Nombre', 'Sector','Keywords'];
break;
case 'sectores':
options = ['Todo'];
break;
case 'contactos':
options = ['Todo', 'Nombre', 'Empresa'];
break;
case'ofertas':
options = ['Todo', 'Nombre', 'Empresa','Fecha antes','Fecha despues','Año','Skill'];
break;
case'sucursales':
options = ['Todo', 'Nombre', 'Empresa','Localidad'];
break;
case'skills':
options = ['Todo'];
break;
case'familias':
options = ['Todo'];
break;
case'ciclos':
options = ['Todo','Familia','Codigo'];
break;
case'alumnos':
options = ['Todo', 'Nombre', 'Apellido','Ciclo','Keywords','Nia' ,'Dni'];
break;
default:
options = [];
}
// Add the new options to the secondary dropdown // Add the new options to the secondary dropdown
for (var i = 0; i < options.length; i++) { for (var i = 0; i < options.length; i++) {
var option = document.createElement('option'); var option = document.createElement('option');
@ -389,40 +304,74 @@
secondaryDropdown.add(option); secondaryDropdown.add(option);
} }
}); });
// Trigger the change event manually to populate the secondary dropdown when the page loads
primaryDropdown.dispatchEvent(new Event('change')); primaryDropdown.dispatchEvent(new Event('change'));
// Reset the form
document.querySelector('form').reset(); document.querySelector('form').reset();
// Set the value of the search bar to "Todo" and disable it
searchBar.value = 'Todo'; searchBar.value = 'Todo';
searchBar.disabled = true; searchBar.disabled = true;
function submitForm() { function submitForm() {
var searchOption = document.getElementById('searchOption').value; var searchOption = document.getElementById('searchOption');
var secondaryOption = document.getElementById('secondaryDropdown').value; var secondaryOption = document.getElementById('secondaryDropdown').value;
var datePicker = document.getElementById('datePicker'); document.getElementById('hiddenSecondaryOption').value = secondaryOption;
// Update the searchOption value to the selected year
// Update the searchBar value to the selected year
if (secondaryOption === 'Año') {
searchBar.value = document.getElementById('yearDropdown').value;
console.log('searchBar.value after assignment: ', searchBar.value);
}
this.action = "/buscador/" + searchOption.value + "/page/1";
return true;
}
////////////////////////////////////////DATE//////////////////////////////////////
// Fetch the distinct years from the server
// Fetch the distinct years from the server
fetch('/api/distinct-years')
.then(response => response.json()) // Convert the response to JSON
.then(years => {
// Get a reference to the yearDropdown select element
var yearDropdown = document.getElementById('yearDropdown');
// Remove any existing options in the dropdown
yearDropdown.innerHTML = '';
// Iterate over each year
years.forEach(year => {
// Create a new option element
var option = document.createElement('option');
option.value = year;
option.text = year;
// Append the option to the yearDropdown select element
yearDropdown.appendChild(option);
});
})
.catch(error => console.error('Error:', error));
// If the selected option is 'Fecha antes', 'Fecha despues', or 'Año', set the value of the search bar to the value of the date picker // Get a reference to the yearDropdownContainer div
if (['Fecha antes', 'Fecha despues', 'Año'].includes(secondaryOption)) {
datePicker.name = "query"; // Add an event listener to the secondaryDropdown select element
secondaryDropdown.addEventListener('change', function() {
// Check if the selected value is "Año"
if (secondaryDropdown.value === 'Año') {
// If it is, make the yearDropdownContainer visible
yearDropdownContainer.style.display = 'block';
searchBar.disabled = true;
} else { } else {
datePicker.name = ""; // If it's not, hide the yearDropdownContainer
yearDropdownContainer.style.display = 'none';
searchBar.disabled = false;
} }
});
// Log the query to the console var yearDropdown = document.getElementById('yearDropdown');
//console.log("Query SENT TEST: " + datePicker.value); var searchOption = document.getElementById('searchOption');
yearDropdown.addEventListener('change', function() {
searchBar.value = yearDropdown.value;
});
// Update the value of the hidden input field
document.getElementById('hiddenSecondaryOption').value = secondaryOption;
this.action = "/buscador/" + searchOption + "/page/1";
return true;
}
window.onload = function() {
primaryDropdown.dispatchEvent(new Event('change'));
};
</script> </script>
</body> </body>
</html> </html>

@ -121,9 +121,6 @@
<select id="secondaryDropdown"></select> <select id="secondaryDropdown"></select>
<input type="hidden" name="secondaryOption" id="hiddenSecondaryOption"> <input type="hidden" name="secondaryOption" id="hiddenSecondaryOption">
</div> </div>
<div id="date">
<input type="date" id="datePicker" name="query" style="display: none;">
</div>
</form> </form>
</div> </div>
@ -210,34 +207,9 @@
userUpdated === 'false'; userUpdated === 'false';
} }
}); });
// Get reference to the date picker
var datePicker = document.getElementById('datePicker');
// Add an event listener to the date picker
datePicker.addEventListener('change', function() {
var searchBar = document.querySelector('input[name="query"]');
var secondaryOption = document.getElementById('secondaryDropdown').value;
// If the selected option is 'Fecha antes', 'Fecha despues', or 'Año', set the value of the search bar to the value of the date picker
if (['Fecha antes', 'Fecha despues', 'Año'].includes(secondaryOption)) {
searchBar.value = datePicker.value;
}
// Log the value of the search bar to the console
//console.log("Query: " + searchBar.value);
});
document.getElementById('searchForm').addEventListener('submit', function() { document.getElementById('searchForm').addEventListener('submit', function() {
var searchOption = document.getElementById('searchOption').value; var searchOption = document.getElementById('searchOption').value;
var secondaryOption = document.getElementById('secondaryDropdown').value; var secondaryOption = document.getElementById('secondaryDropdown').value;
var datePicker = document.getElementById('datePicker');
var searchBar = document.querySelector('input[name="query"]');
// If the selected option is 'Fecha antes', 'Fecha despues', or 'Año', set the value of the search bar to the value of the date picker
if (['Fecha antes', 'Fecha despues', 'Año'].includes(secondaryOption)) {
searchBar.value = datePicker.value;
}
// Update the value of the hidden input field
document.getElementById('hiddenSecondaryOption').value = secondaryOption; document.getElementById('hiddenSecondaryOption').value = secondaryOption;
this.action = "/buscador/" + searchOption + "/page/1"; this.action = "/buscador/" + searchOption + "/page/1";
}); });
@ -246,34 +218,17 @@
var searchBar = document.querySelector('input[name="query"]'); var searchBar = document.querySelector('input[name="query"]');
var secondaryDropdown = document.getElementById('secondaryDropdown'); var secondaryDropdown = document.getElementById('secondaryDropdown');
primaryDropdown.addEventListener('change', function() {
if (primaryDropdown.value === 'YourCondition') { // replace 'YourCondition' with the actual condition
secondaryDropdown.style.display = 'none';
} else {
secondaryDropdown.style.display = 'block';
}
});
secondaryDropdown.addEventListener('change', function() { secondaryDropdown.addEventListener('change', function() {
var datePicker = document.getElementById('datePicker'); if (secondaryDropdown.value === 'Todo') {
if (['Fecha antes', 'Fecha despues', 'Año'].includes(secondaryDropdown.value)) {
searchBar.value = '';
searchBar.disabled = true;
datePicker.style.display = 'block';
} else if (secondaryDropdown.value === 'Todo') {
searchBar.value = 'Todo'; searchBar.value = 'Todo';
searchBar.disabled = true; searchBar.disabled = true;
datePicker.style.display = 'none';
} else { } else {
searchBar.value = ''; searchBar.value = '';
searchBar.disabled = false; searchBar.disabled = false;
datePicker.style.display = 'none';
} }
}); });
primaryDropdown.addEventListener('change', function() { primaryDropdown.addEventListener('change', function() {
// Clear the secondary dropdown
secondaryDropdown.innerHTML = ''; secondaryDropdown.innerHTML = '';
// Determine what to add to the secondary dropdown based on the selected option of the primary dropdown // Determine what to add to the secondary dropdown based on the selected option of the primary dropdown
@ -289,7 +244,7 @@
options = ['Todo', 'Nombre', 'Empresa']; options = ['Todo', 'Nombre', 'Empresa'];
break; break;
case'ofertas': case'ofertas':
options = ['Todo', 'Nombre', 'Empresa','Fecha']; options = ['Todo', 'Nombre', 'Empresa','Año'];
break; break;
case'sucursales': case'sucursales':
options = ['Todo', 'Nombre', 'Empresa','Localidad']; options = ['Todo', 'Nombre', 'Empresa','Localidad'];
@ -320,77 +275,18 @@
secondaryDropdown.add(option); secondaryDropdown.add(option);
} }
});// Add an event listener to the primary dropdown });// Add an event listener to the primary dropdown
primaryDropdown.addEventListener('change', function() {
// Clear the secondary dropdown
secondaryDropdown.innerHTML = '';
// Determine what to add to the secondary dropdown based on the selected option of the primary dropdown
var options;
switch (primaryDropdown.value) {
case 'empresas':
options = ['Todo', 'Nombre', 'Sector','Keywords'];
break;
case 'sectores':
options = ['Todo'];
break;
case 'contactos':
options = ['Todo', 'Nombre', 'Empresa'];
break;
case'ofertas':
options = ['Todo', 'Nombre', 'Empresa','Fecha antes','Fecha despues','Año','Skill'];
break;
case'sucursales':
options = ['Todo', 'Nombre', 'Empresa','Localidad'];
break;
case'skills':
options = ['Todo'];
break;
case'familias':
options = ['Todo'];
break;
case'ciclos':
options = ['Todo','Familia','Codigo'];
break;
case'alumnos':
options = ['Todo', 'Nombre', 'Apellido','Ciclo','Keywords','Nia' ,'Dni'];
break;
default:
options = [];
}
// Add the new options to the secondary dropdown
for (var i = 0; i < options.length; i++) {
var option = document.createElement('option');
option.text = options[i];
secondaryDropdown.add(option);
}
});
// Trigger the change event manually to populate the secondary dropdown when the page loads // Trigger the change event manually to populate the secondary dropdown when the page loads
primaryDropdown.dispatchEvent(new Event('change')); primaryDropdown.dispatchEvent(new Event('change'));
// Reset the form // Reset the form
document.querySelector('form').reset(); document.querySelector('form').reset();
// Set the value of the search bar to "Todo" and disable it
searchBar.value = 'Todo'; searchBar.value = 'Todo';
searchBar.disabled = true; searchBar.disabled = true;
function submitForm() { function submitForm() {
var searchOption = document.getElementById('searchOption').value; var searchOption = document.getElementById('searchOption').value;
var secondaryOption = document.getElementById('secondaryDropdown').value; var secondaryOption = document.getElementById('secondaryDropdown').value;
var datePicker = document.getElementById('datePicker');
// If the selected option is 'Fecha antes', 'Fecha despues', or 'Año', set the value of the search bar to the value of the date picker
if (['Fecha antes', 'Fecha despues', 'Año'].includes(secondaryOption)) {
datePicker.name = "query";
} else {
datePicker.name = "";
}
// Log the query to the console
//console.log("Query SENT TEST: " + datePicker.value);
// Update the value of the hidden input field
document.getElementById('hiddenSecondaryOption').value = secondaryOption; document.getElementById('hiddenSecondaryOption').value = secondaryOption;
this.action = "/buscador/" + searchOption + "/page/1"; this.action = "/buscador/" + searchOption + "/page/1";
return true; return true;

Loading…
Cancel
Save

Powered by INFORMATICA.FP.EDU.ES.