diff --git a/src/main/java/com/example/proyectofinal/configuration/database/DatabaseTest.java b/src/main/java/com/example/proyectofinal/configuration/database/DatabaseTest.java index a7f5c32..fc74914 100644 --- a/src/main/java/com/example/proyectofinal/configuration/database/DatabaseTest.java +++ b/src/main/java/com/example/proyectofinal/configuration/database/DatabaseTest.java @@ -96,16 +96,16 @@ public class DatabaseTest { ); ofertaRepository.save(oferta); } - JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); - jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON empresas(keywords,nombre)"); - jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON alumnos(keywords,nombre,apellido,apellido2,dni,nia,correo,correo2,nacionalidad,genero)"); - jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON ofertas(nombre,fecha)"); - jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON sucursales(nombre,localidad,direccion)"); - jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON sectores(nombre)"); - jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON ciclos(nombre)"); - jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON familias(nombre)"); - jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON skills(nombre)"); - jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON contactos(nombre,apellido,apellido2,correo,telefono)"); +// JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); +// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON empresas(keywords,nombre)"); +// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON alumnos(keywords,nombre,apellido,apellido2,dni,nia,correo,correo2,nacionalidad,genero)"); +// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON ofertas(nombre,fecha)"); +// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON sucursales(nombre,localidad,direccion)"); +// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON sectores(nombre)"); +// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON ciclos(nombre)"); +// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON familias(nombre)"); +// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON skills(nombre)"); +// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON contactos(nombre,apellido,apellido2,correo,telefono)"); }; } diff --git a/src/main/java/com/example/proyectofinal/controllers/BuscadorController.java b/src/main/java/com/example/proyectofinal/controllers/BuscadorController.java index 4522b8a..7fdadf1 100644 --- a/src/main/java/com/example/proyectofinal/controllers/BuscadorController.java +++ b/src/main/java/com/example/proyectofinal/controllers/BuscadorController.java @@ -47,106 +47,108 @@ public class BuscadorController { String[] word = query.split("\\b(y|o)\\b|[,/]"); if (searchOption.equals("OptEmpresa")) { if(word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")){ - Set empresas = new HashSet<>(empressaRepository.findAll()); + ArrayList empresas = new ArrayList<>(empressaRepository.findAllAsc()); model.addAttribute("empresas", empresas); - return "/list/list_empresas"; - } - System.out.println("Buscando empresas"); - if(word.length == 1){ - Set empresas = new HashSet<>(empressaRepository.getEmpressaByKeywordsOrName(word[0])); - model.addAttribute("empresas", empresas); - return "/list/list_empresas"; - }else if(word.length == 2){ - Set empresas = new HashSet<>(empressaRepository.getEmpressaByKeywordsOrName(word[0])); - empresas.addAll(empressaRepository.getEmpressaByKeywordsOrName(word[1])); - model.addAttribute("empresas", empresas); - return "/list/list_empresas"; + return "/list/empresas"; } +// if(word.length == 1){ +// ArrayList empresas = new ArrayList<>(empressaRepository.getEmpressaByKeywordsOrName(word[0])); +// model.addAttribute("empresas", empresas); +// return "/list/empresas"; +// }else if(word.length == 2){ +// ArrayList empresas = new ArrayList<>(empressaRepository.getEmpressaByKeywordsOrName(word[0])); +// empresas.addAll(empressaRepository.getEmpressaByKeywordsOrName(word[1])); +// model.addAttribute("empresas", empresas); +// return "/list/empresas"; +// } } else if (searchOption.equals("OptAlumno")) { if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todos")) { - Set alumnos = new HashSet<>(alumnoRepository.findAll()); + ArrayList alumnos = new ArrayList<>(alumnoRepository.findAll()); model.addAttribute("alumnos", alumnos); - return "/list/list_alumnos"; - } - if (word.length == 1) { - System.out.println("Buscando alumnos"); - Set alumnos = new HashSet<>(alumnoRepository.getAlumnoByKeywordsOrName(word[0])); - model.addAttribute("alumnos", alumnos); - return "/list/list_alumnos"; - } else if (word.length == 2) { - System.out.println("Buscando alumnos"); - Set alumnos = new HashSet<>(alumnoRepository.getAlumnoByKeywordsOrName(word[0])); - alumnos.addAll(alumnoRepository.getAlumnoByKeywordsOrName(word[1])); - model.addAttribute("alumnos", alumnos); - return "/list/list_alumnos"; + return "/list/alumnos"; } +// if (word.length == 1) { +// System.out.println("Buscando alumnos"); +// ArrayList alumnos = new ArrayList<>(alumnoRepository.getAlumnoByKeywordsOrName(word[0])); +// model.addAttribute("alumnos", alumnos); +// return "/list/alumnos"; +// } else if (word.length == 2) { +// System.out.println("Buscando alumnos"); +// ArrayList alumnos = new ArrayList<>(alumnoRepository.getAlumnoByKeywordsOrName(word[0])); +// alumnos.addAll(alumnoRepository.getAlumnoByKeywordsOrName(word[1])); +// model.addAttribute("alumnos", alumnos); +// return "/list/alumnos"; +// } }else if(searchOption.equals("OptOferta")) { if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) { - Set ofertas = new HashSet<>(ofertaRepository.findAll()); - model.addAttribute("ofertas", ofertas); - return "/list/list_ofertas"; - } - if (word.length == 1) { - Set ofertas = new HashSet<>(ofertaRepository.getOfertaFullTextSeach(word[0])); - model.addAttribute("ofertas", ofertas); - return "/list/list_ofertas"; - } else if (word.length == 2) { - Set ofertas = new HashSet<>(ofertaRepository.getOfertaFullTextSeach(word[0])); - ofertas.addAll(ofertaRepository.getOfertaFullTextSeach(word[1])); + ArrayList ofertas = new ArrayList<>(ofertaRepository.findAll()); model.addAttribute("ofertas", ofertas); - return "/list/list_ofertas"; + return "/list/ofertas"; } +// if (word.length == 1) { +// ArrayList ofertas = new ArrayList<>(ofertaRepository.getOfertaFullTextSeach(word[0])); +// model.addAttribute("ofertas", ofertas); +// return "/list/ofertas"; +// } else if (word.length == 2) { +// ArrayList ofertas = new ArrayList<>(ofertaRepository.getOfertaFullTextSeach(word[0])); +// ofertas.addAll(ofertaRepository.getOfertaFullTextSeach(word[1])); +// model.addAttribute("ofertas", ofertas); +// return "/list/ofertas"; +// } } else if (searchOption.equals("OptSector")) { if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) { - Set sectores = new HashSet<>(sectorRepository.findAll()); + ArrayList sectores = new ArrayList<>(sectorRepository.findAll()); model.addAttribute("sectores", sectores); - return "/list/list_sectores"; + return "/list/sectores"; } else { Sector sector = sectorRepository.findByNombre(word[0]); model.addAttribute("sectores", sector); - return "/list/list_sectores"; + return "/list/sectores"; } }else if(searchOption.equals("OptSucursal")) { if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) { - Set sucursalSet = new HashSet<>(sucursalRepository.findAll()); - model.addAttribute("sucursales", sucursalSet); - return "/list/list_sucursales"; - } else { - Set sucursalSet = new HashSet<>(sucursalRepository.getSucursalFullTextSeach(word[0])); + ArrayList sucursalSet = new ArrayList<>(sucursalRepository.findAll()); model.addAttribute("sucursales", sucursalSet); - return "/list/list_sucursales"; + return "/list/sucursales"; } +// } else { +// ArrayList sucursalSet = new ArrayList<>(sucursalRepository.getSucursalFullTextSeach(word[0])); +// model.addAttribute("sucursales", sucursalSet); +// return "/list/sucursales"; +// } }else if(searchOption.equals("OptSkill")){ if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) { - Set skills = new HashSet<>(skillRepository.findAll()); + ArrayList skills = new ArrayList<>(skillRepository.findAll()); model.addAttribute("skills", skills); - return "/list/list_skills"; - }else{ - Set skills = new HashSet<>(skillRepository.getSkillFullTextSeach(word[0])); - model.addAttribute("skills", skills); - return "/list/list_skills"; + return "/list/skills"; } +// else{ +// ArrayList skills = new ArrayList<>(skillRepository.getSkillFullTextSeach(word[0])); +// model.addAttribute("skills", skills); +// return "/list/skills"; +// } }else if(searchOption.equals("OptContactos")) { if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) { - Set contactos = new HashSet<>(contactoRepository.findAll()); - model.addAttribute("contactos", contactos); - return "/list/list_contactos"; - } else { - Set contactos = new HashSet<>(contactoRepository.getContactoFullTextSeach(word[0])); + ArrayList contactos = new ArrayList<>(contactoRepository.findAll()); model.addAttribute("contactos", contactos); - return "/list/list_contactos"; + return "/list/contactos"; } +// else { +// ArrayList contactos = new ArrayList<>(contactoRepository.getContactoFullTextSeach(word[0])); +// model.addAttribute("contactos", contactos); +// return "/list/contactos"; +// } }else if(searchOption.equals("OptFamilias")) { if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) { - Set familias = new HashSet<>(familiaRepository.findAll()); + ArrayList familias = new ArrayList<>(familiaRepository.findAll()); model.addAttribute("familias", familias); - return "/list/list_familias"; + return "/list/familias"; } }else if(searchOption.equals("OptCiclos")){ if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) { - Set ciclos = new HashSet<>(cicloRepository.findAll()); + ArrayList ciclos = new ArrayList<>(cicloRepository.findAll()); model.addAttribute("ciclos", ciclos); - return "/list/list_ciclos"; + return "/list/ciclos"; } }else{ System.out.println("ERROR EN BUSQUEDA DE UNA PALABRA"); diff --git a/src/main/java/com/example/proyectofinal/controllers/modelControllers/EmpressaController.java b/src/main/java/com/example/proyectofinal/controllers/modelControllers/EmpressaController.java index 6f7cc31..88f90c2 100644 --- a/src/main/java/com/example/proyectofinal/controllers/modelControllers/EmpressaController.java +++ b/src/main/java/com/example/proyectofinal/controllers/modelControllers/EmpressaController.java @@ -2,6 +2,7 @@ package com.example.proyectofinal.controllers.modelControllers; import com.example.proyectofinal.models.empresas.Contacto; import com.example.proyectofinal.repositories.empresas.ContactoRepository; +import com.example.proyectofinal.repositories.empresas.EmpressaRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -13,15 +14,17 @@ import java.util.HashSet; import java.util.Set; @Controller -@RequestMapping("/empresa") +@RequestMapping("/empresas") public class EmpressaController { @Autowired private ContactoRepository contactoRepository; + @Autowired + private EmpressaRepository empressaRepository; @GetMapping("/{id}") public String getEmpressaBySector(@PathVariable Long id, Model model) { Set contactoSet = new HashSet<>(contactoRepository.findBySector(id)); model.addAttribute("contactos", contactoSet); - return "/list/list_contactos"; + return "contactos"; } } diff --git a/src/main/java/com/example/proyectofinal/controllers/modelControllers/FamiliaController.java b/src/main/java/com/example/proyectofinal/controllers/modelControllers/FamiliaController.java index b2939de..4927540 100644 --- a/src/main/java/com/example/proyectofinal/controllers/modelControllers/FamiliaController.java +++ b/src/main/java/com/example/proyectofinal/controllers/modelControllers/FamiliaController.java @@ -39,6 +39,6 @@ public class FamiliaController { public String getFamiliaById(@PathVariable Long id, Model model) { Set cicloSet = new HashSet<>(cicloRepository.findCicloByFamiliaId(id)); model.addAttribute("ciclos", cicloSet); - return "/list/list_ciclo"; + return "ciclo"; } } diff --git a/src/main/java/com/example/proyectofinal/controllers/modelControllers/SectorController.java b/src/main/java/com/example/proyectofinal/controllers/modelControllers/SectorController.java index 290be6e..fc360a2 100644 --- a/src/main/java/com/example/proyectofinal/controllers/modelControllers/SectorController.java +++ b/src/main/java/com/example/proyectofinal/controllers/modelControllers/SectorController.java @@ -22,6 +22,6 @@ public class SectorController { public String getEmpressaBySector(@PathVariable Long id, Model model) { Set empresaSet = new HashSet<>(empressaRepository.findBySector(id)); model.addAttribute("empresas", empresaSet); - return "/list/list_empresas"; + return "empresas"; } } diff --git a/src/main/java/com/example/proyectofinal/models/empresas/Empresa.java b/src/main/java/com/example/proyectofinal/models/empresas/Empresa.java index 21d216b..10fc223 100644 --- a/src/main/java/com/example/proyectofinal/models/empresas/Empresa.java +++ b/src/main/java/com/example/proyectofinal/models/empresas/Empresa.java @@ -37,7 +37,7 @@ public class Empresa { @Column(length = 2500) private String keywords; - @ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE, CascadeType.REMOVE,CascadeType.REFRESH},fetch = FetchType.LAZY) + @ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE, CascadeType.REMOVE,CascadeType.REFRESH},fetch = FetchType.EAGER) @JoinColumn(name = "Sector_id",referencedColumnName = "id") private Sector sector; diff --git a/src/main/java/com/example/proyectofinal/repositories/empresas/EmpressaRepository.java b/src/main/java/com/example/proyectofinal/repositories/empresas/EmpressaRepository.java index 6688508..3dd0ee3 100644 --- a/src/main/java/com/example/proyectofinal/repositories/empresas/EmpressaRepository.java +++ b/src/main/java/com/example/proyectofinal/repositories/empresas/EmpressaRepository.java @@ -2,11 +2,12 @@ package com.example.proyectofinal.repositories.empresas; import com.example.proyectofinal.models.empresas.Empresa; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; - import java.util.ArrayList; +import java.util.List; -public interface EmpressaRepository extends JpaRepository { +public interface EmpressaRepository extends JpaRepository, JpaSpecificationExecutor { //there is value = and nativeQuery = true so the query is written in SQL refering to the table in the database @@ -16,4 +17,9 @@ public interface EmpressaRepository extends JpaRepository { @Query(value = "SELECT * FROM empresas u WHERE u.sector_id = ?1", nativeQuery = true) public ArrayList findBySector(Long id); + @Query(value = "SELECT * FROM empresas order by id Asc", nativeQuery = true) + List findAllAsc(); + + + } diff --git a/src/main/resources/static/orderTable.js b/src/main/resources/static/orderTable.js new file mode 100644 index 0000000..f225502 --- /dev/null +++ b/src/main/resources/static/orderTable.js @@ -0,0 +1,64 @@ +function myFunction() { + var input, filter, table, tbody, tr, td, i, j, txtValue; + input = document.getElementById("myInput"); + filter = input.value.toUpperCase(); + table = document.getElementById("table"); + tbody = table.getElementsByTagName("tbody")[0]; + tr = tbody.getElementsByTagName("tr"); + + for (i = 0; i < tr.length; i++) { + for (j = 0; j < tr[i].cells.length; j++) { + td = tr[i].cells[j]; + if (td) { + txtValue = td.textContent || td.innerText; + if (txtValue.toUpperCase().indexOf(filter) > -1) { + tr[i].style.display = ""; + break; + } else { + tr[i].style.display = "none"; + } + } + } + } +} + +function sortTableCol(n) { + var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0; + table = document.getElementById("table"); + switching = true; + dir = "asc"; + while (switching) { + switching = false; + rows = table.rows; + for (i = 1; i < (rows.length - 1); i++) { + shouldSwitch = false; + x = rows[i].getElementsByTagName("TD")[n].innerHTML.trim(); + y = rows[i + 1].getElementsByTagName("TD")[n].innerHTML.trim(); + var xIsNumber = !isNaN(parseFloat(x)) && isFinite(x); + var yIsNumber = !isNaN(parseFloat(y)) && isFinite(y); + if (dir == "asc") { + if ((xIsNumber && yIsNumber && parseFloat(x) > parseFloat(y)) || + (!xIsNumber && !yIsNumber && x.localeCompare(y) > 0)) { + shouldSwitch = true; + break; + } + } else if (dir == "desc") { + if ((xIsNumber && yIsNumber && parseFloat(x) < parseFloat(y)) || + (!xIsNumber && !yIsNumber && x.localeCompare(y) < 0)) { + shouldSwitch = true; + break; + } + } + } + if (shouldSwitch) { + rows[i].parentNode.insertBefore(rows[i + 1], rows[i]); + switching = true; + switchcount++; + } else { + if (switchcount === 0 && dir === "asc") { + dir = "desc"; + switching = true; + } + } + } +} diff --git a/src/main/resources/templates/list/list_alumnos.html b/src/main/resources/templates/list/alumnos.html similarity index 100% rename from src/main/resources/templates/list/list_alumnos.html rename to src/main/resources/templates/list/alumnos.html diff --git a/src/main/resources/templates/list/list_ciclo.html b/src/main/resources/templates/list/ciclo.html similarity index 100% rename from src/main/resources/templates/list/list_ciclo.html rename to src/main/resources/templates/list/ciclo.html diff --git a/src/main/resources/templates/list/list_contactos.html b/src/main/resources/templates/list/contactos.html similarity index 100% rename from src/main/resources/templates/list/list_contactos.html rename to src/main/resources/templates/list/contactos.html diff --git a/src/main/resources/templates/list/list_empresas.html b/src/main/resources/templates/list/empresas.html similarity index 78% rename from src/main/resources/templates/list/list_empresas.html rename to src/main/resources/templates/list/empresas.html index 4ff7535..beecc7c 100644 --- a/src/main/resources/templates/list/list_empresas.html +++ b/src/main/resources/templates/list/empresas.html @@ -25,12 +25,11 @@ width: 40px; height: 40px; } - th { - background-color: #f2f2f2; /* Change this to your preferred color */ - color: black; /* Change this to your preferred color */ + background-color: #f2f2f2; + color: black; padding: 10px; - border: 1px solid #ddd; /* Adds border to the table headers */ + border: 1px solid #ddd; } h1 { @@ -49,7 +48,6 @@ width: 100%; position: relative; } - .table { padding-top: 5px; width: 100%; @@ -59,21 +57,17 @@ .cell{ height: 10px; } - @media screen and (max-width: 600px) { .table { } } - .table tr { height: 10%; } - body { margin: 0; padding: 0px; } - .header { display: flex; align-items: center; @@ -82,19 +76,15 @@ padding: 0; box-sizing: border-box; } - .header h1 { margin: 0; } - .header button { margin-right: auto; } - .logout-button { position: relative; } - .logout-button { position: relative; } @@ -110,19 +100,23 @@

