Commit d4e647f7 by willgonzz

Postulantes convocatoria

parent ee6c61fc
package com.roshka.controller;
import java.util.Date;
import java.util.List;
import javax.validation.ConstraintViolationException;
......@@ -13,13 +14,18 @@ import com.roshka.modelo.EstadoCivil;
import com.roshka.modelo.Nacionalidad;
import com.roshka.modelo.Postulante;
import com.roshka.modelo.TipoExperiencia;
import com.roshka.repositorio.CargoRepository;
import com.roshka.repositorio.CiudadRepository;
import com.roshka.repositorio.ConvocatoriaRepository;
import com.roshka.repositorio.DepartamentoRepository;
import com.roshka.repositorio.ExperienciaRepository;
import com.roshka.repositorio.InstitucionRepository;
import com.roshka.repositorio.PostulanteRepository;
import com.roshka.repositorio.TecnologiaRepository;
import org.hibernate.jpa.TypedParameterValue;
import org.hibernate.type.IntegerType;
import org.hibernate.type.LongType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -38,15 +44,19 @@ public class PostulanteController {
InstitucionRepository institucionRepository;
DepartamentoRepository depRepo;
CiudadRepository ciuRepo;
ConvocatoriaRepository cargoRepo;
CargoRepository carRepo;
@Autowired
public PostulanteController(PostulanteRepository post, TecnologiaRepository tecRepo, ExperienciaRepository expRepo, InstitucionRepository institucionRepository, DepartamentoRepository depRepo, CiudadRepository ciuRepo) {
public PostulanteController(PostulanteRepository post, TecnologiaRepository tecRepo, ExperienciaRepository expRepo, InstitucionRepository institucionRepository, DepartamentoRepository depRepo, CiudadRepository ciuRepo,ConvocatoriaRepository cargoRepo, CargoRepository carRepo) {
this.post = post;
this.tecRepo = tecRepo;
this.expRepo = expRepo;
this.institucionRepository = institucionRepository;
this.depRepo = depRepo;
this.ciuRepo = ciuRepo;
this.cargoRepo =cargoRepo;
this.carRepo=carRepo;
}
......@@ -75,11 +85,12 @@ public class PostulanteController {
model.addAttribute("estadosCiviles", EstadoCivil.values());
model.addAttribute("nacionalidades", Nacionalidad.values());
model.addAttribute("tiposExperencia", TipoExperiencia.values());
model.addAttribute("CargosDisponibles", cargoRepo.f1ndByCargoAndEstado(new TypedParameterValue(LongType.INSTANCE, null), new Date(), new TypedParameterValue(IntegerType.INSTANCE, 1)));
try {
model.addAttribute("ciudades", new ObjectMapper().writeValueAsString(ciuRepo.findAll()));
} catch (JsonProcessingException e) {
} catch (JsonProcessingException er) {
// TODO Auto-generated catch block
e.printStackTrace();
er.printStackTrace();
}
model.addAttribute("departamentos", depRepo.findAll());
......@@ -94,6 +105,12 @@ public class PostulanteController {
).forEach(
tec -> tec.setTecnologia(tecRepo.getById(tec.getTecnologia().getId()))
);
for (int i = 0; i < postulante.getPostulaciones().size(); i++) {
postulante.getPostulaciones().set(i, cargoRepo.getById(postulante.getPostulaciones().get(i).getId()));
}
for(Estudio estudio: postulante.getEstudios()){
Institucion institucion = institucionRepository.findByNombre(estudio.getInstitucion().getNombre());
if(institucion==null){
......
......@@ -47,4 +47,7 @@ public class Cargo {
public void setConvocatorias(List<ConvocatoriaCargo> convocatorias) {
this.convocatorias = convocatorias;
}
public static Object values() {
return null;
}
}
......@@ -15,10 +15,13 @@ import javax.persistence.Table;
import javax.persistence.Transient;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.roshka.utils.Helper;
@Entity
@Table(name = "convocatoria_cargo")
@JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class, property="@UUID")
public class ConvocatoriaCargo {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
......
......@@ -3,8 +3,10 @@ package com.roshka.modelo;
import javax.persistence.*;
import javax.validation.constraints.*;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.roshka.utils.Helper;
import java.util.ArrayList;
......@@ -14,6 +16,7 @@ import java.util.List;
@Entity
@Table(name="postulante")
@JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class, property="@UUID")
public class Postulante {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
......@@ -103,7 +106,6 @@ public class Postulante {
joinColumns = @JoinColumn(name="postulante_id", referencedColumnName="id"),
inverseJoinColumns= @JoinColumn(name="convocatoria_cargo_id", referencedColumnName="id")
)
@JsonIgnore
private List<ConvocatoriaCargo> postulaciones;
......
......@@ -34,7 +34,7 @@ public class PostulanteTecnologia {
private Tecnologia tecnologia;
@ManyToOne()
@JoinColumn
@JoinColumn
@JsonBackReference(value = "postulantetecnologia-postulante")
private Postulante postulante;
......
......@@ -11,7 +11,8 @@ import org.springframework.data.jpa.repository.Query;
public interface ConvocatoriaRepository extends JpaRepository<ConvocatoriaCargo,Long> {
public List<ConvocatoriaCargo> findByCargoId(Long cargoId);
//@Query(value="selec x from ConvocatoriaCargo x where (x.fechaFinal > ?1)",nativeQuery = true)
//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);
}
var cont_experiencia = 0;
let cont_estudios = 0;
let cont_tecnologia = 0;
let cont_cargo = 0;
const experiencias = [];
const estudios = [];
const tecnologias = [];
const postulaciones = [];
const formValidator = function () {
'use strict'
......@@ -190,6 +192,7 @@ function serializeJSON (form) {
pairs["experiencias"] = experiencias.filter(exp => exp)//eliminacion de nulos
pairs["estudios"] = estudios.filter(est => est)//eliminacion de nulos
pairs["tecnologias"] = tecnologias.filter(tec => tec)//eliminacion de nulos
pairs["postulaciones"] = postulaciones.filter(car => car)//eliminacion de nulos
// Return the JSON string
return JSON.stringify(pairs, null, 2);
......@@ -319,7 +322,77 @@ function eliminarEstudio(event) {
//eliminar en html
event.target.parentElement.remove()
}
/*--------------------------------------------------------------------*/
function agregarFieldCargo(){
//recoger del form
const pairs = {};
const formcar = document.querySelector("[name=cargo-form]");
const formData = new FormData(formcar);
//Validacion
let returnFlag = false;
let requiredValues = ["nombre"]
formData.forEach((value, key)=>{
if(requiredValues.includes(key)
&& value==="" && returnFlag == false){
console.log(key, value)
returnFlag = true;
}
});
if(returnFlag===true){
let message = "Rellene "
for(let i=0;i<requiredValues.length;i++){
message+=", "+requiredValues[i];
}
message += " como minimo."
alert(message);
return;
}
for (const [name, value] of formData){
pairs[name] = value
}
console.log(pairs)
postulaciones[cont_cargo]={}
postulaciones[cont_cargo]["id"]=pairs["cargo-id"]
//postulaciones[cont_cargo]["cargo"]=pairs["cargo-id"]=="-1"?{nombre: pairs["cargo-nombre"]}:{id: pairs["cargo-id"],nombre:document.querySelector('[name=cargo-id] > option[value="'+pairs["cargo-id"]+'"]').innerHTML}
console.log(postulaciones)
formcar.reset();
//imprimir lista actualizada
const div = document.querySelector("#cargos")
const div1 = document.createElement('div');
console.log(postulaciones[0])
let content1='<ul>'
for (let index = 0; index < postulaciones.length; index++) {
const car = postulaciones[index];
if(car==null) continue;
content1 += `
<li id="car-${index}">
${document.querySelector('[name=cargo-id] > option[value="'+pairs["cargo-id"]+'"]').innerHTML}
<button type="button" onclick="eliminarCargoPostulante(event)">Eliminar</button>
</li>
`
}
content1 += "</ul>"
div1.innerHTML = content1
div.innerHTML = '';
div.appendChild(div1);
cont_cargo++;
}
/*---------------------------------------------------------------------------------------------------*/
function eliminarCargoPostulante(event) {
//eliminar del array
postulaciones[event.target.parentElement.id.split("-")[1]]=null
//eliminar en html
event.target.parentElement.remove()
}
/*--------------------------------------------------------------------*/
//evento para cambio de ciudad segun departamento
......
......@@ -260,7 +260,13 @@
</select> </div>
<div class="inputs p-3 py-5">
<div class=" inputs d-flex justify-content-between align-items-center experience"><span class="border px-3 p-1 add-experience" data-toggle="modal" data-target="#cargoForm"><i class="fa fa-plus"></i>&nbsp;Cargo al que postulas</span></div><br>
</div>
<div class="mt-3 gap-2 d-flex justify-content-between" id="cargos">
</div>
<div class="inputs p-3 py-5">
<div class=" inputs d-flex justify-content-between align-items-center experience"><span class="border px-3 p-1 add-experience" data-toggle="modal" data-target="#experienciaForm"><i class="fa fa-plus"></i>&nbsp;Agregar Experiencia</span></div><br>
</div>
......@@ -296,7 +302,37 @@
</div>
</div>
</form>
<!---------------------------------------Modal de Cargos disponibles---------------------------------------------------------------->
<div class="modal fade" id="cargoForm" tabindex="-2" role="dialog" aria-labelledby="cargoForm" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel" >CargosDisponibles</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form name="cargo-form" class="needs-validation" novalidate>
<label for="cargo-nombre" class="form-label">Cargo</label>
<div class="input-group mb-3">
<select class="form-select" name="cargo-id" aria-label="Default select example" required>
<option value="-1" selected>Open this select menu</option>
<c:forEach items="${CargosDisponibles}" var="convocatoria">
<option value="${convocatoria.getId()}">${convocatoria.getCargo().getNombre()}</option>
</c:forEach>>
</select>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" onclick="agregarFieldCargo()" data-dismiss="modal">Agregar</button>
</div>
</div>
</div>
</div>
<!-------------------------------------------------------------------------------------------------------------------------->
<!--Modal de Experiencia-->
<div class="modal fade" id="experienciaForm" tabindex="-1" role="dialog" aria-labelledby="experienciaForm" aria-hidden="true">
......
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