Commit 139b7976 by Joel Florentin

merge validar al menos una tecnologia o cargo en form postulante

parents eeac29e9 89dbfaec
File mode changed from 100644 to 100755
......@@ -3,10 +3,13 @@ package com.roshka.controller;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.roshka.modelo.Cargo;
import com.roshka.modelo.ConvocatoriaCargo;
import com.roshka.repositorio.CargoRepository;
import com.roshka.repositorio.ConvocatoriaRepository;
import org.apache.jasper.tagplugins.jstl.core.ForEach;
import org.dom4j.Branch;
import org.hibernate.jpa.TypedParameterValue;
import org.hibernate.type.IntegerType;
import org.hibernate.type.LongType;
......@@ -49,24 +52,48 @@ public class ConvocatoriaController {
@RequestMapping(path = {"/convocatoria","/convocatoria/{id}"})
public String formConvocatoria(Model model,@PathVariable(required = false) Long id) {
model.addAttribute("cargos", cargoRepo.findAll());
if(id == null) model.addAttribute("convocatoria", new ConvocatoriaCargo());
if(id == null){
model.addAttribute("convocatoria", new ConvocatoriaCargo());
model.addAttribute("listaConvocatoria", convoRepo.findAll());
}
else {
ConvocatoriaCargo cc = convoRepo.getById(id);
cc.setFechaFinS(new SimpleDateFormat("yyyy-MM-dd").format((cc.getFechaFin())));
cc.setFechaInicioS(new SimpleDateFormat("yyyy-MM-dd").format((cc.getFechaInicio())));
model.addAttribute("convocatoria", cc);
model.addAttribute("listaConvocatoria", convoRepo.findAll());
}
return "convocatoria-form";
}
@PostMapping(path = {"/convocatoria","/convocatoria/{id}"})
public String guardarConvocatoria(@ModelAttribute ConvocatoriaCargo convocatoria, BindingResult result, @PathVariable(required = false) Long id) {
public String guardarConvocatoria(@ModelAttribute ConvocatoriaCargo convocatoria, BindingResult result, @PathVariable(required = false) Long id,Model model) {
if(result.hasErrors());
if(id != null) convocatoria.setId(id);
convoRepo.save(convocatoria);
System.out.println(convocatoria.getFechaInicio());
//System.out.println(convoRepo.filtrarConvocatoriasPorCargo(convocatoria.getCargoId()));
for(ConvocatoriaCargo c: convoRepo.filtrarConvocatoriasPorCargo(convocatoria.getCargoId())){
if(result.hasErrors() || c.getCargoId()==convocatoria.getCargoId() && c.getFechaFin().after(convocatoria.getFechaInicio()) )
{
model.addAttribute("existeFecha", true);
System.out.println("no debe");
return "convocatoria-form";
}
else{
convoRepo.save(convocatoria);
System.out.println("si anda");
break;
}
}
return "redirect:/convocatorias";
}
}
......@@ -37,6 +37,9 @@ import org.springframework.util.StringUtils;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.view.RedirectView;
@Controller
public class PostulanteController {
......@@ -124,8 +127,10 @@ public class PostulanteController {
}
@PostMapping(value = "/work-with-us",consumes = "multipart/form-data")
public String guardarPostulante(@RequestPart(name = "file",required = false) MultipartFile file,@RequestPart("postulante") Postulante postulante){
public RedirectView guardarPostulante(@RequestPart(name = "file",required = false) MultipartFile file,@RequestPart("postulante") Postulante postulante, RedirectAttributes redirectAttributes){
//Codigo encargado de modificar postulacion si se envia mismo CI
//Codigo encargado de modificar postulacion si se envia mismo CI
RedirectView redirectView = new RedirectView("/work-with-us/postulacion-correcta",true);
Postulante postulantex = post.findByNroDocument(postulante.getNroDocument());
if(postulantex != null){
estudioRepository.findByPostulante(postulantex).forEach(x -> estudioRepository.delete(x));
......@@ -138,11 +143,8 @@ public class PostulanteController {
if(cv!=null) cv.setPostulante(postulante);
postulante.setCvFile(cv);
}
postulante.getTecnologias().stream().filter(
tec -> tec.getTecnologia().getId() != 0
).forEach(
tec -> tec.setTecnologia(tecRepo.getById(tec.getTecnologia().getId()))
);
postulante.getTecnologias().stream().filter(tec -> tec.getTecnologia().getId() != 0)
.forEach(tec -> tec.setTecnologia(tecRepo.getById(tec.getTecnologia().getId())));
for(Estudio estudio: postulante.getEstudios()){
String nombreIns = "";
......@@ -154,8 +156,13 @@ public class PostulanteController {
estudio.setInstitucion(institucion);
}
}
if(postulante.getPostulaciones().isEmpty() || postulante.getTecnologias().isEmpty()){
redirectView.setUrl("/postulante");
redirectAttributes.addFlashAttribute("error", "Datos invalidos");
return redirectView;
}
post.save(postulante);
return "redirect:/work-with-us/postulacion-correcta";
return redirectView;
}
......
......@@ -67,17 +67,21 @@ public class RRHHUserController {
}
@PostMapping("/process_register")
public String processRegister(HttpServletRequest request, RRHHUser user) {
public RedirectView processRegister(HttpServletRequest request, RRHHUser user, RedirectAttributes redirectAttributes) {
RedirectView redirectView = new RedirectView("/register",true);
redirectAttributes.addFlashAttribute("success", "Datos actualizados");
if(Long.parseLong(request.getParameter("registrationCode")) != REGISTER_CODE){
return "redirect:/register";
redirectAttributes.addFlashAttribute("error", "Codigo Incorrecto");
return redirectView;
}
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String encodedPassword = passwordEncoder.encode(user.getPassword());
user.setPassword(encodedPassword);
rrhhUserRepository.save(user);
return "register_success";
redirectView.setUrl("/login");
redirectAttributes.addFlashAttribute("success", "Registro Correcto");
return redirectView;
}
@GetMapping("/edit-user-data")
......
......@@ -15,4 +15,7 @@ public interface ConvocatoriaRepository extends JpaRepository<ConvocatoriaCargo,
//public List<ConvocatoriaCargo> findConvocatoriaCargoByCargo(Date fechaFinal);
@Query("select c from ConvocatoriaCargo c where ( ?1 is null and ?3 is null) or ( ( ( (c.fechaFin > ?2 and ?3 = 1) or (c.fechaFin < ?2 and ?3 = 0)) or ?3 is null ) and (c.cargoId = ?1 or ?1 is null) )")
public List<ConvocatoriaCargo> f1ndByCargoAndEstado(TypedParameterValue cargoId, Date fecha, TypedParameterValue isOpen);
@Query("SELECT c FROM ConvocatoriaCargo c WHERE (cargoId=?1)")
public List<ConvocatoriaCargo> filtrarConvocatoriasPorCargo(Long cargoId);
}
......@@ -80,4 +80,8 @@ public interface PostulanteRepository extends JpaRepository<Postulante,Long> {
@Query("UPDATE Postulante p SET p.comentarioRRHH = ?1 WHERE p.id = ?2")
void setPostulanteEstadoComentario( String comentario, Long Id);*/
@Query("SELECT p FROM Postulante p JOIN Estudio e ON p.id=e.postulante.id "+
"where e.temaDeEstudio=?1")
public List<Postulante> obtenerPostulantesPorCarrera(String carrera);
}
......@@ -97,7 +97,7 @@ function agregarFieldExpierncia(event){
content += `
<li id="exp-${index}">
${exp.institucion}
<button type="button" onclick="eliminarExperiencia(event)"> <span class="glyphicon glyphicon-trash"></span> Eliminar</button>
<button type="button" class="btn btn-primary" onclick="eliminarExperiencia(event)"> <span class="glyphicon glyphicon-trash"></span> Eliminar</button>
</li>
`
......@@ -159,7 +159,7 @@ function agregarFieldTecnologia(){
content1 += `
<li id="tecn-${index}">
${tecn.tecnologia.nombre}
<button type="button" onclick="eliminarTecnologia(event)">Eliminar</button>
<button type="button" class="btn btn-primary" onclick="eliminarTecnologia(event)">Eliminar</button>
<br>
</li>
......@@ -192,7 +192,6 @@ function serializeJSON (form) {
// Create a new FormData object
const formData = new FormData(form);
// Create an object to hold the name/value pairs
const pairs = {};
......@@ -205,7 +204,23 @@ function serializeJSON (form) {
pairs["tecnologias"] = tecnologias.filter(tec => tec)//eliminacion de nulos
pairs["postulaciones"] = postulaciones.filter(car => car)//eliminacion de nulos
pairs["referencias"] = referencias.filter(tec => tec)
if(pairs["postulaciones"].length<1){
document.querySelector("#no-valid-cargo").style.display = "block";
noValidateFlag = true;
}else{
document.querySelector("#no-valid-cargo").style.display = "none";
}
console.log(pairs["tecnologias"])
if(pairs["tecnologias"].length<1){
document.querySelector("#no-valid-tecno").style.display = "block";
noValidateFlag = true;
}else{
document.querySelector("#no-valid-tecno").style.display = "none";
}
if(noValidateFlag){
return;
}
noValidateFlag = false
// Return the JSON string
return JSON.stringify(pairs, null, 2);
......@@ -235,7 +250,10 @@ async function postData(url = '', data = {}) {
body: data // body data type must match "Content-Type" header
}
senddata["headers"][headerxs] = token;
const response = await fetch(url, senddata);
let response = null
if(!noValidateFlag){
response = await fetch(url, senddata);
}
return response; // parses JSON response into native JavaScript objects
}
......@@ -270,7 +288,6 @@ form.addEventListener("submit",(evt)=>{
noValidateFlag = false
} );
document.querySelector("#btn-new-tech").addEventListener('click',()=>{document.querySelector("#tecnologia-nombre").classList.remove('d-none')})
//Metodos para Estudios
......@@ -339,7 +356,7 @@ function agregarFieldEstudio(){
content += `
<li id="est-${index}">
${est.institucion.nombre}
<button type="button" onclick="eliminarEstudio(event)">Eliminar</button>
<button type="button" class="btn btn-primary" onclick="eliminarEstudio(event)">Eliminar</button>
</li>
`
......@@ -400,7 +417,7 @@ function agregarFieldCargo(){
if(postulaciones[i]!==null){
if(postulaciones[i]["id"]===pairs["cargo-id"]){
alert("Ya has agregado ese cargo!")
cont_cargo--;
//cont_cargo--;
return;
}
}
......@@ -420,8 +437,8 @@ function agregarFieldCargo(){
if(car==null) continue;
content1 += `
<li id="car-${index}">
${document.querySelector('[name=cargo-id] > option[value="'+car.id+'"]').innerHTML}
<button type="button" onclick="eliminarCargoPostulante(event)">Eliminar</button>
${document.querySelector('[name=cargo-id] > option[value="'+car.id+'"]').innerHTML}<br>
<button type="button" class="btn btn-primary" onclick="eliminarCargoPostulante(event)">Eliminar</button>
</li>
`
......@@ -522,7 +539,7 @@ function agregarFieldReferencia(event){
content += `
<li id="exp-${index}">
${exp.nombre}
<button type="button" onclick="eliminarReferencia(event)"> <span class="glyphicon glyphicon-trash"></span> Tras</button>
<button type="button" class="btn btn-primary" onclick="eliminarReferencia(event)"> <span class="glyphicon glyphicon-trash"></span> Tras</button>
</li>
`
......@@ -546,57 +563,57 @@ function eliminarReferencia(event) {
/*--------------------------------------------------------------------------------------------------------- */
$(function(){
$("#wizard").steps({
headerTag: "h4",
bodyTag: "section",
transitionEffect: "fade",
enableAllSteps: true,
transitionEffectSpeed: 500,
onStepChanging: function (event, currentIndex, newIndex) {
if ( newIndex === 1 ) {
$('.steps ul').addClass('step-2');
} else {
$('.steps ul').removeClass('step-2');
}
if ( newIndex === 2 ) {
$('.steps ul').addClass('step-3');
} else {
$('.steps ul').removeClass('step-3');
}
if ( newIndex === 3 ) {
$('.steps ul').addClass('step-4');
$('.actions ul').addClass('step-last');
} else {
$('.steps ul').removeClass('step-4');
$('.actions ul').removeClass('step-last');
}
return true;
},
labels: {
finish: "Order again",
next: "Next",
previous: "Previous"
}
});
// Custom Steps Jquery Steps
$('.wizard > .steps li a').click(function(){
$(this).parent().addClass('checked');
$(this).parent().prevAll().addClass('checked');
$(this).parent().nextAll().removeClass('checked');
});
// Custom Button Jquery Steps
$('.forward').click(function(){
$("#wizard").steps('next');
})
$('.backward').click(function(){
$("#wizard").steps('previous');
})
// Checkbox
$('.checkbox-circle label').click(function(){
$('.checkbox-circle label').removeClass('active');
$(this).addClass('active');
})
})
// $(function(){
// $("#wizard").steps({
// headerTag: "h4",
// bodyTag: "section",
// transitionEffect: "fade",
// enableAllSteps: true,
// transitionEffectSpeed: 500,
// onStepChanging: function (event, currentIndex, newIndex) {
// if ( newIndex === 1 ) {
// $('.steps ul').addClass('step-2');
// } else {
// $('.steps ul').removeClass('step-2');
// }
// if ( newIndex === 2 ) {
// $('.steps ul').addClass('step-3');
// } else {
// $('.steps ul').removeClass('step-3');
// }
//
// if ( newIndex === 3 ) {
// $('.steps ul').addClass('step-4');
// $('.actions ul').addClass('step-last');
// } else {
// $('.steps ul').removeClass('step-4');
// $('.actions ul').removeClass('step-last');
// }
// return true;
// },
// labels: {
// finish: "Order again",
// next: "Next",
// previous: "Previous"
// }
// });
// // Custom Steps Jquery Steps
// $('.wizard > .steps li a').click(function(){
// $(this).parent().addClass('checked');
// $(this).parent().prevAll().addClass('checked');
// $(this).parent().nextAll().removeClass('checked');
// });
// // Custom Button Jquery Steps
// $('.forward').click(function(){
// $("#wizard").steps('next');
// })
// $('.backward').click(function(){
// $("#wizard").steps('previous');
// })
// // Checkbox
// $('.checkbox-circle label').click(function(){
// $('.checkbox-circle label').removeClass('active');
// $(this).addClass('active');
// })
// })
/*--------------------------------------------------------------------------------------------------------- */
\ No newline at end of file
......@@ -9,13 +9,19 @@
<div class="p-3 mb-2 bg-light text-dark border border-light ">
<form:form action="/convocatoria/${convocatoria.id == null ? '' : convocatoria.id}" method="post" modelAttribute="convocatoria">
<div class="mb-3 col-3">
<form:label path="fechaInicioS" class="form-label">Fecha inicial</form:label>
<form:input type="date" class="form-control" path="fechaInicioS" required="true"/>
<form:label path="fechaInicioS" class="form-label ">Fecha inicial</form:label>
<form:input type="date" path="fechaInicioS" required="true" class="form-control ${ existeFecha ? 'is-invalid' : ''}" placeholder="Fecha requerida" requiered="true" />
<div id="validationServerUsernameFeedback1" class="invalid-feedback">
Esta fecha ya existe
</div>
</div>
<div class="mb-3 col-3">
<form:label path="fechaFinS" class="form-label">Fecha Fin</form:label>
<form:input type="date" class="form-control" path="fechaFinS" required="true"/>
<form:input type="date" path="fechaFinS" required="true" class="form-control ${existeFecha ? 'is-invalid': '' }" placeholder="Fecha requerida" requiered="true" />
<div id="validationServerUsernameFeedback2" class="invalid-feedback">
Esta fecha ya existe
</div>
</div>
<div class="mb-3 col-3">
<form:label path="cupos" class="form-label">Cupos:</form:label>
......@@ -23,7 +29,7 @@
</div>
<div class="mb-3 col-3">
<form:label path="cargoId" class="form-label">Cargo</form:label>
<form:select class="form-select" path="cargoId" required="true">
<form:select class="form-select" path="cargoId">
<c:forEach items="${cargos}" var="cargo">
<form:option value="${cargo.id}">${cargo.nombre} </form:option>
</c:forEach>
......
......@@ -53,6 +53,7 @@
</div>
<button type="submit" class="btn btn-success btn-lg mb-1">Submit</button>
<a href="/home" class="btn btn-danger btn-lg mr-3 ml-3 mb-1">Volver</a>
</form:form>
</div>
......
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<header>
......@@ -49,11 +52,31 @@
<a class="nav-link" href="/edit-user-data">Editar mis datos</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/logout">Salir</a>
<%-- <a class="nav-link" href="/logout">Salir</a>--%>
<button type="button" class="btn btn-light" data-toggle="modal" data-target="#exampleModal">
Salir
</button>
</li>
</ul>
</div>
</div>
</nav>
</header>
\ No newline at end of file
</header>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title" id="exampleModalLabel">Esta seguro que desea salir?</h6>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<a href="/logout" class="btn btn-danger">Salir</a>
</div>
</div>
</div>
</div>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Registration Success</title>
<link rel="stylesheet" type="text/css" href="/webjars/bootstrap/css/bootstrap.min.css" />
</head>
<body>
<div class="container text-center">
<h3>You have signed up successfully!</h3>
<h4><a href="${pageContext.request.contextPath}/login">Click here to Login</a></h4>
</div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment