Terminando con buscador y cantidad de entradas en la lista y arreglando cosas del diseños de html, tamaño de los td de la tabla. Y comenzado con operaciones crud antes de aplicar lo msimo sobre otras tablas

master
vicsash 5 months ago
parent cf90ff5a99
commit 89b8d8d427

@ -69,6 +69,11 @@
<artifactId>javafaker</artifactId> <artifactId>javafaker</artifactId>
<version>1.0.2</version> <version>1.0.2</version>
</dependency> </dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -1,112 +0,0 @@
package com.example.proyectofinal.configuration.database;
import com.example.proyectofinal.models.empresas.*;
import com.example.proyectofinal.repositories.empresas.*;
import com.github.javafaker.Faker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
@Configuration
public class DatabaseTest {
@Autowired
private DataSource dataSource;
@Bean
CommandLineRunner initDatabase(AlumnoRepository alumnoRepository, ContactoRepository contactoRepository, SucursalRepository sucursalRepository, OfertaRepository ofertaRepository, SkillRepository skillRepository, EmpressaRepository empressaRepository, CicloRepository cicloRepository, SectorRepository sectorRepository) {
return args -> {
Faker faker = new Faker();
String[] cicloNames = {"DAM", "DAM2", "DAW", "DAW2", "ACI"};
String[] familiaNames = {"Informatica", "Informatica2", "Informatica3", "Informatica4", "Informatica5"};
Random random = new Random();
for (int i = 0; i < 30; i++) {
int randomIndex = random.nextInt(cicloNames.length);
Familia familia = new Familia(familiaNames[randomIndex]);
Ciclo ciclo = new Ciclo("Programacion cilclo",cicloNames[randomIndex], familia);
Skill skill = new Skill(faker.lorem().word() + i);
skillRepository.save(skill);
Set<Skill> skills = new HashSet<>();
skills.add(skill);
Alumno alumno = new Alumno(
faker.name().firstName(),
faker.name().lastName(),
faker.name().lastName(),
faker.date().birthday(),
faker.demographic().sex(),
faker.number().digits(8),
faker.number().digits(8),
faker.internet().emailAddress(),
faker.internet().emailAddress(),
faker.country().name(),
faker.lorem().word(),
skills,
ciclo
);
alumnoRepository.save(alumno);
Sector sector = new Sector("Tecnologia" + i);
//sectorRepository.save(sector);
Empresa empresa = new Empresa(
faker.company().name(),
"123456789W" + i,
faker.internet().emailAddress(),
faker.phoneNumber().cellPhone(),
faker.company().profession(),
sector
);
//empressaRepository.save(empresa);
Contacto contacto = new Contacto(
faker.name().firstName(),
faker.name().lastName(),
faker.name().lastName(),
faker.internet().emailAddress(),
faker.phoneNumber().cellPhone(),
empresa
);
contactoRepository.save(contacto);
Sucursal sucursal = new Sucursal(
"Sucursal " + (i + 1),
"Sevilla",
"Calle Falsa 123",
true,
empresa
);
//sucursalRepository.save(sucursal);
Oferta oferta = new Oferta(
"Oferta " + (i + 1),
"Descripcion de la oferta",
"2023-01-11",
sucursal,
skills
);
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)");
};
}
}

