Commit 1b08dcc3 by willgonzz

Paginacion de las listas de tecnologias y cargos

parent 78c12fed
package com.roshka.controller; package com.roshka.controller;
import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import com.roshka.modelo.Cargo; import com.roshka.modelo.Cargo;
import com.roshka.repositorio.CargoRepository; import com.roshka.repositorio.CargoRepository;
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.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
...@@ -27,10 +33,13 @@ public class CargoController { ...@@ -27,10 +33,13 @@ public class CargoController {
} }
@RequestMapping("/cargos") @RequestMapping("/cargos")
public String menuCargos(Model model, public String menuCargos(Model model,@RequestParam(required = false) String nombre,@RequestParam(defaultValue = "0")Integer nroPagina) {
@RequestParam(required = false) String nombre final Integer CANTIDAD_POR_PAGINA = 1;
) { Pageable page = PageRequest.of(nroPagina,CANTIDAD_POR_PAGINA,Sort.by("id"));
if(nombre == null || nombre.trim().isEmpty()) model.addAttribute("cargos", cargoRepo.findAll()); Page<Cargo> CargoPag=cargoRepo.findAllCargo(page);
List<Cargo> cargo = CargoPag.getContent();
model.addAttribute("pages", CargoPag.getTotalPages());
if(nombre == null || nombre.trim().isEmpty()) model.addAttribute("cargos", cargo);
else model.addAttribute("cargos", cargoRepo.findByNombreContainingIgnoreCase(nombre)); else model.addAttribute("cargos", cargoRepo.findByNombreContainingIgnoreCase(nombre));
return "cargos"; return "cargos";
} }
......
package com.roshka.controller; package com.roshka.controller;
import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import com.roshka.modelo.Tecnologia; import com.roshka.modelo.Tecnologia;
...@@ -15,6 +17,10 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -15,6 +17,10 @@ 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.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@Controller @Controller
public class TecnologiaController { public class TecnologiaController {
...@@ -38,10 +44,13 @@ public String addtecnologiaView(Model model,@PathVariable(required = false) Long ...@@ -38,10 +44,13 @@ public String addtecnologiaView(Model model,@PathVariable(required = false) Long
} }
@RequestMapping("/tecnologias") @RequestMapping("/tecnologias")
public String menuTecnologias(Model model, public String menuTecnologias(Model model,@RequestParam(required = false) String nombre,@RequestParam(defaultValue = "0")Integer nroPagina) {
@RequestParam(required = false) String nombre final Integer CANTIDAD_POR_PAGINA = 5;
) { Pageable page = PageRequest.of(nroPagina,CANTIDAD_POR_PAGINA,Sort.by("id"));
if(nombre == null || nombre.trim().isEmpty()) model.addAttribute("tecnologias", tecRepo.findAll()); Page<Tecnologia> tecnologiaPag=tecRepo.findAllTecnologia(page);
List<Tecnologia> tecnologia = tecnologiaPag.getContent();
model.addAttribute("pages", tecnologiaPag.getTotalPages());
if(nombre == null || nombre.trim().isEmpty()) model.addAttribute("tecnologias", tecnologia);
else model.addAttribute("tecnologias", tecRepo.findByNombreContainingIgnoreCase(nombre)); else model.addAttribute("tecnologias", tecRepo.findByNombreContainingIgnoreCase(nombre));
return "tecnologias"; return "tecnologias";
} }
......
...@@ -4,9 +4,16 @@ import java.util.List; ...@@ -4,9 +4,16 @@ import java.util.List;
import com.roshka.modelo.Cargo; import com.roshka.modelo.Cargo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface CargoRepository extends JpaRepository<Cargo,Long>{ public interface CargoRepository extends JpaRepository<Cargo,Long>{
public List<Cargo> findByNombreContainingIgnoreCase(String nombre); public List<Cargo> findByNombreContainingIgnoreCase(String nombre);
public boolean existsByNombreIgnoreCase(String nombre); public boolean existsByNombreIgnoreCase(String nombre);
@Query(value = "SELECT * FROM cargo",nativeQuery = true)
public Page<Cargo> findAllCargo(Pageable pageable );
} }
package com.roshka.repositorio; package com.roshka.repositorio;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List; import java.util.List;
...@@ -11,4 +14,8 @@ public interface TecnologiaRepository extends JpaRepository<Tecnologia,Long> { ...@@ -11,4 +14,8 @@ public interface TecnologiaRepository extends JpaRepository<Tecnologia,Long> {
public List<Tecnologia> findByNombreContainingIgnoreCase(String nombre); public List<Tecnologia> findByNombreContainingIgnoreCase(String nombre);
public boolean existsByNombreIgnoreCase(String nombre); public boolean existsByNombreIgnoreCase(String nombre);
@Query(value = "SELECT * FROM tecnologia",nativeQuery = true)
public Page<Tecnologia> findAllTecnologia(Pageable pageable );
} }
...@@ -3,6 +3,6 @@ body{ ...@@ -3,6 +3,6 @@ body{
background-size:cover; background-size:cover;
background-repeat:no-repeat; background-repeat:no-repeat;
height:100vh;width:100vw; height:100vh;width:100vw;
position: absolute;
-webkit-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;
} }
\ No newline at end of file
...@@ -45,8 +45,31 @@ contentType="text/html;charset=UTF-8" language="java" %> ...@@ -45,8 +45,31 @@ contentType="text/html;charset=UTF-8" language="java" %>
</table> </table>
</div> </div>
</div> </div>
<div class="card-footer">
<div>
<nav aria-label="Page navigation example">
<ul class="pagination">
<c:forEach begin="1" end="${pages}" var="nro">
<li class="page-item ${(param.nroPagina == null and nro == 1) or param.nroPagina == nro-1 ? 'active' : ''}"><a class="page-link" href="javascript:buscarPagina(${nro})">${nro}</a></li>
</c:forEach>
</ul>
</nav>
</div>
</div>
</div>
</layout:put> </layout:put>
<layout:put block="scripts" type="APPEND"> <layout:put block="scripts" type="APPEND">
<script>
function buscarPagina(nro){
nro--
const aBuscar = 'nroPagina='+nro
if(!location.search) location.search = "?"+aBuscar
const inicial = location.search.search(aBuscar);
if(inicial==-1){//si no se encuentra y hay otros queries
location.search = "&"+aBuscar
}
location.search.replace('nroPagina=',aBuscar)
}
</script>
</layout:put> </layout:put>
</layout:extends> </layout:extends>
...@@ -149,7 +149,7 @@ ...@@ -149,7 +149,7 @@
<input class="form-control" type="file" id="cvFile"> <input class="form-control" type="file" id="cvFile">
</div> </div>
<!-- Button Agregar Cargo al que postulas --> <!-- Button Agregar Cargo al que postulas -->
<button type="button" class="btn btn-primary"><span class="add-experience" class="btn btn-primary" data-toggle="modal" data-target="#cargoForm"><i class="fa fa-plus"></i>&nbsp;Agregar Cargo al que postulas</span></button><br> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#cargoForm"><span class="add-experience"><i class="fa fa-plus"></i>&nbsp;Agregar Cargo al que postulas</span></button><br>
<p id="no-valid-cargo" style="display: none; color: darkred; border: solid 1px darkred; border-radius: 25px; width: 75%" class="m-3"> <p id="no-valid-cargo" style="display: none; color: darkred; border: solid 1px darkred; border-radius: 25px; width: 75%" class="m-3">
*Agrega por lo menos un cargo *Agrega por lo menos un cargo
</p> </p>
......
...@@ -39,5 +39,33 @@ ...@@ -39,5 +39,33 @@
</tbody> </tbody>
</table> </table>
</div> </div>
</layout:put> <div class="card-footer">
<div>
<nav aria-label="Page navigation example">
<ul class="pagination">
<c:forEach begin="1" end="${pages}" var="nro">
<li class="page-item ${(param.nroPagina == null and nro == 1) or param.nroPagina == nro-1 ? 'active' : ''}"><a class="page-link" href="javascript:buscarPagina(${nro})">${nro}</a></li>
</c:forEach>
</ul>
</nav>
</div>
</div>
</div>
</layout:put>
<layout:put block="scripts" type="APPEND">
<script>
function buscarPagina(nro){
nro--
const aBuscar = 'nroPagina='+nro
if(!location.search) location.search = "?"+aBuscar
const inicial = location.search.search(aBuscar);
if(inicial==-1){//si no se encuentra y hay otros queries
location.search = "&"+aBuscar
}
location.search.replace('nroPagina=',aBuscar)
}
</script>
</layout:put>
</layout:extends> </layout:extends>
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