Continuando Los cambios a las listas, encontrando un erro de creacion raro, habia que comental la linea del id en los create htmls. Acabado los contactos y tabla de sucursales esta casi acabado, falta borar por id

master
vicsash 5 months ago
parent 19f3bc0f7f
commit dffe0bdbf0

@ -5,6 +5,7 @@ import com.example.proyectofinal.models.empresas.*;
import com.example.proyectofinal.repositories.empresas.*; import com.example.proyectofinal.repositories.empresas.*;
import com.example.proyectofinal.servicios.ContactosService; import com.example.proyectofinal.servicios.ContactosService;
import com.example.proyectofinal.servicios.SectorService; import com.example.proyectofinal.servicios.SectorService;
import com.example.proyectofinal.servicios.SucursalService;
import com.example.proyectofinal.servicios.implemetations.IEmpresa; import com.example.proyectofinal.servicios.implemetations.IEmpresa;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
@ -33,7 +34,7 @@ public class BuscadorController {
@Autowired @Autowired
private SectorService sectorService; private SectorService sectorService;
@Autowired @Autowired
private SucursalRepository sucursalRepository; private SucursalService sucursalService;
@Autowired @Autowired
private SkillRepository skillRepository; private SkillRepository skillRepository;
@ -101,7 +102,7 @@ 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, Model model,
@ -124,6 +125,28 @@ public class BuscadorController {
return "/list/contactos"; return "/list/contactos";
} }
@GetMapping("/sucursales/page/{pageNum}")
public String searchSucursalesList(@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|[,/]");
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
if (word.length == 1 && (word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas"))) {
sortField = "id";
sortDir = "asc";
}
Page<Sucursal> page = this.sucursalService.finadAllpaginated(pageNum, size, sortField, sortDir);
List<Sucursal> sucursals = page.getContent();
model.addAttribute("currentSize", size);
Map<String, Object> attributes = getPagAtrSucursales(pageNum, query, size, sortField, sortDir, sucursals, itemsPage);
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
model.addAttribute(entry.getKey(), entry.getValue());
}
return "/list/sucursales";
}
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) { 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) {
Pageable pageable = PageRequest.of(page, size); Pageable pageable = PageRequest.of(page, size);
String[] word = query.split("\\b(y|o)\\b|[,/]"); String[] word = query.split("\\b(y|o)\\b|[,/]");
@ -147,23 +170,6 @@ public class BuscadorController {
return "/list/ofertas"; return "/list/ofertas";
} }
@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")) {
List<Sucursal> sucursalSet = new ArrayList<>(sucursalRepository.findAll());
model.addAttribute("sucursales", sucursalSet);
return "/list/sucursales";
}
return "/list/sucursales";
}
@GetMapping("/familias") @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) { 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) {
Pageable pageable = PageRequest.of(page, size); Pageable pageable = PageRequest.of(page, size);
@ -247,6 +253,21 @@ public class BuscadorController {
attributes.put("itemsPage", itemsPage); attributes.put("itemsPage", itemsPage);
return attributes; return attributes;
} }
public Map<String, Object> getPagAtrSucursales(int pageNum, String query, int size, String sortField, String sortDir, List<Sucursal> sucursals, List<Integer> itemsPage) {
Map<String, Object> attributes = new HashMap<>();
Page<Sucursal> page = this.sucursalService.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("sucursales", sucursals);
attributes.put("query", query);
attributes.put("itemsPage", itemsPage);
return attributes;
}
@GetMapping("/empresas/search") @GetMapping("/empresas/search")
public ResponseEntity<List<Empresa>> searchEmpresas(@RequestParam String query) { public ResponseEntity<List<Empresa>> searchEmpresas(@RequestParam String query) {
@ -260,9 +281,15 @@ public class BuscadorController {
return ResponseEntity.ok(sectors); return ResponseEntity.ok(sectors);
} }
@GetMapping("/sectores/search") @GetMapping("/contactos/search")
public ResponseEntity<List<Contacto>> searchContactos(@RequestParam String query) { public ResponseEntity<List<Contacto>> searchContactos(@RequestParam String query) {
List<Contacto> contactos = null; List<Contacto> contactos = contactosService.search(query);
return ResponseEntity.ok(contactos); return ResponseEntity.ok(contactos);
} }
@GetMapping("/sucursales/search")
public ResponseEntity<List<Sucursal>> searchSucursales(@RequestParam String query) {
List<Sucursal> sucursals = sucursalService.search(query);
return ResponseEntity.ok(sucursals);
}
} }