@ -3,14 +3,20 @@ 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 jakarta.servlet.http.HttpSession; import com.example.proyectofinal.servicios.EmpresaService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import java.util.*; import java.util.*;
@Controller @Controller
@ -37,67 +43,73 @@ public class BuscadorController {
@Autowired @Autowired
private CicloRepository cicloRepository; private CicloRepository cicloRepository;
@Autowired
private EmpresaService empresaService;
@GetMapping @GetMapping
public String buscador(){ public String buscador(){
return "buscador_admin"; return "buscador_admin";
} }
@GetMapping("/search") @GetMapping("/empresas/page/{pageNum}")
public String search(@RequestParam String query, @RequestParam String searchOption, Model model, HttpSession session) { public String seachEmpresasList(@PathVariable int pageNum,
@RequestParam(defaultValue = "") String query,
Model model,
@RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "id") String sortField,
@RequestParam(defaultValue = "asc") String sortDir){
String[] word = query.split("\\b(y|o)\\b|[,/]"); String[] word = query.split("\\b(y|o)\\b|[,/]");
if (searchOption.equals("OptEmpresa")) { List<Empresa> empresas;
if(word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")){ List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
ArrayList<Empresa> empresas = new ArrayList<>(empressaRepository.findAllAsc());
model.addAttribute("empresas", empresas); if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
Page<Empresa> page = this.empresaService.finadAllpaginated(pageNum, size, "id", "asc");
empresas = page.getContent();
} else {
Page<Empresa> page = this.empresaService.finadAllpaginated(pageNum, size, sortField, sortDir);
empresas = page.getContent();
}
model.addAttribute("currentSize", size);
Map<String, Object> attributes = getPagAtrEmpresas(pageNum, query, size, sortField, sortDir, empresas, itemsPage);
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
model.addAttribute(entry.getKey(), entry.getValue());
}
return "/list/empresas"; return "/list/empresas";
} }
// if(word.length == 1){
// ArrayList<Empresa> empresas = new ArrayList<>(empressaRepository.getEmpressaByKeywordsOrName(word[0]));
// model.addAttribute("empresas", empresas);
// return "/list/empresas"; public String searchAlumnosList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
// }else if(word.length == 2){ Pageable pageable = PageRequest.of(page, size);
// ArrayList<Empresa> empresas = new ArrayList<>(empressaRepository.getEmpressaByKeywordsOrName(word[0])); String[] word = query.split("\\b(y|o)\\b|[,/]");
// 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")) { if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todos")) {
ArrayList<Alumno> alumnos = new ArrayList<>(alumnoRepository.findAll()); List<Alumno> alumnos = new ArrayList<>(alumnoRepository.findAll());
model.addAttribute("alumnos", alumnos); model.addAttribute("alumnos", alumnos);
return "/list/alumnos"; return "/list/alumnos";
} }
// if (word.length == 1) { return "/list/alumnos";
// System.out.println("Buscando alumnos"); }
// ArrayList<Alumno> alumnos = new ArrayList<>(alumnoRepository.getAlumnoByKeywordsOrName(word[0]));
// model.addAttribute("alumnos", alumnos); @GetMapping("/ofertas")
// return "/list/alumnos"; public String searchOfertasList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size){
// } else if (word.length == 2) { Pageable pageable = PageRequest.of(page, size);
// System.out.println("Buscando alumnos"); String[] word = query.split("\\b(y|o)\\b|[,/]");
// ArrayList<Alumno> 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")) { if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
ArrayList<Oferta> ofertas = new ArrayList<>(ofertaRepository.findAll()); List<Oferta> ofertas = new ArrayList<>(ofertaRepository.findAll());
model.addAttribute("ofertas", ofertas); model.addAttribute("ofertas", ofertas);
return "/list/ofertas"; return "/list/ofertas";
} }
// if (word.length == 1) { return "/list/ofertas";
// ArrayList<Oferta> ofertas = new ArrayList<>(ofertaRepository.getOfertaFullTextSeach(word[0])); }
// model.addAttribute("ofertas", ofertas);
// return "/list/ofertas"; @GetMapping("/sectores")
// } else if (word.length == 2) { public String searchSectoresList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size){
// ArrayList<Oferta> ofertas = new ArrayList<>(ofertaRepository.getOfertaFullTextSeach(word[0])); Pageable pageable = PageRequest.of(page, size);
// ofertas.addAll(ofertaRepository.getOfertaFullTextSeach(word[1])); String[] word = query.split("\\b(y|o)\\b|[,/]");
// model.addAttribute("ofertas", ofertas);
// return "/list/ofertas";
// }
} else if (searchOption.equals("OptSector")) {
if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) { if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
ArrayList<Sector> sectores = new ArrayList<>(sectorRepository.findAll()); List<Sector> sectores = new ArrayList<>(sectorRepository.findAll());
model.addAttribute("sectores", sectores); model.addAttribute("sectores", sectores);
return "/list/sectores"; return "/list/sectores";
} else { } else {
@ -105,55 +117,92 @@ public class BuscadorController {
model.addAttribute("sectores", sector); model.addAttribute("sectores", sector);
return "/list/sectores"; return "/list/sectores";
} }
}else if(searchOption.equals("OptSucursal")) { }
@GetMapping("/sucursales")
public String searchSucursalesList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size){
Pageable pageable = PageRequest.of(page, size);
String[] word = query.split("\\b(y|o)\\b|[,/]");
if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) { if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
ArrayList<Sucursal> sucursalSet = new ArrayList<>(sucursalRepository.findAll()); List<Sucursal> sucursalSet = new ArrayList<>(sucursalRepository.findAll());
model.addAttribute("sucursales", sucursalSet); model.addAttribute("sucursales", sucursalSet);
return "/list/sucursales"; return "/list/sucursales";
} }
// } else { return "/list/sucursales";
// ArrayList<Sucursal> 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")) {
ArrayList<Skill> skills = new ArrayList<>(skillRepository.findAll());
model.addAttribute("skills", skills);
return "/list/skills";
} }
// else{
// ArrayList<Skill> skills = new ArrayList<>(skillRepository.getSkillFullTextSeach(word[0]));
// model.addAttribute("skills", skills); @GetMapping("/contactos")
// return "/list/skills"; public String searchContactosList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
// } Pageable pageable = PageRequest.of(page, size);
}else if(searchOption.equals("OptContactos")) { String[] word = query.split("\\b(y|o)\\b|[,/]");
if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) { if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
ArrayList<Contacto> contactos = new ArrayList<>(contactoRepository.findAll()); List<Contacto> contactos = new ArrayList<>(contactoRepository.findAll());
model.addAttribute("contactos", contactos); model.addAttribute("contactos", contactos);
return "/list/contactos"; return "/list/contactos";
} }
// else { return "/list/contactos";
// ArrayList<Contacto> contactos = new ArrayList<>(contactoRepository.getContactoFullTextSeach(word[0])); }
// model.addAttribute("contactos", contactos);
// return "/list/contactos"; @GetMapping("/familias")
// } public String searchFamiliasList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
}else if(searchOption.equals("OptFamilias")) { Pageable pageable = PageRequest.of(page, size);
String[] word = query.split("\\b(y|o)\\b|[,/]");
if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) { if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
ArrayList<Familia> familias = new ArrayList<>(familiaRepository.findAll()); List<Familia> familias = new ArrayList<>(familiaRepository.findAll());
model.addAttribute("familias", familias); model.addAttribute("familias", familias);
return "/list/familias"; return "/list/familias";
} }
}else if(searchOption.equals("OptCiclos")){ return "/list/familias";
}
@GetMapping("/ciclos")
public String searchCiclosList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
String[] word = query.split("\\b(y|o)\\b|[,/]");
if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) { if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
ArrayList<Ciclo> ciclos = new ArrayList<>(cicloRepository.findAll()); List<Ciclo> ciclos = new ArrayList<>(cicloRepository.findAll());
model.addAttribute("ciclos", ciclos); model.addAttribute("ciclos", ciclos);
return "/list/ciclos"; return "/list/ciclos";
} }
}else{ return "/list/ciclos";
System.out.println("ERROR EN BUSQUEDA DE UNA PALABRA"); }
return "error";
@GetMapping("/skills")
public String searchSkillsList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
String[] word = query.split("\\b(y|o)\\b|[,/]");
if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
List<Skill> skills = new ArrayList<>(skillRepository.findAll());
model.addAttribute("skills", skills);
return "/list/skills";
}
return "/list/skills";
} }
return "error";
public Map<String, Object> getPagAtrEmpresas(int pageNum, String query, int size, String sortField, String sortDir, List<Empresa> empresas, List<Integer> itemsPage) {
Map<String, Object> attributes = new HashMap<>();
Page<Empresa> page = this.empresaService.finadAllpaginated(pageNum, size, "id", "asc");
attributes.put("currentPage", pageNum);
attributes.put("totalPages", page.getTotalPages());
attributes.put("totalItems", page.getTotalElements());
attributes.put("sortField", sortField);
attributes.put("sortDir", sortDir);
attributes.put("reverseSortDir", sortDir.equals("asc") ? "desc" : "asc");
attributes.put("empresas", empresas);
attributes.put("query", query);
attributes.put("itemsPage", itemsPage);
return attributes;
}
@GetMapping("/empresas/search")
public ResponseEntity<List<Empresa>> searchEmpresas(@RequestParam String query) {
List<Empresa> empresas = empresaService.search(query);
return ResponseEntity.ok(empresas);
} }
} }

