- Timestamp:
- 10/07/21 20:07:41 (3 years ago)
- Branches:
- master
- Children:
- 0c37625
- Parents:
- 0f4f552
- Location:
- src/main
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/it/finki/charitable/controller/DonationPostController.java
r0f4f552 r276a8b6 4 4 import it.finki.charitable.services.*; 5 5 import it.finki.charitable.util.FileUploadUtil; 6 import org.springframework.data.domain.Page; 6 7 import org.springframework.format.annotation.DateTimeFormat; 7 8 import org.springframework.security.core.context.SecurityContextHolder; … … 122 123 123 124 @RequestMapping("/album") 124 public String album(Model model) { 125 List<DonationPost> postList = donationPostService.findAllByApproved(true); 126 if (postList.size() == 0) { 125 public String album(Model model, 126 @RequestParam int page, 127 @RequestParam String sort, 128 @RequestParam(required = false,defaultValue = "") String order) { 129 Page<DonationPost> postList = donationPostService.findPaginated(page,6, sort, order); 130 if (postList.getSize() == 0) { 127 131 model.addAttribute("noPosts", true); 128 132 return "album"; 129 133 } 134 model.addAttribute("totalPages", postList.getTotalPages()); 130 135 model.addAttribute("postList", postList); 131 136 return "album"; -
src/main/java/it/finki/charitable/repository/DonationPostRepository.java
r0f4f552 r276a8b6 4 4 import it.finki.charitable.entities.DonationPost; 5 5 import it.finki.charitable.entities.Moderator; 6 import org.springframework.data.domain.Page; 7 import org.springframework.data.domain.Pageable; 6 8 import org.springframework.data.jpa.repository.JpaRepository; 7 9 import org.springframework.stereotype.Repository; … … 14 16 List<DonationPost> findAllByApproved(Boolean approved); 15 17 List<DonationPost> findAllByModerator(Moderator moderator); 18 Page<DonationPost> findAllByApproved(Pageable pageable, boolean approved); 16 19 } -
src/main/java/it/finki/charitable/services/DonationPostService.java
r0f4f552 r276a8b6 54 54 } 55 55 56 public Page<DonationPost> findPaginated(int pageNo, int pageSize, String sort) { 57 Pageable pageable = PageRequest.of(pageNo - 1, pageSize, Sort.by(sort)); 58 return donationPostRepository.findAll(pageable); 56 public Page<DonationPost> findPaginated(int pageNo, int pageSize, String sort, String order) { 57 Sort s = Sort.by(sort); 58 s = order.equals("asc") ? s.ascending() : s.descending(); 59 Pageable pageable = PageRequest.of(pageNo - 1, pageSize, s); 60 return donationPostRepository.findAllByApproved(pageable, true); 59 61 } 60 62 } -
src/main/resources/templates/album.html
r0f4f552 r276a8b6 16 16 <p th:if="${noPosts}">No posts</p> 17 17 <div th:unless="${noPosts}" class="album py-5 bg-light"> 18 18 19 <div class="container"> 19 20 <div class="row"> 21 <div class="col-md-2"> 22 <label class="form-label" for="sortBy">Sort By</label> 23 <select class="input-group-text" id="sortBy"> 24 <option value="id">Default</option> 25 <option value="title">Title</option> 26 <option value="dateDue">Date due</option> 27 <option value="fundsNeeded">Funds needed</option> 28 </select> 29 </div> 30 <div class="col-md-2"> 31 <label class="form-label" for="order">Order</label> 32 <select class="input-group-text" id="order"> 33 <option value="asc">Ascending</option> 34 <option value="desc">Descending</option> 35 </select> 36 </div> 37 </div> 38 <br> 20 39 <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3"> 21 40 <div class="col" th:each="post : ${postList}"> … … 37 56 </div> 38 57 </div> 39 <hr class="ui-menu-divider" 58 <hr class="ui-menu-divider"/> 40 59 <nav> 41 <ul class="pagination justify-content-center"> 42 <li class="page-item"><a class="page-link" href="#">Previous</a></li> 43 <li class="page-item"><a class="page-link" href="#">1</a></li> 44 <li class="page-item"><a class="page-link" href="#">2</a></li> 45 <li class="page-item"><a class="page-link" href="#">3</a></li> 46 <li class="page-item"><a class="page-link" href="#">Next</a></li> 47 </ul> 60 <div id="pagination"></div> 48 61 </nav> 49 62 </div> … … 51 64 </main> 52 65 <script src="/js/bootstrap.min.js"></script> 66 <script id="helper" src="/js/pagination.js" th:data-pages="${totalPages}"></script> 53 67 </body> 54 68 </html> -
src/main/resources/templates/common/navbar.html
r0f4f552 r276a8b6 23 23 </li> 24 24 <li class="nav-item"> 25 <a sec:authorize="isAnonymous() or hasAuthority('USER')" th:href="@{/album?page=1 }" class="nav-link px-2 text-white">Posts</a>25 <a sec:authorize="isAnonymous() or hasAuthority('USER')" th:href="@{/album?page=1&sort=id}" class="nav-link px-2 text-white">Posts</a> 26 26 <a sec:authorize="hasAuthority('MODERATOR')" th:href="@{/moderator/approval}" class="nav-link px-2 text-white">Posts for approval</a> 27 27 </li>
Note:
See TracChangeset
for help on using the changeset viewer.