Listado de Empresas

+ + + +
- +
- - - - - - - + + + + + + + - + @@ -130,19 +124,23 @@ - +
IdNombreCifCorreoTelefonoKeywordsSectorIdNombreCifCorreoTelefonoKeywordsSector
[[${empresa.id}]][[${empresa.cif}]] [[${empresa.correo}]] [[${empresa.telefono}]] -
[[${keyword}]]
-
[[${empresa.keywords}]] [[${empresa.sector.nombre}]]
- + + \ No newline at end of file diff --git a/src/main/resources/templates/list/list_familias.html b/src/main/resources/templates/list/familias.html similarity index 100% rename from src/main/resources/templates/list/list_familias.html rename to src/main/resources/templates/list/familias.html diff --git a/src/main/resources/templates/list/list_ofertas.html b/src/main/resources/templates/list/ofertas.html similarity index 100% rename from src/main/resources/templates/list/list_ofertas.html rename to src/main/resources/templates/list/ofertas.html diff --git a/src/main/resources/templates/list/list_sectores.html b/src/main/resources/templates/list/sectores.html similarity index 100% rename from src/main/resources/templates/list/list_sectores.html rename to src/main/resources/templates/list/sectores.html diff --git a/src/main/resources/templates/list/list_skills.html b/src/main/resources/templates/list/skills.html similarity index 100% rename from src/main/resources/templates/list/list_skills.html rename to src/main/resources/templates/list/skills.html diff --git a/src/main/resources/templates/list/list_sucursales.html b/src/main/resources/templates/list/sucursales.html similarity index 100% rename from src/main/resources/templates/list/list_sucursales.html rename to src/main/resources/templates/list/sucursales.html