@ -1,18 +1,22 @@
package com.example.proyectofinal.repositories.empresas; package com.example.proyectofinal.repositories.empresas;
import com.example.proyectofinal.models.empresas.Empresa; import com.example.proyectofinal.models.empresas.Empresa;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public interface EmpressaRepository extends JpaRepository<Empresa, Long>, JpaSpecificationExecutor<Empresa> { public interface EmpressaRepository extends JpaRepository<Empresa, Long>, JpaSpecificationExecutor<Empresa> {
Page<Empresa> findAll(Pageable pageable);
//there is value = and nativeQuery = true so the query is written in SQL refering to the table in the database // //there is value = and nativeQuery = true so the query is written in SQL refering to the table in the database
@Query(value = "SELECT * FROM empresas u WHERE MATCH(u.nombre, u.keywords) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true) // @Query(value = "SELECT * FROM empresas u WHERE MATCH(u.nombre, u.keywords) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
public ArrayList<Empresa> getEmpressaByKeywordsOrName(String word); // public ArrayList<Empresa> getEmpressaByKeywordsOrName(String word);
@Query(value = "SELECT * FROM empresas u WHERE u.sector_id = ?1", nativeQuery = true) @Query(value = "SELECT * FROM empresas u WHERE u.sector_id = ?1", nativeQuery = true)
public ArrayList<Empresa> findBySector(Long id); public ArrayList<Empresa> findBySector(Long id);
@ -20,6 +24,10 @@ public interface EmpressaRepository extends JpaRepository<Empresa, Long>, JpaSpe
@Query(value = "SELECT * FROM empresas order by id Asc", nativeQuery = true) @Query(value = "SELECT * FROM empresas order by id Asc", nativeQuery = true)
List<Empresa> findAllAsc(); List<Empresa> findAllAsc();
@Query("SELECT e FROM Empresa e WHERE e.nombre LIKE %:query% OR e.cif LIKE %:query% OR e.correo LIKE %:query% OR e.telefono LIKE %:query% OR e.keywords LIKE %:query% OR e.sector.nombre LIKE %:query%")
List<Empresa> search(@Param("query") String query);
} }

@ -0,0 +1,21 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Empresa;
import org.springframework.data.domain.Page;
import java.util.List;
public interface EmpresaService {
List<Empresa> findAll();
Page<Empresa> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir);
Empresa findById(Long id);
Empresa save(Empresa empresa);
void deleteById(Long id);
List<Empresa> search(String query);
}