@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
@Controller @Controller
@ -38,22 +39,18 @@ public class ContactoController {
@PostMapping("/contacto/save") @PostMapping("/contacto/save")
public ResponseEntity<String> saveContacto(Contacto contacto, @RequestParam("sector.id") Long empresaId){ public ResponseEntity<String> saveContacto(Contacto contacto, @RequestParam("empresa.id") Long empresaId){
try{ try{
Empresa existingEmpresa = empresaService.findById(empresaId); Empresa existingEmpresa = empresaService.findById(empresaId);
if(existingEmpresa != null) {
contacto.setEmpresa(existingEmpresa); contacto.setEmpresa(existingEmpresa);
} else { if(contactosService.exists(contacto) != null){
return new ResponseEntity<>("Empresa no encontrada", HttpStatus.BAD_REQUEST);
}
if(contactosService.exists(contacto)){
return new ResponseEntity<>("Este contacto ya existe en la base de datos", HttpStatus.BAD_REQUEST); return new ResponseEntity<>("Este contacto ya existe en la base de datos", HttpStatus.BAD_REQUEST);
}else{ }else{
contactosService.save(contacto); contactosService.save(contacto);
return new ResponseEntity<>("El contacto fue guardado con exito", HttpStatus.OK); return new ResponseEntity<>("El contacto fue guardado con exito", HttpStatus.OK);
} }
}catch (Exception e) { }catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
} }
} }
@ -69,7 +66,7 @@ public class ContactoController {
} }
@PostMapping("/contacto/update") @PostMapping("/contacto/update")
public ResponseEntity<String> updateContacto(Contacto contacto, @RequestParam("sector.id") Long empresaId){ public ResponseEntity<String> updateContacto(Contacto contacto, @RequestParam("empresa.id") Long empresaId){
try{ try{
Empresa existingEmpresa = empresaService.findById(empresaId); Empresa existingEmpresa = empresaService.findById(empresaId);
if(existingEmpresa != null) { if(existingEmpresa != null) {

@ -52,13 +52,8 @@ public class EmpressaController {
public ResponseEntity<String> saveEmpresa(Empresa empresa, @RequestParam("sector.id") Long sectorId){ public ResponseEntity<String> saveEmpresa(Empresa empresa, @RequestParam("sector.id") Long sectorId){
try{ try{
Sector existingSector = sectorService.findById(sectorId); Sector existingSector = sectorService.findById(sectorId);
if(existingSector != null) {
empresa.setSector(existingSector); empresa.setSector(existingSector);
} else {
return new ResponseEntity<>("Sector no encontrado", HttpStatus.BAD_REQUEST);
}
if(empresaService.exists(empresa) != null){ if(empresaService.exists(empresa) != null){
System.out.println("Empresa ya existe");
return new ResponseEntity<>("Este empresa ya existe en la base de datos", HttpStatus.BAD_REQUEST); return new ResponseEntity<>("Este empresa ya existe en la base de datos", HttpStatus.BAD_REQUEST);
}else { }else {
empresaService.save(empresa); empresaService.save(empresa);
@ -102,9 +97,8 @@ public class EmpressaController {
@GetMapping("/empresa/delete/{id}") @GetMapping("/empresa/delete/{id}")
public ResponseEntity<String> deleteEmpresa(@PathVariable Long id){ public ResponseEntity<String> deleteEmpresa(@PathVariable Long id){
try{ try{
System.out.println("Deleting empresa with id: " + id);
empresaService.deleteById(id); empresaService.deleteById(id);
return new ResponseEntity<>("El sector ha sido eliminado", HttpStatus.OK); return new ResponseEntity<>("La empresa ha sido eliminado", HttpStatus.OK);
}catch (Exception e){ }catch (Exception e){
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
} }

@ -0,0 +1,89 @@
package com.example.proyectofinal.controllers.modelControllers;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.models.empresas.Sucursal;
import com.example.proyectofinal.servicios.EmpresaService;
import com.example.proyectofinal.servicios.SucursalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@Controller
public class SucursalController {
@Autowired
private SucursalService sucursalService;
@Autowired
private EmpresaService empresaService;
@GetMapping("/admin/sucursal/create")
public String showCreateForm(Model model) {
Sucursal sucursal = new Sucursal();
Empresa empresa = new Empresa();
List<Empresa> empresas = empresaService.findAll();
model.addAttribute("sucursal", sucursal);
model.addAttribute("empresa", empresa);
model.addAttribute("empresas", empresas);
return "admin/sucursal/create";
}
@PostMapping("/sucursal/save")
public ResponseEntity<String> saveSucursal(Sucursal sucursal, @RequestParam("empresa.id") Long empresaId){
try{
Empresa existingEmpresa = empresaService.findById(empresaId);
sucursal.setEmpresa(existingEmpresa);
if(sucursalService.exists(sucursal) != null){
return new ResponseEntity<>("Este sucursal ya existe en la base de datos", HttpStatus.BAD_REQUEST);
}else {
sucursalService.save(sucursal);
return new ResponseEntity<>("La sucursal fue guardado con exito", HttpStatus.OK);
}
}catch (Exception e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/admin/sucursal/update/{id}")
public String showUpdateForm(Model model, @PathVariable Long id) {
Sucursal sucursal = sucursalService.findById(id);
Empresa empresa = new Empresa();
List<Empresa> empresas = empresaService.findAll();
model.addAttribute("sucursal", sucursal);
model.addAttribute("empresa", empresa);
model.addAttribute("empresas", empresas);
model.addAttribute("sedeCentral", sucursal.getSedeCentral());
return "admin/sucursal/update";
}
@PostMapping("/sucursal/update")
public ResponseEntity<String> updateSucursal(Sucursal sucursal, @RequestParam("empresa.id") Long sectorId){
try{
Empresa existingEmpresa = empresaService.findById(sectorId);
sucursal.setEmpresa(existingEmpresa);
sucursalService.save(sucursal);
return new ResponseEntity<>("Los datos del sucursal fue renovados con exito", HttpStatus.OK);
}catch (Exception e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/sucursal/delete/{id}")
public ResponseEntity<String> deleteSucursal(@PathVariable Long id){
System.out.println("Attempting to delete Sucursal with ID: " + id);
try{
sucursalService.deleteById(id);
return new ResponseEntity<>("La empresa ha sido eliminado", HttpStatus.OK);
}catch (Exception e){
System.out.println("Error deleting Sucursal: " + e.getMessage());
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

@ -79,64 +79,4 @@ public class Alumno {
@JoinColumn(name = "fk_ciclo",referencedColumnName = "id") @JoinColumn(name = "fk_ciclo",referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE) @OnDelete(action = OnDeleteAction.CASCADE)
private Ciclo ciclo; private Ciclo ciclo;
public Alumno(@NonNull String nombre, @NonNull String apellido, String apellido2, @NonNull Date fechaNacimiento, @NonNull String genero, @NonNull String nia, @NonNull String dni, @NonNull String correo, String correo2, @NonNull String nacionalidad, @NonNull String keyword, Set<Skill> skills, Ciclo ciclo) {
this.nombre = nombre;
this.apellido = apellido;
this.apellido2 = apellido2;
this.fechaNacimiento = fechaNacimiento;
this.genero = genero;
this.nia = nia;
this.dni = dni;
this.correo = correo;
this.correo2 = correo2;
this.nacionalidad = nacionalidad;
this.keywords = keyword;
this.skills = skills;
this.ciclo = ciclo;
}
// public Alumno(@NonNull String nombre, @NonNull String apellido, String apellido2, @NonNull Date fechaNacimiento, @NonNull String genero, @NonNull String nia, @NonNull String dni, @NonNull String correo, @NonNull String nacionalidad, @NonNull String keyword, Set<Skill> skills, Ciclo ciclo) {
// this.nombre = nombre;
// this.apellido = apellido;
// this.apellido2 = apellido2;
// this.fechaNacimiento = fechaNacimiento;
// this.genero = genero;
// this.nia = nia;
// this.dni = dni;
// this.correo = correo;
// this.nacionalidad = nacionalidad;
// this.keyword = keyword;
// this.skills = skills;
// this.ciclo = ciclo;
// }
//
// public Alumno( @NonNull String nombre, @NonNull String apellido, @NonNull Date fechaNacimiento, @NonNull String genero, @NonNull String nia, @NonNull String dni, @NonNull String correo, @NonNull String nacionalidad, @NonNull String keyword, Set<Skill> skills, Ciclo ciclo) {
// this.nombre = nombre;
// this.apellido = apellido;
// this.fechaNacimiento = fechaNacimiento;
// this.genero = genero;
// this.nia = nia;
// this.dni = dni;
// this.correo = correo;
// this.nacionalidad = nacionalidad;
// this.keyword = keyword;
// this.skills = skills;
// this.ciclo = ciclo;
// }
//
// public Alumno(@NonNull String nombre, @NonNull String apellido, @NonNull Date fechaNacimiento, @NonNull String genero, @NonNull String nia, @NonNull String dni, @NonNull String correo, String correo2, @NonNull String nacionalidad, @NonNull String keyword, Set<Skill> skills, Ciclo ciclo) {
// this.nombre = nombre;
// this.apellido = apellido;
// this.fechaNacimiento = fechaNacimiento;
// this.genero = genero;
// this.nia = nia;
// this.dni = dni;
// this.correo = correo;
// this.correo2 = correo2;
// this.nacionalidad = nacionalidad;
// this.keyword = keyword;
// this.skills = skills;
// this.ciclo = ciclo;
// }
} }

@ -33,9 +33,4 @@ public class Ciclo {
@OnDelete(action = OnDeleteAction.CASCADE) @OnDelete(action = OnDeleteAction.CASCADE)
private Familia familia; private Familia familia;
public Ciclo(@NonNull String nombre, @NonNull String codigo, Familia familia) {
this.nombre = nombre;
this.codigo = codigo;
this.familia = familia;
}
} }

@ -21,14 +21,14 @@ public class Contacto {
private long id; private long id;
@NonNull @NonNull
@Column(length = 70) @Column(length = 75)
private String nombre; private String nombre;
@NonNull @NonNull
@Column(length = 70) @Column(length = 125)
private String apellido; private String apellido;
@Column(length = 70) @Column(length = 125)
private String apellido2; private String apellido2;
@Column(length = 100) @Column(length = 100)
@ -37,25 +37,8 @@ public class Contacto {
@Column(length = 70) @Column(length = 70)
private String telefono; private String telefono;
@ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.LAZY) @ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.EAGER)
@JoinColumn(name = "fk_empressa",referencedColumnName = "id") @JoinColumn(name = "fk_empressa",referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE) @OnDelete(action = OnDeleteAction.CASCADE)
private Empresa empresa; private Empresa empresa;
public Contacto(@NonNull String nombre, @NonNull String apellido1, String apellido2, String correo, String telefono, Empresa empresa) {
this.nombre = nombre;
this.apellido = apellido1;
this.apellido2 = apellido2;
this.correo = correo;
this.telefono = telefono;
this.empresa = empresa;
}
public Contacto(@NonNull String nombre, @NonNull String apellido1, String correo, String telefono, Empresa empresa) {
this.nombre = nombre;
this.apellido = apellido1;
this.correo = correo;
this.telefono = telefono;
this.empresa = empresa;
}
} }

@ -43,13 +43,4 @@ public class Empresa {
@JoinColumn(name = "fk_sector",referencedColumnName = "id") @JoinColumn(name = "fk_sector",referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE) @OnDelete(action = OnDeleteAction.CASCADE)
private Sector sector; private Sector sector;
public Empresa(@NonNull String nombre, @NonNull String cif, @NonNull String correo, @NonNull String telefono1, @NonNull String keywords, Sector sector) {
this.nombre = nombre;
this.cif = cif;
this.correo = correo;
this.telefono = telefono1;
this.keywords = keywords;
this.sector = sector;
}
} }

@ -53,11 +53,4 @@ public class Oferta {
) )
private Set<Skill> skills; private Set<Skill> skills;
public Oferta(@NonNull String nombre, String descripcion, @NonNull String fecha, Sucursal sucursal, Set<Skill> skills) {
this.nombre = nombre;
this.descripcion = descripcion;
this.fecha = fecha;
this.sucursal = sucursal;
this.skills = skills;
}
} }

@ -20,7 +20,4 @@ public class Sector {
@Column(length = 75) @Column(length = 75)
private String nombre; private String nombre;
public Sector(@NonNull String nombre) {
this.nombre = nombre;
}
} }

@ -30,7 +30,4 @@ public class Skill {
@ManyToMany(mappedBy = "skills") @ManyToMany(mappedBy = "skills")
private Set<Oferta> ofertas; private Set<Oferta> ofertas;
public Skill(@NonNull String nombre) {
this.nombre = nombre;
}
} }

@ -35,16 +35,12 @@ public class Sucursal {
@Name("sede_central") @Name("sede_central")
private boolean sedeCentral; private boolean sedeCentral;
@ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.LAZY) @ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.EAGER)
@JoinColumn(name = "fk_empressa", referencedColumnName = "id") @JoinColumn(name = "fk_empressa", referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE) @OnDelete(action = OnDeleteAction.CASCADE)
private Empresa empresa; private Empresa empresa;
public Sucursal(@NonNull String nombre, @NonNull String localidad, @NonNull String direccion, @NonNull boolean sedeCentral, Empresa empresa) { public boolean getSedeCentral() {
this.nombre = nombre; return this.sedeCentral;
this.localidad = localidad;
this.direccion = direccion;
this.sedeCentral = sedeCentral;
this.empresa = empresa;
} }
} }

@ -2,9 +2,12 @@ package com.example.proyectofinal.repositories.empresas;
import com.example.proyectofinal.models.empresas.Contacto; import com.example.proyectofinal.models.empresas.Contacto;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
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;
public interface ContactoRepository extends JpaRepository<Contacto, Long> { public interface ContactoRepository extends JpaRepository<Contacto, Long> {
@Query("SELECT c FROM Contacto c WHERE c.empresa.id = ?1") @Query("SELECT c FROM Contacto c WHERE c.empresa.id = ?1")
@ -19,6 +22,13 @@ public interface ContactoRepository extends JpaRepository<Contacto, Long> {
@Query(value="SELECT * FROM contactos WHERE fk_empressa = ?1", nativeQuery = true) @Query(value="SELECT * FROM contactos WHERE fk_empressa = ?1", nativeQuery = true)
public ArrayList<Contacto> findByEmpresaId(Long id); public ArrayList<Contacto> findByEmpresaId(Long id);
@Query(value="SELECT * FROM contactos WHERE nombre=?1", nativeQuery = true) @Query(value="SELECT * FROM contactos c WHERE nombre= ?1 and apellido = ?2 and apellido2 =?3", nativeQuery = true)
boolean existsByNombre(String nombre); Contacto existsByNombreApe(String nombre, String apellido, String apellido2);
@Query("SELECT c FROM Contacto c WHERE c.nombre LIKE %:query% OR c.apellido LIKE %:query% OR c.apellido2 LIKE %:query% OR c.correo LIKE %:query% OR c.telefono LIKE %:query% OR c.empresa.nombre LIKE %:query% OR CAST(c.id AS string) = :query")
List<Contacto> search(@Param("query") String query);
@Modifying
@Query(value = "INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES (:nombre, :apellido, :apellido2, :correo, :telefono, :fk_empressa)", nativeQuery = true)
void insertContacto(@Param("nombre") String nombre, @Param("apellido") String apellido, @Param("apellido2") String apellido2, @Param("correo") String correo, @Param("telefono") String telefono, @Param("fk_empressa") Long fk_empressa);
} }

@ -3,6 +3,7 @@ package com.example.proyectofinal.repositories.empresas;
import com.example.proyectofinal.models.empresas.Sucursal; import com.example.proyectofinal.models.empresas.Sucursal;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
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;
@ -15,4 +16,10 @@ public interface SucursalRepository extends JpaRepository<Sucursal, Long> {
@Query(value="Select * from sucursales where fk_empressa = ?1", nativeQuery = true) @Query(value="Select * from sucursales where fk_empressa = ?1", nativeQuery = true)
public List<Sucursal> findByEmpresaId(Long id); public List<Sucursal> findByEmpresaId(Long id);
@Query("SELECT s FROM Sucursal s WHERE s.nombre LIKE %:query% OR s.localidad LIKE %:query% OR s.direccion LIKE %:query% OR CAST(s.id AS string) = :query")
List<Sucursal> search(@Param("query") String query);
@Query("SELECT s FROM Sucursal s WHERE s.nombre = :nombre")
Sucursal findByName(String nombre);
} }

@ -10,11 +10,13 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.example.proyectofinal.repositories.empresas.ContactoRepository; import com.example.proyectofinal.repositories.empresas.ContactoRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
@Service @Service
public class ContactosService implements IContactos { public class ContactosService implements IContactos {
private static final Logger log = LoggerFactory.getLogger(ContactosService.class);
@Autowired @Autowired
private ContactoRepository contactoRepository; private ContactoRepository contactoRepository;
@ -48,6 +50,26 @@ public class ContactosService implements IContactos {
return contactoRepository.save(contacto); return contactoRepository.save(contacto);
} }
public void insertContacto(Contacto contacto) {
Contacto newContacto = new Contacto();
long id = Long.parseLong(null);
newContacto.setId(id);
newContacto.setNombre(contacto.getNombre());
newContacto.setApellido(contacto.getApellido());
newContacto.setApellido2(contacto.getApellido2());
newContacto.setCorreo(contacto.getCorreo());
newContacto.setTelefono(contacto.getTelefono());
newContacto.setEmpresa(contacto.getEmpresa());
contactoRepository.insertContacto(
newContacto.getNombre(),
newContacto.getApellido(),
newContacto.getApellido2(),
newContacto.getCorreo(),
newContacto.getTelefono(),
newContacto.getEmpresa().getId()
);
}
@Override @Override
public void deleteById(Long id) { public void deleteById(Long id) {
contactoRepository.deleteById(id); contactoRepository.deleteById(id);
@ -55,7 +77,7 @@ public class ContactosService implements IContactos {
@Override @Override
public List<Contacto> search(String query) { public List<Contacto> search(String query) {
return List.of(); return contactoRepository.search(query);
} }
@Override @Override
@ -67,7 +89,7 @@ public class ContactosService implements IContactos {
} }
@Override @Override
public boolean exists(Contacto contacto) { public Contacto exists(Contacto contacto) {
return contactoRepository.existsByNombre(contacto.getNombre()); return contactoRepository.existsByNombreApe(contacto.getNombre(),contacto.getApellido(),contacto.getApellido2());
} }
} }

@ -1,11 +1,17 @@
package com.example.proyectofinal.servicios; package com.example.proyectofinal.servicios;
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.Sucursal; import com.example.proyectofinal.models.empresas.Sucursal;
import com.example.proyectofinal.repositories.empresas.OfertaRepository;
import com.example.proyectofinal.repositories.empresas.SkillRepository;
import com.example.proyectofinal.repositories.empresas.SucursalRepository; import com.example.proyectofinal.repositories.empresas.SucursalRepository;
import com.example.proyectofinal.servicios.implemetations.ISucursal; import com.example.proyectofinal.servicios.implemetations.ISucursal;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; 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 org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -14,6 +20,12 @@ public class SucursalService implements ISucursal {
@Autowired @Autowired
private SucursalRepository sucursalRepository; private SucursalRepository sucursalRepository;
@Autowired
private OfertaService ofertaService;
@Autowired
private SkillRepository skillRepository;
@Autowired
private OfertaRepository ofertaRepository;
@Override @Override
public List<Sucursal> findAll() { public List<Sucursal> findAll() {
@ -22,7 +34,11 @@ public class SucursalService implements ISucursal {
@Override @Override
public Page<Sucursal> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) { public Page<Sucursal> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) {
return null; 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.sucursalRepository.findAll(pageable);
} }
@Override @Override
@ -42,12 +58,18 @@ public class SucursalService implements ISucursal {
@Override @Override
public void deleteById(Long id) { public void deleteById(Long id) {
Sucursal sucursal = findById(id);
List<Oferta> ofertas = ofertaService.findBySucursal(sucursal);
for (Oferta oferta : ofertas) {
ofertaRepository.deleteSkillsByOfertaId(oferta.getId());
ofertaService.deleteById(oferta.getId());
}
sucursalRepository.deleteById(id); sucursalRepository.deleteById(id);
} }
@Override @Override
public List<Sucursal> search(String query) { public List<Sucursal> search(String query) {
return List.of(); return sucursalRepository.search(query);
} }
@Override @Override
@ -55,4 +77,9 @@ public class SucursalService implements ISucursal {
return sucursalRepository.findByEmpresaId(empresa.getId()); return sucursalRepository.findByEmpresaId(empresa.getId());
} }
@Override
public Sucursal exists(Sucursal sucursal) {
return sucursalRepository.findByName(sucursal.getNombre());
}
} }

@ -24,5 +24,5 @@ public interface IContactos {
void deleteByEmpresa(Empresa empresa); void deleteByEmpresa(Empresa empresa);
boolean exists(Contacto contacto); Contacto exists(Contacto contacto);
} }

@ -22,4 +22,6 @@ public interface ISucursal {
List<Sucursal> search(String query); List<Sucursal> search(String query);
List<Sucursal> findByEmpresa(Empresa empresa); List<Sucursal> findByEmpresa(Empresa empresa);
Sucursal exists(Sucursal sucursal);
} }

@ -4,6 +4,10 @@
<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" 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">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css">
<script type="text/javascript" src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Title</title> <title>Title</title>
<style> <style>
@ -11,33 +15,27 @@
</style> </style>
</head> </head>
<body> <body>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> <h1>Listado de Sucursales<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
<h1>Listado de Alumnos<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<div class="table"> <div class="table">
<table class ="table table-hover table-responsive-xl"> <table class ="table table-hover table-responsive-xl">
<thead class="thread-light"> <thead class="thread-light">
<tr> <tr>
<th>Id</th> <th>Id</th>
<th>Nombre</th> <th>Nombre</th>
<th>Apellido 1</th> <th>Localidad</th>
<th>Apellido 2</th> <th>Dirección</th>
<th>Correo</th> <th>SedeCentral</th>
<th>Telefono</th>
<th>Empressa</th> <th>Empressa</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr class="cell" th:each="contacto :${contactos}"> <tr class="cell" th:each="sucursal :${sucursales}">
<td>[[${contacto.id}]]</td> <td>[[${sucursal.id}]]</td>
<td>[[${contacto.nombre}]]</td> <td>[[${sucursal.nombre}]]</td>
<td>[[${contacto.apellido}]]</td> <td>[[${sucursal.localidad}]]</td>
<td>[[${contacto.apellido2}]]</td> <td>[[${sucursal.direccion}]]</td>
<td>[[${contacto.correo}]]</td> <td>[[${sucursal.sedeCentral}]]</td>
<td>[[${contacto.telefono}]]</td> <td>[[${sucursal.empresa.nombre}]]</td>
<td>[[${contacto.empresa.nombre}]]</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Creacion: Empresa</title> <title>Creacion: Contacto</title>
<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" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
@ -49,51 +49,51 @@
</style> </style>
</head> </head>
<body> <body>
<h1>Añadir Empresa<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1> <h1>Añadir Contacto<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<form th:action="@{/contacto/save}" method="post" enctype="multipart/form-data" th:object="${contacto}"> <form th:action="@{/contacto/save}" method="post" enctype="multipart/form-data" th:object="${contacto}">
<input type="hidden" th:field="*{id}"/> <!-- <input type="hidden" th:field="*{id}"/>-->
<div class="p-3"> <div class="p-3">
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="nombre">Nombre</label> <label class="col-sm-3 col-form-label" for="nombre">Nombre</label>
<div class = "col-sm-9"> <div class = "col-sm-9">
<input type="text" th:field="*{nombre}" required minlength="2" maxlength="128" class="form-control" id="nombre"> <input type="text" th:field="*{nombre}" required minlength="2" maxlength="75" class="form-control" id="nombre">
</div> </div>
</div> </div>
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="cif">Apellido</label> <label class="col-sm-3 col-form-label" for="cif">Apellido</label>
<div class = "col-sm-9"> <div class = "col-sm-9">
<input type="text" th:field="*{apellido}" title="Entra un nombre" class="form-control" id="cif"> <input type="text" th:field="*{apellido}" required minlength="2" maxlength="75" title="Entra un nombre" class="form-control" id="cif">
</div> </div>
</div> </div>
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="apellido2">Apellido2</label> <label class="col-sm-3 col-form-label" for="apellido2">Apellido2</label>
<div class = "col-sm-9"> <div class = "col-sm-9">
<input type="text" th:field="*{apellido2}" class="form-control" id="apellido2"> <input type="text" th:field="*{apellido2}" minlength="2" maxlength="75" class="form-control" id="apellido2">
</div> </div>
</div> </div>
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="correo">Correo</label> <label class="col-sm-3 col-form-label" for="correo">Correo</label>
<div class = "col-sm-9"> <div class = "col-sm-9">
<input type="text" th:field="*{correo}" required pattern="^\d{10}$" title="Entra un numero de telefono valido de 10 digitos" class="form-control" id="correo"> <input type="text" th:field="*{correo}" title="Entra en correo valido." class="form-control" id="correo">
</div> </div>
</div> </div>
<!--
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="Telefono">Keywords</label> <label class="col-sm-3 col-form-label" for="telefono">Telefono</label>
<div class = "col-sm-9"> <div class = "col-sm-9">
<input type="text" th:field="*{keywords}" required pattern="([a-zA-Z0-9]+,)*[a-zA-Z0-9]+" title="Los keywords tiene que ser separados por una ," class="form-control" id="keywords"> <input type="text" th:field="*{telefono}" required pattern="^\d{10}$" title="Entra un numero de telefono valido de 10 digitos" class="form-control" id="telefono">
</div> </div>
</div> </div>
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="sector">Empresas</label> <label class="col-sm-3 col-form-label" for="empresa">Empresas</label>
<div class = "col-sm-9"> <div class = "col-sm-9">
<select th:field="*{sector.id}" class="form-control" id="sector"> <select th:field="*{empresa.id}" class="form-control" id="empresa">
<option th:each="sector : ${sectores}" th:value="${sector.id}" th:text="${sector.nombre}"></option> <option th:each="empresa : ${empresas}" th:value="${empresa.id}" th:text="${empresa.nombre}"></option>
</select> </select>
</div> </div>
</div> </div>
@ -103,11 +103,10 @@
<input type="button" value="Cancelar" id="btnCancelar" class="btn" onclick="goBack()"/> <input type="button" value="Cancelar" id="btnCancelar" class="btn" onclick="goBack()"/>
</div> </div>
</div> </div>
</form>--> </form>
<script> <script>
function goBack() { function goBack() {
console.log("goBack function called");
window.history.back(); window.history.back();
} }
$(document).ready(function () { $(document).ready(function () {
@ -115,18 +114,18 @@
event.preventDefault(); event.preventDefault();
var formData = $(this).serialize(); var formData = $(this).serialize();
var sectorId = $('#sector').val(); var empresaId = $('#empresa').val();
formData += '&sector=' + encodeURIComponent(sectorId); formData += '&contacto=' + encodeURIComponent(empresaId);
$.ajax({ $.ajax({
url: '/empresa/save', url: '/contacto/save',
type: 'post', type: 'post',
data: formData, data: formData,
success: function (message) { success: function (message) {
if(message === "La empresa fue guardado con exito") { if(message === "El contacto fue guardado con exito") {
alert("La empresa fue guardado con exito") alert("El contacto fue guardado con exito")
window.history.go(-1); // Go back two pages window.history.go(-1); // Go back two pages
} else if(message === "Este empresa ya existe en la base de datos"){ } else if(message === "Este contacto ya existe en la base de datos"){
alert("Este empresa ya existe en la base de datos"); alert("Este El contacto ya existe en la base de datos");
window.history.go(-1); window.history.go(-1);
}else{ }else{
alert("Error, consulata a los informaticos") alert("Error, consulata a los informaticos")

@ -51,50 +51,48 @@
<body> <body>
<h1>Editar datos de Empresa<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1> <h1>Editar datos de Empresa<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<form th:action="@{/empresa/update}" method="post" enctype="multipart/form-data" th:object="${empresa}"> <form th:action="@{/contacto/update}" method="post" enctype="multipart/form-data" th:object="${contacto}">
<input type="hidden" th:field="*{id}"/> <input type="hidden" th:field="*{id}"/>
<div class="p-3"> <div class="p-3">
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="nombre">Nombre</label> <label class="col-sm-3 col-form-label" for="nombre">Nombre</label>
<div class = "col-sm-9"> <div class = "col-sm-9">
<input type="text" th:field="*{nombre}" th:value="*{nombre}" required minlength="2" maxlength="128" class="form-control" id="nombre"> <input type="text" th:field="*{nombre}" required minlength="2" maxlength="75" class="form-control" id="nombre">
</div> </div>
</div> </div>
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="cif">Cif</label> <label class="col-sm-3 col-form-label" for="cif">Apellido</label>
<div class = "col-sm-9"> <div class = "col-sm-9">
<input type="text" th:field="*{cif}" th:value="*{cif}" required pattern="^[A-HJ-NP-SUVW]{1}[0-9]{7}[0-9A-J]{1}$" title="Entra un cif valido eje. W12345678" class="form-control" id="cif"> <input type="text" th:field="*{apellido}" required minlength="2" maxlength="75" title="Entra un nombre" class="form-control" id="cif">
</div> </div>
</div> </div>
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="correo">Correo</label> <label class="col-sm-3 col-form-label" for="apellido2">Apellido2</label>
<div class = "col-sm-9"> <div class = "col-sm-9">
<input type="text" th:field="*{correo}" th:value="*{correo}" required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" title="Entra en correo valido." class="form-control" id="correo"> <input type="text" th:field="*{apellido2}" minlength="2" maxlength="75" class="form-control" id="apellido2">
</div> </div>
</div> </div>
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="telefono">Telefono</label> <label class="col-sm-3 col-form-label" for="correo">Correo</label>
<div class = "col-sm-9"> <div class = "col-sm-9">
<input type="text" th:field="*{telefono}" th:value="*{telefono}" required pattern="^\d{10}$" title="Entra un numero de telefono valido de 10 digitos" class="form-control" id="telefono"> <input type="text" th:field="*{correo}" required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" title="Entra en correo valido." class="form-control" id="correo">
</div> </div>
</div> </div>
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="keywords">Keywords</label> <label class="col-sm-3 col-form-label" for="telefono">Telefono</label>
<div class = "col-sm-9"> <div class = "col-sm-9">
<input type="text" th:field="*{keywords}" th:value="*{keywords}" required pattern="([a-zA-Z0-9]+,)*[a-zA-Z0-9]+" title="Los keywords tiene que ser separados por una ," class="form-control" id="keywords"> <input type="text" th:field="*{telefono}" required pattern="^\d{10}$" title="Entra un numero de telefono valido de 10 digitos" class="form-control" id="telefono">
</div> </div>
</div> </div>
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="sector">Sector</label> <label class="col-sm-3 col-form-label" for="empresa">Empresas</label>
<div class = "col-sm-9"> <div class = "col-sm-9">
<select th:field="*{sector.id}" class="form-control" id="sector"> <select th:field="*{empresa.id}" class="form-control" id="empresa">
<option th:each="sector : ${sectores}" th:value="${sector.id}" th:text="${sector.nombre}" th:selected="${sector.id == empresa.sector.id}"></option> <option th:each="empresa : ${empresas}" th:value="${empresa.id}" th:text="${empresa.nombre}"></option>
</select> </select>
</div> </div>
</div> </div>
@ -116,15 +114,15 @@
event.preventDefault(); event.preventDefault();
var formData = $(this).serialize(); var formData = $(this).serialize();
var sectorId = $('#sector').val(); var empresaId = $('#empresa').val();
formData += '&sector=' + encodeURIComponent(sectorId); formData += '&contacto=' + encodeURIComponent(empresaId);
$.ajax({ $.ajax({
url: '/empresa/update', url: '/contacto/update',
type: 'post', type: 'post',
data: formData, data: formData,
success: function (message) { success: function (message) {
if(message === "Los datos de la empresa fue renovados con exito") { if(message === "Los datos del contacto fue renovados con exito") {
alert("Los datos de la empresa fue renovada con exito") alert("Los datos del contacto fue renovada con exito")
window.history.go(-1); // Go back two pages window.history.go(-1); // Go back two pages
}else{ }else{
alert("Error, consulata a los informaticos") alert("Error, consulata a los informaticos")

@ -52,7 +52,7 @@
<h1>Añadir Empresa<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1> <h1>Añadir Empresa<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<form th:action="@{/empresa/save}" method="post" enctype="multipart/form-data" th:object="${empresa}"> <form th:action="@{/empresa/save}" method="post" enctype="multipart/form-data" th:object="${empresa}">
<input type="hidden" th:field="*{id}"/> <!--<input type="hidden" th:field="*{id}"/>-->
<div class="p-3"> <div class="p-3">
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="nombre">Nombre</label> <label class="col-sm-3 col-form-label" for="nombre">Nombre</label>
@ -116,7 +116,7 @@
var formData = $(this).serialize(); var formData = $(this).serialize();
var sectorId = $('#sector').val(); var sectorId = $('#sector').val();
formData += '&sector=' + encodeURIComponent(sectorId); formData += '&empresa=' + encodeURIComponent(sectorId);
$.ajax({ $.ajax({
url: '/empresa/save', url: '/empresa/save',
type: 'post', type: 'post',

@ -52,7 +52,7 @@
<h1>Añadir Sector<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1> <h1>Añadir Sector<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<form th:action="@{/sector/save}" method="post" enctype="multipart/form-data" th:object="${sector}"> <form th:action="@{/sector/save}" method="post" enctype="multipart/form-data" th:object="${sector}">
<input type="hidden" th:field="*{id}"/> <!--<input type="hidden" th:field="*{id}"/>-->
<div class="p-3"> <div class="p-3">
<div class ="form-group row"> <div class ="form-group row">
<label class="col-sm-3 col-form-label" for="nombre">Nombre</label> <label class="col-sm-3 col-form-label" for="nombre">Nombre</label>

@ -0,0 +1,139 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Creacion: Empresa</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" th:href="@{/top.css}">
<style>
form {
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
width: 100%;
max-width: none;
margin: auto;
padding: 25px;
margin-top: 100px;
}
.btn {
margin-top: 25px;
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
}
form input[type="text"]{
width: 75%;
}
form label{
font-size: 20px;
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
body, h1 {
margin: 0;
padding: 0;
width: 100%;
box-sizing: border-box;
}
</style>
</head>
<body>
<h1>Añadir Empresa<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<form th:action="@{/sucursal/save}" method="post" enctype="multipart/form-data" th:object="${sucursal}">
<!--<input type="hidden" th:field="*{id}"/>-->
<div class="p-3">
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="nombre">Nombre</label>
<div class = "col-sm-9">
<input type="text" th:field="*{nombre}" required minlength="2" maxlength="128" class="form-control" id="nombre">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="localidad">Localidad</label>
<div class = "col-sm-9">
<input type="text" th:field="*{localidad}" required minlength="2" maxlength="75" title="Entra una localidad valida" class="form-control" id="localidad">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="direccion">Direccion</label>
<div class = "col-sm-9">
<input type="text" th:field="*{direccion}" required minlength="2" maxlength="75" title="Entra una dirreccion valida." class="form-control" id="direccion">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="sedeCentral">Sede Central</label>
<div class = "col-sm-9">
<input type="number" th:field="*{sedeCentral}" required min="0" max="1" title="Entra 0 o 1" class="form-control" id="sedeCentral">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="empresa">Empresas</label>
<div class = "col-sm-9">
<select th:field="*{empresa.id}" class="form-control" id="empresa">
<option th:each="empresa : ${empresas}" th:value="${empresa.id}" th:text="${empresa.nombre}"></option>
</select>
</div>
</div>
<div class="text-center">
<input type="submit" value="Guardar" class="btn"/>
<input type="button" value="Cancelar" id="btnCancelar" class="btn" onclick="goBack()"/>
</div>
</div>
</form>
<script>
function goBack() {
console.log("goBack function called");
window.history.back();
}
$(document).ready(function () {
$("form").on("submit", function (event) {
event.preventDefault();
var formData = $(this).serialize();
var empresaId = $('#empresa').val();
formData += '&sucursal=' + encodeURIComponent(empresaId);
$.ajax({
url: '/sucursal/save',
type: 'post',
data: formData,
success: function (message) {
if(message === "La sucursal fue guardado con exito") {
alert("La sucursal fue guardado con exito")
window.history.go(-1); // Go back two pages
} else if(message === "Este sucursal ya existe en la base de datos"){
alert("Este sucursal ya existe en la base de datos");
window.history.go(-1);
}else{
alert("Error, consulata a los informaticos")
window.history.go(-1)
}
},
error: function (jqXHR) {
alert(jqXHR.responseText);
window.history.back();
}
});
});
});
</script>
</body>
</html>

@ -0,0 +1,137 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Update: Empresa</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" th:href="@{/top.css}">
<style>
form {
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
width: 100%;
max-width: none;
margin: auto;
padding: 25px;
margin-top: 100px;
}
.btn {
margin-top: 25px;
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
}
form input[type="text"]{
width: 75%;
}
form label{
font-size: 20px;
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
body, h1 {
margin: 0;
padding: 0;
width: 100%;
box-sizing: border-box;
}
</style>
</head>
<body>
<h1>Editar datos de Empresa<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<form th:action="@{/sucursal/update}" method="post" enctype="multipart/form-data" th:object="${sucursal}">
<input type="hidden" th:field="*{id}"/>
<div class="p-3">
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="nombre">Nombre</label>
<div class = "col-sm-9">
<input type="text" th:field="*{nombre}" required minlength="2" maxlength="128" class="form-control" id="nombre">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="localidad">Localidad</label>
<div class = "col-sm-9">
<input type="text" th:field="*{localidad}" required minlength="2" maxlength="75" title="Entra una localidad valida" class="form-control" id="localidad">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="direccion">Direccion</label>
<div class = "col-sm-9">
<input type="text" th:field="*{direccion}" required minlength="2" maxlength="75" title="Entra una dirreccion valida." class="form-control" id="direccion">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="sedeCentral">Sede Central</label>
<div class = "col-sm-9">
<input type="text" th:field="*{sedeCentral}" pattern="[0-1]" title="Enter either 0 or 1" class="form-control" id="sedeCentral" th:value="${sedeCentral}">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="empresa">Empresas</label>
<div class = "col-sm-9">
<select th:field="*{empresa.id}" class="form-control" id="empresa">
<option th:each="empresa : ${empresas}" th:value="${empresa.id}" th:text="${empresa.nombre}"></option>
</select>
</div>
</div>
<div class="text-center">
<input type="submit" value="Guardar" class="btn"/>
<input type="button" value="Cancelar" id="btnCancelar" class="btn" onclick="goBack()"/>
</div>
</div>
</form>
<script>
function goBack() {
console.log("goBack function called");
window.history.back();
}
$(document).ready(function () {
$("form").on("submit", function (event) {
event.preventDefault();
var formData = $(this).serialize();
var empresaId = $('#empresa').val();
formData += '&sucursal=' + encodeURIComponent(empresaId);
$.ajax({
url: '/sucursal/update',
type: 'post',
data: formData,
success: function (message) {
if(message === "Los datos del sucursal fue renovados con exito") {
alert("Los datos del sucursal fue renovada con exito")
window.history.go(-1); // Go back two pages
}else{
alert("Error, consulata a los informaticos")
window.history.go(-1)
}
},
error: function (jqXHR) {
alert(jqXHR.responseText);
window.history.back();
}
});
});
});
</script>
</body>
</html>

@ -6,7 +6,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <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>Lista: Sectore</title> <title>Lista: Contactos</title>
<style> <style>
</style> </style>
@ -14,7 +14,7 @@
<body> <body>
<div class="header"> <div class="header">
<button onclick="goBack()">Atras</button> <button onclick="goBack()">Atras</button>
<h1>Listado de Sectores</h1> <h1>Listado de Contactos</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>
@ -46,7 +46,7 @@
</a> </a>
</th> </th>
<th class="table-header"> <th class="table-header">
<a th:href="@{'/buscador/contactos/page/' + ${currentPage} + '?sortField=correo2&sortDir=' + ${reverseSortDir}}"> <a th:href="@{'/buscador/contactos/page/' + ${currentPage} + '?sortField=correo&sortDir=' + ${reverseSortDir}}">
Correo Correo
</a> </a>
</th> </th>
@ -57,7 +57,7 @@
</th> </th>
<th class="table-header"> <th class="table-header">
<a th:href="@{'/buscador/contactos/page/' + ${currentPage} + '?sortField=empresa.nombre&sortDir=' + ${reverseSortDir}}"> <a th:href="@{'/buscador/contactos/page/' + ${currentPage} + '?sortField=empresa.nombre&sortDir=' + ${reverseSortDir}}">
Sector Empresa
</a> </a>
</th> </th>
</tr> </tr>
@ -83,23 +83,23 @@
<nav aria-label="Page navigation" id="paginationControls"> <nav aria-label="Page navigation" id="paginationControls">
<ul class="pagination"> <ul class="pagination">
<li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}"> <li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Prim</a> <a class="page-link" th:href="@{'/buscador/contactos/page/' + ${1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Prim</a>
</li> </li>
<li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}"> <li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${currentPage - 1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Ant</a> <a class="page-link" th:href="@{'/buscador/contactos/page/' + ${currentPage - 1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Ant</a>
</li> </li>
<li class="page-item" th:each="pageNum : ${#numbers.sequence(1, totalPages)}" th:classappend="${pageNum eq currentPage ? 'active' : ''}"> <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}"> <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} + '&size=' + ${currentSize}}">[[${pageNum}]]</a> <a class="page-link" th:href="@{'/buscador/contactos/page/' + ${pageNum} + '?query=' + ${query} + '&size=' + ${currentSize}}">[[${pageNum}]]</a>
</th:block> </th:block>
<th:block th:if="${pageNum eq 3 and currentPage gt 5}">...</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> <th:block th:if="${pageNum eq totalPages - 2 and currentPage lt totalPages - 4}">...</th:block>
</li> </li>
<li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}"> <li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${currentPage + 1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Sig</a> <a class="page-link" th:href="@{'/buscador/contactos/page/' + ${currentPage + 1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Sig</a>
</li> </li>
<li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}"> <li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${totalPages} + '?query=' + ${query} + '&size=' + ${currentSize}}">Ult</a> <a class="page-link" th:href="@{'/buscador/contactos/page/' + ${totalPages} + '?query=' + ${query} + '&size=' + ${currentSize}}">Ult</a>
</li> </li>
</ul> </ul>
</nav> </nav>
@ -130,14 +130,12 @@
var entriesCountDropdown = document.querySelector('#entriesCount'); var entriesCountDropdown = document.querySelector('#entriesCount');
if (query == '') { if (query == '') {
// If the search bar is empty, show the pagination controls and the entries count dropdown, and reload the page
paginationControls.style.display = ''; paginationControls.style.display = '';
entriesCountDropdown.style.display = ''; entriesCountDropdown.style.display = '';
table.style.pointerEvents = ''; table.style.pointerEvents = '';
location.reload(); location.reload();
} else { } 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'; paginationControls.style.display = 'none';
entriesCountDropdown.style.display = 'none'; entriesCountDropdown.style.display = 'none';
table.style.pointerEvents = 'none'; table.style.pointerEvents = 'none';
@ -156,18 +154,18 @@
<i id="edit-icon" class="fas fa-pen-square"></i> <i id="edit-icon" class="fas fa-pen-square"></i>
<i id="delete-icon" class="fas fa-ban"></i> <i id="delete-icon" class="fas fa-ban"></i>
</td> </td>
<td>[[${contacto.apellido}]]</td> <td>${contacto.apellido}</td>
<td>[[${contacto.apellido2}]]</td> <td>${contacto.apellido2}</td>
<td>[[${contacto.correo}]]</td> <td>${contacto.correo}</td>
<td>[[${contacto.telefono}]]</td> <td>${contacto.telefono}</td>
<td>[[${contacto.empresa.nombre}]]</td> <td>${contacto.empresa.nombre}</td>
`; `;
tableBody.appendChild(row); tableBody.appendChild(row);
}); });
}); });
} }
}); });
<!--
document.getElementById('create-icon').addEventListener('click', function() { document.getElementById('create-icon').addEventListener('click', function() {
window.location = "/admin/contacto/create"; window.location = "/admin/contacto/create";
}); });
@ -196,11 +194,11 @@
url: '/contacto/delete/' + rowId, url: '/contacto/delete/' + rowId,
type: 'GET', type: 'GET',
success: function(response) { success: function(response) {
if (response==="La empresa ha sido eliminado") { if (response==="El contacto ha sido eliminado") {
alert("Empresa borrada con exito"); alert("Contacto borrada con exito");
window.location.reload(); window.location.reload();
}else{ }else{
alert("Error al borrar la empresa"); alert("Error al borrar el contacto");
} }
} }
}); });
@ -212,7 +210,7 @@
} }
} }
} }
});--> });
</script> </script>
</body> </body>

@ -3,35 +3,68 @@
<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">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css">
<script type="text/javascript" src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Title</title> <title>Lista Sucursales</title>
<style> <style>
</style> </style>
</head> </head>
<body> <body>
<h1>Listado de Sucursales<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1> <div class="header">
<div class="table"> <button onclick="goBack()">Atras</button>
<table class ="table table-hover table-responsive-xl"> <h1>Listado de Sucursales</h1>
<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a>
</div>
<input type="text" id="myInput" placeholder="Buscar por...."> <i class="fas fa-plus" id="create-icon"></i>
<div class="table-container">
<table class="table" id="table">
<thead class="thread-light"> <thead class="thread-light">
<tr> <tr>
<th>Id</th> <th class="table-header">
<th>Nombre</th> <a th:href="@{'/buscador/sucursales/page/' + ${currentPage} + '?sortField=id&sortDir=' + ${reverseSortDir}}">
<th>Localidad</th> Id
<th>Dirección</th> </a>
<th>SedeCentral</th> </th>
<th>Empressa</th> <th class="table-header">
<a th:href="@{'/buscador/sucursales/page/' + ${currentPage} + '?sortField=nombre&sortDir=' + ${reverseSortDir}}">
Nombre
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/sucursales/page/' + ${currentPage} + '?sortField=localidad&sortDir=' + ${reverseSortDir}}">
Localidad
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/sucursales/page/' + ${currentPage} + '?sortField=direccion&sortDir=' + ${reverseSortDir}}">
Direccion
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/sucursales/page/' + ${currentPage} + '?sortField=sedeCentral&sortDir=' + ${reverseSortDir}}">
Sede Central
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/sucursales/page/' + ${currentPage} + '?sortField=empresa.nombre&sortDir=' + ${reverseSortDir}}">
Empresa
</a>
</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr class="cell" th:each="sucursal :${sucursales}"> <tr class="cell" th:each="sucursal :${sucursales}">
<td>[[${sucursal.id}]]</td> <td>[[${sucursal.id}]]</td>
<td>[[${sucursal.nombre}]]</td> <td>
[[${sucursal.nombre}]]
<i id="edit-icon" class="fas fa-pen-square"></i>
<i id="delete-icon" class="fas fa-ban"></i>
</td>
<td>[[${sucursal.localidad}]]</td> <td>[[${sucursal.localidad}]]</td>
<td>[[${sucursal.direccion}]]</td> <td>[[${sucursal.direccion}]]</td>
<td>[[${sucursal.sedeCentral}]]</td> <td>[[${sucursal.sedeCentral}]]</td>
@ -40,12 +73,143 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<button onclick="goBack()">Atras</button> <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/sucursales/page/' + ${1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Prim</a>
</li>
<li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/sucursales/page/' + ${currentPage - 1} + '?query=' + ${query} + '&size=' + ${currentSize}}">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/sucursales/page/' + ${pageNum} + '?query=' + ${query} + '&size=' + ${currentSize}}">[[${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/sucursales/page/' + ${currentPage + 1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Sig</a>
</li>
<li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/sucursales/page/' + ${totalPages} + '?query=' + ${query} + '&size=' + ${currentSize}}">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>
<div id="modalDelete" class ="modal">
<div class="modal-content">
<p>¿Estas seguro que quires borar este elemnto?</p>
<span class="delete">Borar</span>
<span class="close">Cancelar</span>
</div>
</div>
<script src="/orderTable.js"></script>
<script> <script>
function goBack() { function goBack() {
window.history.back(); window.history.back();
} }
document.querySelector('#myInput').addEventListener('input', function() {
var query = document.querySelector('#myInput').value;
var paginationControls = document.querySelector('#paginationControls');
var entriesCountDropdown = document.querySelector('#entriesCount');
if (query == '') {
paginationControls.style.display = '';
entriesCountDropdown.style.display = '';
table.style.pointerEvents = '';
location.reload();
} else {
paginationControls.style.display = 'none';
entriesCountDropdown.style.display = 'none';
table.style.pointerEvents = 'none';
fetch('/buscador/sucursales/search?query=' + query)
.then(response => response.json())
.then(data => {
var tableBody = document.querySelector('#table tbody');
tableBody.innerHTML = '';
data.forEach(sucursal => {
var row = document.createElement('tr');
row.innerHTML = `
<td>${sucursal.id}</td>
<td>
${sucursal.nombre}
<i id="edit-icon" class="fas fa-pen-square"></i>
<i id="delete-icon" class="fas fa-ban"></i>
</td>
<td>${sucursal.localidad}</td>
<td>${sucursal.direccion}</td>
<td>${sucursal.sedeCentral}</td>
<td>${sucursal.empresa.nombre}</td>
`;
tableBody.appendChild(row);
});
});
}
});
document.getElementById('create-icon').addEventListener('click', function() {
window.location = "/admin/sucursal/create";
});
document.querySelector('#table').addEventListener('click', function(event) {
if (event.target.matches('#edit-icon')) {
const rowId = event.target.closest('tr').firstElementChild.textContent;
window.location = "/admin/sucursal/update/" + rowId;
} else if (event.target.matches('#delete-icon')) {
const rowId = event.target.closest('tr').firstElementChild.textContent;
var modal = document.getElementById("modalDelete");
var closeSpan = document.getElementsByClassName("close")[0];
var deleteSpan = document.getElementsByClassName("delete")[0];
modal.style.display = "block";
document.body.style.pointerEvents = 'none';
modal.style.pointerEvents = 'auto';
closeSpan.onclick = function() {
modal.style.display = "none";
document.body.style.pointerEvents = 'auto';
}
deleteSpan.onclick = function() {
// Your code here
<!--console.log("Delete button clicked for row with ID: ", rowId)-->
$.ajax({
url: '/sucursal/delete/' + rowId,
type: 'GET',
success: function(response) {
if (response==="La empresa ha sido eliminado") {
alert("Empresa borrada con exito");
window.location.reload();
}else{
alert("Error al borrar la empresa");
}
}
});
}
window.onclick = function(event) {
if (event.target === modal) {
modal.style.display = "none";
document.body.style.pointerEvents = 'auto';
}
}
}
});
</script> </script>
</body> </body>
</html> </html>
Loading…
Cancel
Save

Powered by INFORMATICA.FP.EDU.ES.