show paper list in mvc

This commit is contained in:
Anton Romanov 2018-11-23 16:45:40 +04:00
parent e84e542309
commit 5fa5d670a5
4 changed files with 77 additions and 18 deletions

View File

@ -20,7 +20,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static ru.ulstu.paper.controller.PaperController.URL; import static ru.ulstu.file.FileController.URL;
@RestController @RestController
@RequestMapping(URL) @RequestMapping(URL)

View File

@ -1,5 +1,7 @@
package ru.ulstu.paper.controller; package ru.ulstu.paper.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -7,8 +9,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.ulstu.configuration.Constants;
import ru.ulstu.core.model.response.Response; import ru.ulstu.core.model.response.Response;
import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperFilterDto; import ru.ulstu.paper.model.PaperFilterDto;
@ -19,22 +19,19 @@ import javax.validation.Valid;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import static ru.ulstu.paper.controller.PaperController.URL;
@RestController @Controller()
@RequestMapping(URL) @RequestMapping(value = "/papers")
public class PaperController { public class PaperController {
public static final String URL = Constants.API_1_0 + "papers";
private final PaperService paperService; private final PaperService paperService;
public PaperController(PaperService paperService) { public PaperController(PaperService paperService) {
this.paperService = paperService; this.paperService = paperService;
} }
@GetMapping @GetMapping("/papers")
public Response<List<PaperDto>> getPapers() { public void getPapers(ModelMap modelMap) {
return new Response<>(paperService.findAllDto()); modelMap.put("papers", paperService.findAllDto());
} }
@PostMapping @PostMapping

View File

@ -0,0 +1,41 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head th:fragment="headerfiles">
<meta charset="UTF-8"/>
</head>
<body>
<div th:fragment="titleLine (paper)" class="row text-left paper-row" style="background-color: white;">
<div class="col">
<span class="fa-stack fa-1x">
<th:block th:switch="${paper.status.name()}">
<div th:case="'ATTENTION'">
<i class="fa fa-circle fa-stack-2x text-warning"></i>
</div>
<div th:case="'DRAFT'">
<i class="fa fa-circle fa-stack-2x text-draft"></i>
</div>
<div th:case="'ON_PREPARATION'">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
</div>
<div th:case="'ON_REVIEW'">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
</div>
<div th:case="'COMPLETED'">
<i class="fa fa-circle fa-stack-2x text-success"></i>
</div>
<div th:case="'FAILED'">
<i class="fa fa-circle fa-stack-2x text-failed"></i>
</div>
</th:block>
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
</span>
<a th:href="@{'paper?id='+${paper.id}}"><span th:text="${paper.title}"></span></a>
<span class="remove-paper pull-right d-none" onclick="deletePaper('${id}','#paper-list', '.paper-row')">
<i class="fa fa-trash" aria-hidden="true"></i>
</span>
</div>
</div>
</body>
</html>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" <html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default"> layout:decorator="default" xmlns:th="">
<head> <head>
</head> </head>
<body> <body>
@ -20,25 +20,32 @@
</div> </div>
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3"> <div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
<a href="./dashboard" class="btn btn-light toolbar-button"><i class="fa fa-newspaper-o" <a href="./dashboard" class="btn btn-light toolbar-button"><i class="fa fa-newspaper-o"
aria-hidden="true"></i> Панель управления</a> aria-hidden="true"></i> Панель
управления</a>
</div> </div>
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3"> <div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
<a href="./paper" class="btn btn-light toolbar-button"><i class="fa fa-plus-circle" aria-hidden="true"></i> <a href="./paper" class="btn btn-light toolbar-button"><i class="fa fa-plus-circle"
aria-hidden="true"></i>
Добавить статью</a> Добавить статью</a>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<th:block th:each="paper : ${papers}">
<div th:replace="papers/fragments/paperLineFragment :: titleLine(paper=${paper})"/>
</th:block>
</div> </div>
</section> </section>
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" id="remove-paper-modal"> <div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"
id="remove-paper-modal">
<div class="modal-dialog modal-sm"> <div class="modal-dialog modal-sm">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h8 class="modal-title" id="myModalLabel">Удалить статью?</h8> <h8 class="modal-title" id="myModalLabel">Удалить статью?</h8>
<button type="button" class="close" data-dismiss="modal" aria-label="Закрыть"><span aria-hidden="true">&times;</span></button> <button type="button" class="close" data-dismiss="modal" aria-label="Закрыть"><span
aria-hidden="true">&times;</span></button>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-default" id="modal-btn-yes">Да</button> <button type="button" class="btn btn-default" id="modal-btn-yes">Да</button>
@ -48,11 +55,25 @@
</div> </div>
</div> </div>
<script src="/js/papers.js"></script> <script src="/js/papers.js"></script>
<script>
<script type="text/javascript">
/*<![CDATA[*/
$(document).ready(function () { $(document).ready(function () {
showPapers("#paper-list", ".paper-row"); $(".paper-row").mouseenter(function (event) {
var paperRow = $(event.target).closest(".paper-row");
$(paperRow).css("background-color", "#f8f9fa");
$(paperRow).find(".remove-paper").removeClass("d-none");
});
$(".paper-row").mouseleave(function (event) {
var paperRow = $(event.target).closest(".paper-row");
$(paperRow).css("background-color", "white");
$(paperRow).closest(".paper-row").find(".remove-paper").addClass("d-none");
});
}); });
/*]]>*/
</script> </script>
</div> </div>
</body> </body>