@ -0,0 +1,58 @@
package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.repositories.empresas.EmpressaRepository;
import com.example.proyectofinal.servicios.EmpresaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class EmpresaServiceImplementation implements EmpresaService {
@Autowired
private EmpressaRepository empressaRepository;
@Override
public List<Empresa> findAll() {
return empressaRepository.findAll();
}
@Override
public Page<Empresa> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) {
Sort sort = sortDir.equalsIgnoreCase(Sort.Direction.ASC.name())
? Sort.by(sortField).ascending() :
Sort.by(sortField).descending();
Pageable pageable = PageRequest.of(pageNum - 1,pageSize,sort);
return this.empressaRepository.findAll(pageable);
}
@Override
public Empresa findById(Long id) {
return empressaRepository.findById(id).orElse(null);
}
@Override
public Empresa save(Empresa empresa) {
return empressaRepository.save(empresa);
}
@Override
public void deleteById(Long id) {
}
@Override
public List<Empresa> search(String query ) {
return empressaRepository.search(query);
}
}

@ -1,13 +1,15 @@
spring.datasource.url=jdbc:mysql://localhost:3306/projfin spring.datasource.url=jdbc:mysql://localhost:3306/projfin
spring.datasource.username=projfin spring.datasource.username=projfin
spring.h2.console.enabled=true
spring.datasource.password=1234 spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#Configuracion de JPA #Configuracion de JPA
spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true spring.jpa.show-sql=true
#server #server
server.port=8080 server.port=8080

