Introduciendo otro dropdown para introducion de campo secundario por cual buscamos las cosas en base de datos. Empresas parcialmente hecho, peude hacer todos y sectores. Para este creamos mas interfaces especificos para cada entidad

master
vicsash 5 months ago
parent ea6c8a7d63
commit c92885fac7

@ -4,7 +4,7 @@ package com.example.proyectofinal.controllers;
import com.example.proyectofinal.models.empresas.*; import com.example.proyectofinal.models.empresas.*;
import com.example.proyectofinal.repositories.empresas.*; import com.example.proyectofinal.repositories.empresas.*;
import com.example.proyectofinal.servicios.*; import com.example.proyectofinal.servicios.*;
import com.example.proyectofinal.servicios.implemetations.IPagination; import com.example.proyectofinal.interfaces.IPagination;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@ -52,40 +52,61 @@ public class BuscadorController {
} }
@GetMapping("/empresas/page/{pageNum}") @GetMapping("/empresas/page/{pageNum}")
public String seachEmpresasList(@PathVariable int pageNum, public String searchEmpresasList(@PathVariable int pageNum,
@RequestParam(defaultValue = "") String query, @RequestParam(defaultValue = "") String query,
Model model,
@RequestParam(defaultValue = "10") int size, @RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "nombre") String sortField, @RequestParam(defaultValue = "nombre") String sortField,
@RequestParam(defaultValue = "asc") String sortDir){ @RequestParam(defaultValue = "asc") String sortDir,
@RequestParam String secondaryOption,
String[] word = query.split("\\b(y|o)\\b|[,/]"); Model model){
System.out.println("Selected option TEST: " + secondaryOption);
Page<Empresa> page = empresaService.getPage(pageNum, size, sortField, sortDir, query, secondaryOption);
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50); List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
if (word.length == 1 && (word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas"))) { if(page!=null){
sortField = "nombre"; List<Empresa> empresas = page.getContent();
sortDir = "asc"; model.addAttribute("currentPage", pageNum);
} model.addAttribute("totalPages", page.getTotalPages());
Map<String, Object> attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, empresaService, itemsPage); model.addAttribute("totalItems", page.getTotalElements());
for (Map.Entry<String, Object> entry : attributes.entrySet()) { model.addAttribute("empresas", empresas);
model.addAttribute(entry.getKey(), entry.getValue());
model.addAttribute("sortField", sortField);
model.addAttribute("sortDir", sortDir);
model.addAttribute("reverseSortDir", sortDir.equals("asc") ? "desc" : "asc");
model.addAttribute("query", query);
model.addAttribute("secondaryOption", secondaryOption);
model.addAttribute("itemsPage", itemsPage);
model.addAttribute("currentSize", size);
}else{
System.out.println("No se encontraron empresas");
} }
// List<Object> models = model.asMap().values().stream().toList();
// for(Object m : models){
// System.out.println(m);
// }
return "/list/empresas"; return "/list/empresas";
} }
@GetMapping("/sectores/page/{pageNum}") @GetMapping("/sectores/page/{pageNum}")
public String searchSectoresList(@PathVariable int pageNum, public String searchSectoresList(@PathVariable int pageNum,
@RequestParam(defaultValue = "") String query, @RequestParam(defaultValue = "") String query,
Model model,
@RequestParam(defaultValue = "10") int size, @RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "nombre") String sortField, @RequestParam(defaultValue = "nombre") String sortField,
@RequestParam(defaultValue = "asc") String sortDir){ @RequestParam(defaultValue = "asc") String sortDir,
@RequestParam(defaultValue = "") String secondaryOption,
Model model){
String[] word = query.split("\\b(y|o)\\b|[,/]"); String[] word = query.split("\\b(y|o)\\b|[,/]");
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50); List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
if (word.length == 1 && (word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas"))) { Map<String, Object> attributes = new HashMap<>();
if (secondaryOption.equalsIgnoreCase("Todo")) {
sortField = "nombre"; sortField = "nombre";
sortDir = "asc"; sortDir = "asc";
attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, alumnoService, itemsPage);
} }
Map<String, Object> attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, sectorService, itemsPage);
for (Map.Entry<String, Object> entry : attributes.entrySet()) { for (Map.Entry<String, Object> entry : attributes.entrySet()) {
model.addAttribute(entry.getKey(), entry.getValue()); model.addAttribute(entry.getKey(), entry.getValue());
} }
@ -96,17 +117,20 @@ public class BuscadorController {
@GetMapping("/contactos/page/{pageNum}") @GetMapping("/contactos/page/{pageNum}")
public String searchContactosList(@PathVariable int pageNum, public String searchContactosList(@PathVariable int pageNum,
@RequestParam(defaultValue = "") String query, @RequestParam(defaultValue = "") String query,
Model model,
@RequestParam(defaultValue = "10") int size, @RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "nombre") String sortField, @RequestParam(defaultValue = "nombre") String sortField,
@RequestParam(defaultValue = "asc") String sortDir) { @RequestParam(defaultValue = "asc") String sortDir,
@RequestParam(defaultValue = "") String secondaryOption,
Model model) {
String[] word = query.split("\\b(y|o)\\b|[,/]"); String[] word = query.split("\\b(y|o)\\b|[,/]");
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50); List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
if (word.length == 1 && (word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas"))) { Map<String, Object> attributes =new HashMap<>();
if (secondaryOption.equalsIgnoreCase("Todo")) {
sortField = "nombre"; sortField = "nombre";
sortDir = "asc"; sortDir = "asc";
attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, alumnoService, itemsPage);
} }
Map<String, Object> attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, contactosService, itemsPage);
for (Map.Entry<String, Object> entry : attributes.entrySet()) { for (Map.Entry<String, Object> entry : attributes.entrySet()) {
model.addAttribute(entry.getKey(), entry.getValue()); model.addAttribute(entry.getKey(), entry.getValue());
} }
@ -116,17 +140,19 @@ public class BuscadorController {
@GetMapping("/sucursales/page/{pageNum}") @GetMapping("/sucursales/page/{pageNum}")
public String searchSucursalesList(@PathVariable int pageNum, public String searchSucursalesList(@PathVariable int pageNum,
@RequestParam(defaultValue = "") String query, @RequestParam(defaultValue = "") String query,
Model model,
@RequestParam(defaultValue = "10") int size, @RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "nombre") String sortField, @RequestParam(defaultValue = "nombre") String sortField,
@RequestParam(defaultValue = "asc") String sortDir){ @RequestParam(defaultValue = "asc") String sortDir,
@RequestParam(defaultValue = "") String secondaryOption,
Model model){
String[] word = query.split("\\b(y|o)\\b|[,/]"); String[] word = query.split("\\b(y|o)\\b|[,/]");
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50); List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
if (word.length == 1 && (word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas"))) { Map<String, Object> attributes = new HashMap<>();
if (secondaryOption.equalsIgnoreCase("Todo")) {
sortField = "nombre"; sortField = "nombre";
sortDir = "asc"; sortDir = "asc";
attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, alumnoService, itemsPage);
} }
Map<String, Object> attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, sucursalService, itemsPage);
for (Map.Entry<String, Object> entry : attributes.entrySet()) { for (Map.Entry<String, Object> entry : attributes.entrySet()) {
model.addAttribute(entry.getKey(), entry.getValue()); model.addAttribute(entry.getKey(), entry.getValue());
} }
@ -136,17 +162,19 @@ public class BuscadorController {
@GetMapping("/ofertas/page/{pageNum}") @GetMapping("/ofertas/page/{pageNum}")
public String searchOfertasList(@PathVariable int pageNum, public String searchOfertasList(@PathVariable int pageNum,
@RequestParam(defaultValue = "") String query, @RequestParam(defaultValue = "") String query,
Model model,
@RequestParam(defaultValue = "10") int size, @RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "nombre") String sortField, @RequestParam(defaultValue = "nombre") String sortField,
@RequestParam(defaultValue = "asc") String sortDir){ @RequestParam(defaultValue = "asc") String sortDir,
@RequestParam(defaultValue = "") String secondaryOption,
Model model){
String[] word = query.split("\\b(y|o)\\b|[,/]"); String[] word = query.split("\\b(y|o)\\b|[,/]");
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50); List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
if (word.length == 1 && (word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas"))) { Map<String, Object> attributes = new HashMap<>();
if (secondaryOption.equalsIgnoreCase("Todo")) {
sortField = "nombre"; sortField = "nombre";
sortDir = "asc"; sortDir = "asc";
attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, alumnoService, itemsPage);
} }
Map<String, Object> attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, ofertasService, itemsPage);
for (Map.Entry<String, Object> entry : attributes.entrySet()) { for (Map.Entry<String, Object> entry : attributes.entrySet()) {
model.addAttribute(entry.getKey(), entry.getValue()); model.addAttribute(entry.getKey(), entry.getValue());
} }
@ -156,17 +184,19 @@ public class BuscadorController {
@GetMapping("/familias/page/{pageNum}") @GetMapping("/familias/page/{pageNum}")
public String searchFamiliasList(@PathVariable int pageNum, public String searchFamiliasList(@PathVariable int pageNum,
@RequestParam(defaultValue = "") String query, @RequestParam(defaultValue = "") String query,
Model model,
@RequestParam(defaultValue = "10") int size, @RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "nombre") String sortField, @RequestParam(defaultValue = "nombre") String sortField,
@RequestParam(defaultValue = "asc") String sortDir) { @RequestParam(defaultValue = "asc") String sortDir,
@RequestParam(defaultValue = "") String secondaryOption,
Model model) {
String[] word = query.split("\\b(y|o)\\b|[,/]"); String[] word = query.split("\\b(y|o)\\b|[,/]");
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50); List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
if (word.length == 1 && (word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas"))) { Map<String, Object> attributes = new HashMap<>();
if (secondaryOption.equalsIgnoreCase("Todo")) {
sortField = "nombre"; sortField = "nombre";
sortDir = "asc"; sortDir = "asc";
attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, alumnoService, itemsPage);
} }
Map<String, Object> attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, familiaService, itemsPage);
for (Map.Entry<String, Object> entry : attributes.entrySet()) { for (Map.Entry<String, Object> entry : attributes.entrySet()) {
model.addAttribute(entry.getKey(), entry.getValue()); model.addAttribute(entry.getKey(), entry.getValue());
} }
@ -176,17 +206,19 @@ public class BuscadorController {
@GetMapping("/ciclos/page/{pageNum}") @GetMapping("/ciclos/page/{pageNum}")
public String searchCiclosList(@PathVariable int pageNum, public String searchCiclosList(@PathVariable int pageNum,
@RequestParam(defaultValue = "") String query, @RequestParam(defaultValue = "") String query,
Model model,
@RequestParam(defaultValue = "10") int size, @RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "nombre") String sortField, @RequestParam(defaultValue = "nombre") String sortField,
@RequestParam(defaultValue = "asc") String sortDir) { @RequestParam(defaultValue = "asc") String sortDir,
@RequestParam(defaultValue = "") String secondaryOption,
Model model) {
String[] word = query.split("\\b(y|o)\\b|[,/]"); String[] word = query.split("\\b(y|o)\\b|[,/]");
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50); List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
if (word.length == 1 && (word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas"))) { Map<String, Object> attributes = new HashMap<>();
if (secondaryOption.equalsIgnoreCase("Todo")) {
sortField = "nombre"; sortField = "nombre";
sortDir = "asc"; sortDir = "asc";
attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, alumnoService, itemsPage);
} }
Map<String, Object> attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, cicloService, itemsPage);
for (Map.Entry<String, Object> entry : attributes.entrySet()) { for (Map.Entry<String, Object> entry : attributes.entrySet()) {
model.addAttribute(entry.getKey(), entry.getValue()); model.addAttribute(entry.getKey(), entry.getValue());
} }
@ -196,18 +228,20 @@ public class BuscadorController {
@GetMapping("/alumnos/page/{pageNum}") @GetMapping("/alumnos/page/{pageNum}")
public String searchAlumnosList(@PathVariable int pageNum, public String searchAlumnosList(@PathVariable int pageNum,
@RequestParam(defaultValue = "") String query, @RequestParam(defaultValue = "") String query,
Model model,
@RequestParam(defaultValue = "10") int size, @RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "nombre") String sortField, @RequestParam(defaultValue = "nombre") String sortField,
@RequestParam(defaultValue = "asc") String sortDir) { @RequestParam(defaultValue = "asc") String sortDir,
@RequestParam(defaultValue = "") String secondaryOption,
Model model) {
String[] word = query.split("\\b(y|o)\\b|[,/]"); String[] word = query.split("\\b(y|o)\\b|[,/]");
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50); List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
if (word.length == 1 && (word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas"))) { Map<String, Object> attributes = new HashMap<>();
if (secondaryOption.equalsIgnoreCase("Todo")) {
sortField = "nombre"; sortField = "nombre";
sortDir = "asc"; sortDir = "asc";
attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, alumnoService, itemsPage);
} }
Map<String, Object> attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, alumnoService, itemsPage);
for (Map.Entry<String, Object> entry : attributes.entrySet()) { for (Map.Entry<String, Object> entry : attributes.entrySet()) {
model.addAttribute(entry.getKey(), entry.getValue()); model.addAttribute(entry.getKey(), entry.getValue());
} }
@ -217,17 +251,20 @@ public class BuscadorController {
@GetMapping("/skills/page/{pageNum}") @GetMapping("/skills/page/{pageNum}")
public String searchSkillsList(@PathVariable int pageNum, public String searchSkillsList(@PathVariable int pageNum,
@RequestParam(defaultValue = "") String query, @RequestParam(defaultValue = "") String query,
Model model,
@RequestParam(defaultValue = "10") int size, @RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "nombre") String sortField, @RequestParam(defaultValue = "nombre") String sortField,
@RequestParam(defaultValue = "asc") String sortDir) { @RequestParam(defaultValue = "asc") String sortDir,
@RequestParam(defaultValue = "") String secondaryOption,
Model model) {
String[] word = query.split("\\b(y|o)\\b|[,/]"); String[] word = query.split("\\b(y|o)\\b|[,/]");
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50); List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
if (word.length == 1 && (word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas"))) { Map<String, Object> attributes = new HashMap<>();
if (secondaryOption.equalsIgnoreCase("Todo")) {
sortField = "nombre"; sortField = "nombre";
sortDir = "asc"; sortDir = "asc";
attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, skillService, itemsPage);
} }
Map<String, Object> attributes = getPaginatedAttributes(pageNum, query, size, sortField, sortDir, skillService, itemsPage);
for (Map.Entry<String, Object> entry : attributes.entrySet()) { for (Map.Entry<String, Object> entry : attributes.entrySet()) {
model.addAttribute(entry.getKey(), entry.getValue()); model.addAttribute(entry.getKey(), entry.getValue());
} }

@ -1,8 +1,9 @@
package com.example.proyectofinal.servicios.implemetations; package com.example.proyectofinal.interfaces;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
public interface IPagination<T> { public interface IPagination<T> {
Page<T> findAllPaginated(int pageNum, int size, String sortField, String sortDir); Page<T> findAllPaginated(int pageNum, int size, String sortField, String sortDir);
} }

@ -0,0 +1,8 @@
package com.example.proyectofinal.interfaces;
import org.springframework.data.domain.Page;
public interface IPaginationStrategy<T> {
Page<T> getPage(int pageNum, int size, String sortField, String sortDir, String query, IPagination<T> service);
}

@ -0,0 +1,13 @@
package com.example.proyectofinal.interfaces.specific;
import com.example.proyectofinal.interfaces.IPagination;
import com.example.proyectofinal.models.empresas.Empresa;
import org.springframework.data.domain.Page;
import java.util.List;
public interface IEmpresaSpecificPagination extends IPagination<Empresa> {
Page<Empresa> findEmpresasBySectorPaginated(Long sectorId, int pageNum, int size, String sortField, String sortDir);
}

@ -30,6 +30,11 @@ public interface EmpressaRepository extends JpaRepository<Empresa, Long>, JpaSpe
@Query("SELECT e FROM Empresa e WHERE e.cif = :cif") @Query("SELECT e FROM Empresa e WHERE e.cif = :cif")
Empresa existsCif(@Param("cif") String empresaName); Empresa existsCif(@Param("cif") String empresaName);
@Query(value = "SELECT * FROM empresas u WHERE u.fk_sector = :sectorId", nativeQuery = true)
Page<Empresa> empresaBySector(@Param("sectorId") Long sectorId, Pageable pageable);
// In EmpressaRepository.java
@Query("SELECT e FROM Empresa e WHERE e.sector.nombre = :sectorName")
Page<Empresa> findEmpresasBySectorName(@Param("sectorName") String sectorName, Pageable pageable);
} }