@ -1,64 +0,0 @@
INSERT INTO Familia (nombre) VALUES ('Informatica1');
INSERT INTO Familia (nombre) VALUES ('Informatica2');
INSERT INTO Familia (nombre) VALUES ('Informatica3');
INSERT INTO Familia (nombre) VALUES ('Informatica4');
INSERT INTO Familia (nombre) VALUES ('Informatica5');
-- Insert into Ciclo table
INSERT INTO Ciclo (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones multiplataforma 1','DAM1', 1);
INSERT INTO Ciclo (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones multiplataforma','DAM2', 2);
INSERT INTO Ciclo (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones web 1','DAW2', 3);
INSERT INTO Ciclo (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones web 2','DAW2', 4);
INSERT INTO Ciclo (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones anci 1','ANCI2', 5);
INSERT INTO Ciclo (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones anci 2','ANCI2', 5);
-- Insert into Skill table
INSERT INTO Skill (nombre) VALUES ('Java');
INSERT INTO Skill (nombre) VALUES ('Guitara');
INSERT INTO Skill (nombre) VALUES ('Eletricista');
INSERT INTO Skill (nombre) VALUES ('Moviles');
INSERT INTO Skill (nombre) VALUES ('Deportista');
INSERT INTO Skill (nombre) VALUES ('Python');
-- Insert into Alumno table
INSERT INTO Alumno (nombre, apellido, apellido2, fechaNacimiento, genero, nia, dni, correo, correo2, nacionalidad, keyword, Ciclo_id) VALUES ('John', 'Doe', , '2000-01-01', 'Male', '123456781', '12345678A', 'john.doe@example.com', 'john.smith@example.com', 'American', 'Java, Python', 1);
INSERT INTO Alumno (nombre, apellido, apellido2, fechaNacimiento, genero, nia, dni, correo, correo2, nacionalidad, keyword, Ciclo_id) VALUES ('Jane', 'Doe', 'Johnson', '2000-02-02', 'Female', '123456782', '12345678B', 'jane.doe@example.com', 'jane.johnson@example.com', 'American', 'Guitara', 2);
INSERT INTO Alumno (nombre, apellido, apellido2, fechaNacimiento, genero, nia, dni, correo, correo2, nacionalidad, keyword, Ciclo_id) VALUES ('Robert', 'Smith', , '2000-03-03', 'Male', '123456783', '12345678C', 'robert.smith@example.com', , 'British', 'Eletricista', 3);
INSERT INTO Alumno (nombre, apellido, apellido2, fechaNacimiento, genero, nia, dni, correo, correo2, nacionalidad, keyword, Ciclo_id) VALUES ('Emily', 'Johnson', 'Smith', '2000-04-04', 'Female', '123456784', '12345678D', 'emily.johnson@example.com', 'emily.smith@example.com', 'British', 'Moviles', 4);
INSERT INTO Alumno (nombre, apellido, apellido2, fechaNacimiento, genero, nia, dni, correo, correo2, nacionalidad, keyword, Ciclo_id) VALUES ('James', 'Brown', 'Johnson', '2000-05-05', 'Male', '123456785', '12345678E', 'james.brown@example.com', , 'Australian', 'Deportista', 5);
-- Insert into Sector table
INSERT INTO Sector (nombre) VALUES ('Electricidad');
INSERT INTO Sector (nombre) VALUES ('Informatica');
INSERT INTO Sector (nombre) VALUES ('Deporte');
INSERT INTO Sector (nombre) VALUES ('Musica');
INSERT INTO Sector (nombre) VALUES ('Electronica');
-- Insert into Empresa table
INSERT INTO Empresa (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('LuzT', '123456789W1', 'luzt@example.com', '12345678901', 'trabajador,python', 1);
INSERT INTO Empresa (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('PC R&R', '123456789W2', 'pcrnr@example.com', '12345678902', 'jugador', 2);
INSERT INTO Empresa (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('Runners', '123456789W3', 'run@example.com', '12345678903', 'bailador', 3);
INSERT INTO Empresa (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('Keytara', '123456789W4', 'keytara@example.com', '12345678904', 'programador', 4);
INSERT INTO Empresa (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('Movil', '123456789W5', 'movil@example.com', '12345678905', 'animales', 5);
-- Insert into Contacto table
INSERT INTO Contacto (nombre, apellido1, apellido2, correo, telefono, Empresa_id) VALUES ('Juan', 'Gonzales','Gonzales' , 'juan@example.com', '12345678901', 1);
INSERT INTO Contacto (nombre, apellido1, apellido2, correo, telefono, Empresa_id) VALUES ('Estaban', 'Smit', 'Lokasto', '', '12345678902', 2);
INSERT INTO Contacto (nombre, apellido1, apellido2, correo, telefono, Empresa_id) VALUES ('Pablo', 'Lodrego', , 'pablo@example.com', '12345678903', 3);
INSERT INTO Contacto (nombre, apellido1, apellido2, correo, telefono, Empresa_id) VALUES ('David', 'Borgia', 'Algosto', 'david4@example.com', '12345678904', 4);
INSERT INTO Contacto (nombre, apellido1, apellido2, correo, telefono, Empresa_id) VALUES ('Logan', 'Porlot', , 'logan@example.com', '', 5);
-- Insert into Sucursal table
INSERT INTO Sucursal (nombre, localidad, direccion, sede_central, Empresa_id) VALUES ('Sucursal1', 'Denia', 'Calle 123', true, 1);
INSERT INTO Sucursal (nombre, localidad, direccion, sede_central, Empresa_id) VALUES ('Sucursal2', 'Javea', 'Calle Verdadera 123', true, 2);
INSERT INTO Sucursal (nombre, localidad, direccion, sede_central, Empresa_id) VALUES ('Sucursal3', 'Teulada', 'Calle Alog 123', true, 3);
INSERT INTO Sucursal (nombre, localidad, direccion, sede_central, Empresa_id) VALUES ('Sucursal4', 'Benitachell', 'Calle Loco 123', true, 4);
INSERT INTO Sucursal (nombre, localidad, direccion, sede_central, Empresa_id) VALUES ('Sucursal5', 'Benissa', 'Calle Norm 123', true, 5);
-- Insert into Oferta table
INSERT INTO Oferta (nombre, descripcion, fecha, Sucursal_id) VALUES ('Oferta1', 'Description1', '2023-01-11', 1);
INSERT INTO Oferta (nombre, descripcion, fecha, Sucursal_id) VALUES ('Oferta2', 'Description2', '2023-01-12', 2);
INSERT INTO Oferta (nombre, descripcion, fecha, Sucursal_id) VALUES ('Oferta3', 'Description3', '2023-01-13', 3);
INSERT INTO Oferta (nombre, descripcion, fecha, Sucursal_id) VALUES ('Oferta4', 'Description4', '2023-01-14', 4);
INSERT INTO Oferta (nombre, descripcion, fecha, Sucursal_id) VALUES ('Oferta5', 'Description5', '2023-01-15', 5);

@ -0,0 +1,23 @@
function dynamicSearch() {
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";
}
}
}
}
}

@ -1,64 +1,16 @@
function myFunction() { $('#entriesCount').on('change', function(){
var input, filter, table, tbody, tr, td, i, j, txtValue; var entriesCount = $('#entriesCount').val();
input = document.getElementById("myInput"); console.log(entriesCount);
filter = input.value.toUpperCase(); var url = window.location.href;
table = document.getElementById("table"); var newUrl;
tbody = table.getElementsByTagName("tbody")[0]; if (url.includes('size=')) {
tr = tbody.getElementsByTagName("tr"); newUrl = url.replace(/(size=)[^\&]+/, '$1' + entriesCount);
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 { } else {
tr[i].style.display = "none"; newUrl = url.includes('?') ? url + '&size=' + entriesCount : url + '?size=' + entriesCount;
}
}
}
} }
} window.location.href = newUrl;
});
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;
}
}
}
}

@ -48,28 +48,34 @@
<h1>PAGINA PRINCIPAL</h1> <h1>PAGINA PRINCIPAL</h1>
<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a> <a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a>
</div> </div>
<div class="form-container" style="display: flex; justify-content: center; align-items: center; height: calc(100vh - 60px);"> <div class="form-container" style="display: flex; justify-content: center; align-items: center; height: calc(100vh - 60px);">
<form action="/buscador/search" method="get" id="searchForm"> <form action="/buscador/" method="get" id="searchForm">
<div class="search-container" id="searchContainer"> <div class="search-container" id="searchContainer">
<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>
<select name="searchOption"> <select name="searchOption" id="searchOption">
<option value="OptEmpresa">Empresa</option> <option value="empresas">Empresa</option>
<option value="OptSector">Sector</option> <option value="sectorer">Sector</option>
<option value="OptAlumno">Alumno</option> <option value="alumnos" >Alumno</option>
<option value="OptOferta">Oferta</option> <option value="ofertas">Oferta</option>
<option value="OptSucursal">Sucursal</option> <option value="sucursales">Sucursal</option>
<option value="OptSkill">Skill</option> <option value="skills">Skill</option>
<option value="OptContactos">Contactos</option> <option value="contactos">Contactos</option>
<option value="OptFamilias">Familias</option> <option value="familias">Familias</option>
<option value="OptCiclos">Ciclos</option> <option value="ciclos">Ciclos</option>
</select> </select>
</form> </form>
</div> </div>
<script> <script>
var firstPage= 1;
document.getElementById('searchForm').addEventListener('submit', function(event) {
event.preventDefault();
var searchOption = document.getElementById('searchOption').value;
this.action = "/buscador/" + searchOption +"/page/"+firstPage;
this.submit();
});
window.onload = function() { window.onload = function() {
document.querySelector('form').reset(); document.querySelector('form').reset();
}; };