@ -1,7 +1,9 @@
package com.example.proyectofinal.servicios; package com.example.proyectofinal.servicios;
import com.example.proyectofinal.interfaces.specific.IEmpresaSpecificPagination;
import com.example.proyectofinal.models.empresas.Empresa; import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.models.empresas.Oferta; import com.example.proyectofinal.models.empresas.Oferta;
import com.example.proyectofinal.models.empresas.Sector;
import com.example.proyectofinal.models.empresas.Sucursal; import com.example.proyectofinal.models.empresas.Sucursal;
import com.example.proyectofinal.repositories.empresas.EmpressaRepository; import com.example.proyectofinal.repositories.empresas.EmpressaRepository;
import com.example.proyectofinal.repositories.empresas.OfertaRepository; import com.example.proyectofinal.repositories.empresas.OfertaRepository;
@ -12,10 +14,11 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@Service @Service
public class EmpresaService implements IEmpresa { public class EmpresaService implements IEmpresa, IEmpresaSpecificPagination {
@Autowired @Autowired
private EmpressaRepository empresaRepository; private EmpressaRepository empresaRepository;
@ -28,7 +31,16 @@ public class EmpresaService implements IEmpresa {
@Autowired @Autowired
private OfertaRepository ofertaRepository; private OfertaRepository ofertaRepository;
public Page<Empresa> getPage(int pageNum, int size, String sortField, String sortDir, String query, String secondaryOption) {
if(secondaryOption.equalsIgnoreCase("Todo")){
return findAllPaginated(pageNum, size, sortField, sortDir);
}else if (secondaryOption.equals("Sector")) {
return empresaRepository.findEmpresasBySectorName(query, PageRequest.of(pageNum - 1, size, Sort.by(sortField).ascending()));
} else {
return null;
}
}
@Override @Override
public List<Empresa> findAll() { public List<Empresa> findAll() {
return empresaRepository.findAll(); return empresaRepository.findAll();
@ -41,6 +53,13 @@ public class EmpresaService implements IEmpresa {
Page<Empresa> result = empresaRepository.findAll(pageRequest); Page<Empresa> result = empresaRepository.findAll(pageRequest);
return result; return result;
} }
@Override
public Page<Empresa> findEmpresasBySectorPaginated(Long sectorId, int pageNum, int pageSize, String sortField, String sortDir) {
Sort sort = sortDir.equalsIgnoreCase(Sort.Direction.ASC.name()) ? Sort.by(sortField).ascending() : Sort.by(sortField).descending();
PageRequest pageRequest = PageRequest.of(pageNum - 1, pageSize, sort);
Page<Empresa> result = empresaRepository.empresaBySector(sectorId, pageRequest);
return result;
}
@Override @Override
public Empresa findById(Long id) { public Empresa findById(Long id) {
@ -72,7 +91,7 @@ public class EmpresaService implements IEmpresa {
} }
@Override @Override
public List<Empresa> search(String query ) { public List<Empresa> search(String query) {
return empresaRepository.search(query); return empresaRepository.search(query);
} }
@ -87,6 +106,5 @@ public class EmpresaService implements IEmpresa {
return empresaRepository.findBySector(id); return empresaRepository.findBySector(id);
} }
} }

@ -1,5 +1,6 @@
package com.example.proyectofinal.servicios.implemetations; package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.interfaces.IPagination;
import com.example.proyectofinal.models.empresas.Alumno; import com.example.proyectofinal.models.empresas.Alumno;
import java.util.List; import java.util.List;

@ -1,5 +1,6 @@
package com.example.proyectofinal.servicios.implemetations; package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.interfaces.IPagination;
import com.example.proyectofinal.models.empresas.Ciclo; import com.example.proyectofinal.models.empresas.Ciclo;
import com.example.proyectofinal.models.empresas.Familia; import com.example.proyectofinal.models.empresas.Familia;

@ -1,5 +1,6 @@
package com.example.proyectofinal.servicios.implemetations; package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.interfaces.IPagination;
import com.example.proyectofinal.models.empresas.Contacto; import com.example.proyectofinal.models.empresas.Contacto;
import com.example.proyectofinal.models.empresas.Empresa; import com.example.proyectofinal.models.empresas.Empresa;

@ -1,5 +1,7 @@
package com.example.proyectofinal.servicios.implemetations; package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.interfaces.IPagination;
import com.example.proyectofinal.interfaces.specific.IEmpresaSpecificPagination;
import com.example.proyectofinal.models.empresas.Empresa; import com.example.proyectofinal.models.empresas.Empresa;
import java.util.List; import java.util.List;
@ -8,7 +10,6 @@ public interface IEmpresa extends IPagination<Empresa> {
List<Empresa> findAll(); List<Empresa> findAll();
Empresa findById(Long id); Empresa findById(Long id);
Empresa save(Empresa empresa); Empresa save(Empresa empresa);

@ -1,5 +1,6 @@
package com.example.proyectofinal.servicios.implemetations; package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.interfaces.IPagination;
import com.example.proyectofinal.models.empresas.Familia; import com.example.proyectofinal.models.empresas.Familia;
import java.util.List; import java.util.List;

@ -1,5 +1,6 @@
package com.example.proyectofinal.servicios.implemetations; package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.interfaces.IPagination;
import com.example.proyectofinal.models.empresas.Oferta; import com.example.proyectofinal.models.empresas.Oferta;
import com.example.proyectofinal.models.empresas.Sucursal; import com.example.proyectofinal.models.empresas.Sucursal;

@ -1,5 +1,6 @@
package com.example.proyectofinal.servicios.implemetations; package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.interfaces.IPagination;
import com.example.proyectofinal.models.empresas.Sector; import com.example.proyectofinal.models.empresas.Sector;
import java.util.List; import java.util.List;

@ -1,12 +1,12 @@
package com.example.proyectofinal.servicios.implemetations; package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.interfaces.IPagination;
import com.example.proyectofinal.models.empresas.Skill; import com.example.proyectofinal.models.empresas.Skill;
import org.springframework.data.domain.Page;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
public interface ISkill extends IPagination<Skill>{ public interface ISkill extends IPagination<Skill> {
List<Skill> findAll(); List<Skill> findAll();
Skill findById(Long id); Skill findById(Long id);

@ -1,5 +1,6 @@
package com.example.proyectofinal.servicios.implemetations; package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.interfaces.IPagination;
import com.example.proyectofinal.models.empresas.Empresa; import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.models.empresas.Sucursal; import com.example.proyectofinal.models.empresas.Sucursal;

@ -4,6 +4,7 @@
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
<link rel="stylesheet" type="text/css" th:href="@{/style.css}"> <link rel="stylesheet" type="text/css" th:href="@{/style.css}">
<link rel="stylesheet" type="text/css" th:href="@{/form.css}"> <link rel="stylesheet" type="text/css" th:href="@{/form.css}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<title>Buscador</title> <title>Buscador</title>
<style> <style>
body { body {
@ -41,6 +42,11 @@
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
.dropdown-container {
display: flex;
justify-content: space-between;
width: 100%;
}
</style> </style>
</head> </head>
<body > <body >
@ -55,29 +61,163 @@
<input type="text" name="query" placeholder="Buscar..."> <input type="text" name="query" placeholder="Buscar...">
<input type="submit" value="Buscar"> <input type="submit" value="Buscar">
</div> </div>
<div class="dropdown-container">
<select name="searchOption" id="searchOption"> <select name="searchOption" id="searchOption">
<option value="empresas">Empresa</option> <option value="empresas">Empresa</option>
<option value="sectores">Sector</option> <option value="sectores">Sectores</option>
<option value="alumnos" >Alumno</option> <option value="alumnos" >Alumnos</option>
<option value="ofertas">Oferta</option> <option value="ofertas">Ofertas</option>
<option value="sucursales">Sucursal</option> <option value="sucursales">Sucursales</option>
<option value="skills">Skill</option> <option value="skills">Skills</option>
<option value="contactos">Contactos</option> <option value="contactos">Contactos</option>
<option value="familias">Familias</option> <option value="familias">Familias</option>
<option value="ciclos">Ciclos</option> <option value="ciclos">Ciclos</option>
</select> </select>
<select id="secondaryDropdown"></select>
<input type="hidden" name="secondaryOption" id="hiddenSecondaryOption">
</div>
</form> </form>
</div> </div>
<script> <script>
var firstPage= 1;
document.getElementById('searchForm').addEventListener('submit', function(event) { // Get references to the primary dropdown, the search bar, and the secondary dropdown
event.preventDefault(); var primaryDropdown = document.getElementById('searchOption');
var searchBar = document.querySelector('input[name="query"]');
var secondaryDropdown = document.getElementById('secondaryDropdown');
// Add an event listener to the secondary dropdown
secondaryDropdown.addEventListener('change', function() {
//console.log("Selected option in secondary dropdown: " + secondaryDropdown.value);
// If the selected option is "Todas", disable the search bar and set its value to "Todas"
if (secondaryDropdown.value === 'Todo') {
searchBar.value = 'Todo';
searchBar.disabled = true;
} else {
searchBar.value = '';
searchBar.disabled = false;
}
});
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'];
break;
case'sucursales':
options = ['Todo', 'Nombre', 'Empresa','Localidad'];
break;
case'skills':
options = ['Todo'];
break;
case'familias':
options = ['Todo'];
break;
case'ciclos':
options = ['Todo','Familia'];
break;
case'alumnos':
options = ['Todo', 'Nombre', 'Apellidos','Ciclo','Keywords'];
break;
default:
options = [];
}
console.log("Primary dropdown value: " + primaryDropdown.value); // 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'];
break;
case'sucursales':
options = ['Todo', 'Nombre', 'Empresa','Localidad'];
break;
case'skills':
options = ['Todo'];
break;
case'familias':
options = ['Todo'];
break;
case'ciclos':
options = ['Todo','Familia'];
break;
case'alumnos':
options = ['Todo', 'Nombre', 'Apellidos','Ciclo','Keywords'];
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
primaryDropdown.dispatchEvent(new Event('change'));
// Reset the form
document.querySelector('form').reset();
// Get reference to the search bar
var secondaryDropdown = document.getElementById('secondaryDropdown');
secondaryDropdown.value = 'Todo';
var searchBar = document.querySelector('input[name="query"]');
// Set the value of the search bar to "Todo" and disable it
searchBar.value = 'Todo';
searchBar.disabled = true;
document.getElementById('searchForm').addEventListener('submit', function() {
var searchOption = document.getElementById('searchOption').value; var searchOption = document.getElementById('searchOption').value;
this.action = "/buscador/" + searchOption +"/page/"+firstPage; var secondaryOption = document.getElementById('secondaryDropdown').value;
this.submit(); // Update the value of the hidden input field
document.getElementById('hiddenSecondaryOption').value = secondaryOption;
this.action = "/buscador/" + searchOption + "/page/1";
}); });
window.onload = function() { window.onload = function() {
document.querySelector('form').reset(); primaryDropdown.dispatchEvent(new Event('change'));
}; };
</script> </script>
</body> </body>

@ -58,7 +58,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr class="cell" th:each="empresa :${items}" th:data-id="${empresa.id}"> <tr class="cell" th:each="empresa :${empresas}" th:data-id="${empresa.id}">
<td> <td>
<a th:href="@{/templates/admin/empresa/{id}(id=${empresa.id})}">[[${empresa.nombre}]]</a> <a th:href="@{/templates/admin/empresa/{id}(id=${empresa.id})}">[[${empresa.nombre}]]</a>
<i class="edit-icon fas fa-pen-square"></i> <i class="edit-icon fas fa-pen-square"></i>

Loading…
Cancel
Save

Powered by INFORMATICA.FP.EDU.ES.