@ -3,6 +3,7 @@
<head> <head>
<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}">-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Title</title> <title>Title</title>
@ -49,13 +50,27 @@
position: relative; position: relative;
} }
.table { .table {
padding-top: 5px; table-layout: fixed; /* This will create a fixed layout for the table */
width: 100%; width: 100%; /* This will set the table width to 100% */
height: 90vh; }
overflow-y: auto; .table td, .table th {
width: 150px; /* Adjust this value according to your needs */
height: 50px; /* Adjust this value according to your needs */
overflow: hidden; /* This will hide any content that exceeds the cell size */
text-overflow: ellipsis; /* This will add '...' at the end if the content is too long */
white-space: nowrap; /* This will prevent the content from wrapping to the next line */
}
.table thead th {
position: sticky;
top: 0;
background: #fff;
z-index: 10;
} }
.cell{ .table td {
height: 10px; width: 150px; /* Adjust this value according to your needs */
overflow: hidden; /* This will hide any content that exceeds the cell size */
text-overflow: ellipsis; /* This will add '...' at the end if the content is too long */
white-space: nowrap; /* This will prevent the content from wrapping to the next line */
} }
@media screen and (max-width: 600px) { @media screen and (max-width: 600px) {
.table { .table {
@ -92,6 +107,23 @@
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
.page{
display: flex;
justify-content: center;
align-items: center;
margin-top: 20px;
}
.page a{
padding:10px;
}
.inactive {
pointer-events: none;
color: grey;
}
.no-link-style {
color: inherit;
text-decoration: none;
}
</style> </style>
</head> </head>
<body> <body>
@ -108,19 +140,47 @@
<table class="table" id="table"> <table class="table" id="table">
<thead class="thread-light"> <thead class="thread-light">
<tr> <tr>
<th onclick="sortTableCol(0)">Id</th> <th class="table-header">
<th onclick="sortTableCol(1)">Nombre</th> <a th:href="@{'/buscador/empresas/page/' + ${currentPage} + '?sortField=id&sortDir=' + ${reverseSortDir}}">
<th onclick="sortTableCol(2)">Cif</th> Id
<th onclick="sortTableCol(3)">Correo</th> </a>
<th onclick="sortTableCol(4)">Telefono</th> </th>
<th onclick="sortTableCol(5)">Keywords</th> <th class="table-header">
<th onclick="sortTableCol(6)">Sector</th> <a th:href="@{'/buscador/empresas/page/' + ${currentPage} + '?sortField=nombre&sortDir=' + ${reverseSortDir}}">
Nombre
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/empresas/page/' + ${currentPage} + '?sortField=cif&sortDir=' + ${reverseSortDir}}">
Cif
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/empresas/page/' + ${currentPage} + '?sortField=correo&sortDir=' + ${reverseSortDir}}">
Correo
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/empresas/page/' + ${currentPage} + '?sortField=telefono&sortDir=' + ${reverseSortDir}}">
Telefono
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/empresas/page/' + ${currentPage} + '?sortField=keywords&sortDir=' + ${reverseSortDir}}">
Keywords
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/empresas/page/' + ${currentPage} + '?sortField=sector.nombre&sortDir=' + ${reverseSortDir}}">
Sector
</a>
</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr class="cell" th:each="empresa :${empresas}"> <tr class="cell" th:each="empresa :${empresas}">
<td>[[${empresa.id}]]</td> <td>[[${empresa.id}]]</td>
<td><a th:href="@{/empresa/{id}(id=${empresa.id})}">[[${empresa.nombre}]]</a></td> <td><a th:href="@{/empresa/{id}(id=${empresa.id})}">[[${empresa.nombre}]] <i class="fa-solid fa-pen-to-square"></i></a></td>
<td>[[${empresa.cif}]]</td> <td>[[${empresa.cif}]]</td>
<td>[[${empresa.correo}]]</td> <td>[[${empresa.correo}]]</td>
<td>[[${empresa.telefono}]]</td> <td>[[${empresa.telefono}]]</td>
@ -130,17 +190,81 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="page">
<nav aria-label="Page navigation" id="paginationControls">
<ul class="pagination">
<li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${1} + '?query=' + ${query}}">Prim</a>
</li>
<li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${currentPage - 1} + '?query=' + ${query}}">Ant</a>
</li>
<li class="page-item" th:each="pageNum : ${#numbers.sequence(1, totalPages)}" th:classappend="${pageNum eq currentPage ? 'active' : ''}">
<th:block th:if="${pageNum lt 3 or pageNum gt totalPages - 2 or pageNum eq currentPage - 2 or pageNum eq currentPage - 1 or pageNum eq currentPage or pageNum eq currentPage + 1 or pageNum eq currentPage + 2}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${pageNum} + '?query=' + ${query}}">[[${pageNum}]]</a>
</th:block>
<th:block th:if="${pageNum eq 3 and currentPage gt 5}">...</th:block>
<th:block th:if="${pageNum eq totalPages - 2 and currentPage lt totalPages - 4}">...</th:block>
</li>
<li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${currentPage + 1} + '?query=' + ${query}}">Sig</a>
</li>
<li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${totalPages} + '?query=' + ${query}}">Ult</a>
</li>
</ul>
</nav>
</div>
<select id="entriesCount">
<option th:each="item : ${itemsPage}" th:value="${item}" th:text="${item}" th:selected="${item == currentSize}"></option>
</select>
<script src="/orderTable.js"></script> <script src="/orderTable.js"></script>
<script> <script>
function goBack() { function goBack() {
window.history.back(); window.history.back();
} }
document.querySelector('#myInput').addEventListener('keyup', myFunction); document.querySelector('#myInput').addEventListener('input', function() {
document.querySelector('form').addEventListener('submit', function(event) { var query = document.querySelector('#myInput').value;
event.preventDefault(); var paginationControls = document.querySelector('#paginationControls');
myFunction(); var entriesCountDropdown = document.querySelector('#entriesCount');
if (query == '') {
// If the search bar is empty, show the pagination controls and the entries count dropdown, and reload the page
paginationControls.style.display = '';
entriesCountDropdown.style.display = '';
table.style.pointerEvents = '';
location.reload();
} else {
// If the search bar is not empty, hide the pagination controls and the entries count dropdown, and perform the search
paginationControls.style.display = 'none';
entriesCountDropdown.style.display = 'none';
table.style.pointerEvents = 'none';
fetch('/buscador/empresas/search?query=' + query)
.then(response => response.json())
.then(data => {
var tableBody = document.querySelector('#table tbody');
tableBody.innerHTML = '';
data.forEach(empresa => {
var row = document.createElement('tr');
row.innerHTML = `
<td>${empresa.id}</td>
<td>${empresa.nombre}</td>
<td>${empresa.cif}</td>
<td>${empresa.correo}</td>
<td>${empresa.telefono}</td>
<td>${empresa.keywords}</td>
<td>${empresa.sector.nombre}</td>
`;
tableBody.appendChild(row);
});
});
}
}); });
</script> </script>
</body> </body>
</html> </html>
Loading…
Cancel
Save

Powered by INFORMATICA.FP.EDU.ES.