load paper

pull/149/head
Anton Romanov 6 years ago
parent 5fa5d670a5
commit f376fedc64

@ -4,11 +4,13 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; 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.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable; 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.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.RequestParam;
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;
@ -34,9 +36,18 @@ public class PaperController {
modelMap.put("papers", paperService.findAllDto()); modelMap.put("papers", paperService.findAllDto());
} }
@PostMapping @GetMapping("/paper")
public Response<Integer> createPaper(@RequestBody @Valid PaperDto paperDto) throws IOException { public void getPapers(ModelMap modelMap, @RequestParam(value="id") Integer id) {
return new Response<>(paperService.create(paperDto)); if (id != null && id > 0) {
modelMap.put("paper", paperService.findOneDto(id));
} else {
modelMap.put("paper", new PaperDto());
}
}
@PostMapping("/paper")
public void createPaper(@ModelAttribute PaperDto paperDto) throws IOException {
paperService.create(paperDto);
} }
@PutMapping @PutMapping

@ -14,6 +14,8 @@ import javax.persistence.FetchType;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany; import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
@ -48,13 +50,16 @@ public class Paper extends BaseEntity implements UserContainer {
private PaperStatus status = PaperStatus.DRAFT; private PaperStatus status = PaperStatus.DRAFT;
@Column(name = "create_date") @Column(name = "create_date")
@Temporal(TemporalType.TIMESTAMP)
private Date createDate = new Date(); private Date createDate = new Date();
@Column(name = "update_date") @Column(name = "update_date")
@Temporal(TemporalType.TIMESTAMP)
private Date updateDate = new Date(); private Date updateDate = new Date();
@Column(name = "deadline_date") @Column(name = "deadline_date")
@NotNull @NotNull
@Temporal(TemporalType.DATE)
private Date deadlineDate; private Date deadlineDate;
private String comment; private String comment;

@ -13,21 +13,24 @@ import java.util.stream.Collectors;
import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.core.util.StreamApiUtils.convert;
public class PaperDto { public class PaperDto {
private final Integer id; private Integer id;
@NotEmpty @NotEmpty
private final String title; private String title;
private final Paper.PaperStatus status; private Paper.PaperStatus status;
private final Date createDate; private Date createDate;
private final Date updateDate; private Date updateDate;
@NotNull @NotNull
private final Date deadlineDate; private Date deadlineDate;
private final String comment; private String comment;
private final Boolean locked; private Boolean locked;
private final String tmpFileName; private String tmpFileName;
private final Integer fileId; private Integer fileId;
private final String fileName; private String fileName;
private final Date fileCreateDate; private Date fileCreateDate;
private final Set<UserDto> authors; private Set<UserDto> authors;
public PaperDto() {
}
@JsonCreator @JsonCreator
public PaperDto(@JsonProperty("id") Integer id, public PaperDto(@JsonProperty("id") Integer id,

@ -56,6 +56,10 @@ public class PaperService {
return convert(findAll(), PaperDto::new); return convert(findAll(), PaperDto::new);
} }
public PaperDto findOneDto(Integer id) {
return new PaperDto(paperRepository.findOne(id));
}
@Transactional @Transactional
public Integer create(PaperDto paperDto) throws IOException { public Integer create(PaperDto paperDto) throws IOException {
Paper newPaper = copyFromDto(new Paper(), paperDto); Paper newPaper = copyFromDto(new Paper(), paperDto);

@ -23,4 +23,10 @@
constraintName="fk_event_child_event" referencedTableName="event" constraintName="fk_event_child_event" referencedTableName="event"
referencedColumnNames="id"/> referencedColumnNames="id"/>
</changeSet> </changeSet>
<changeSet author="orion" id="20181126_000000-4">
<modifyDataType
columnName="deadline_date"
newDataType="date"
tableName="paper"/>
</changeSet>
</databaseChangeLog> </databaseChangeLog>

@ -32,7 +32,8 @@ function showPapers(papersElement, paperRowClass) {
}); });
} }
function deletePaper(id, papersElement, paperRowClass) { function deletePaper(idElement, papersElement, paperRowClass) {
var id = $(idElement).parent().find('.id-class').val();
$("#remove-paper-modal").modal('show'); $("#remove-paper-modal").modal('show');
$("#modal-btn-yes").on("click", function () { $("#modal-btn-yes").on("click", function () {

@ -88,8 +88,6 @@
</div> </div>
</footer> </footer>
<!-- Custom scripts for this template -->
<script src="/js/agency.js"></script>
<script src="/js/core.js"></script> <script src="/js/core.js"></script>
<!-- Yandex.Metrika counter --> <!-- Yandex.Metrika counter -->
<script type="text/javascript" > <script type="text/javascript" >

@ -19,7 +19,7 @@
Список</a> Список</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="./dashboard" class="btn btn-light toolbar-button"><i class="fa fa-newspaper-o" <a href="./dashboard?id=0" 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">

@ -30,7 +30,9 @@
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i> <i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
</span> </span>
<a th:href="@{'paper?id='+${paper.id}}"><span th:text="${paper.title}"></span></a> <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')"> <input class="id-class" type="hidden" th:value="${paper.id}"/>
<span class="remove-paper pull-right d-none"
onclick="deletePaper($(this), '#paper-list', '.paper-row');">
<i class="fa fa-trash" aria-hidden="true"></i> <i class="fa fa-trash" aria-hidden="true"></i>
</span> </span>
</div> </div>

@ -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:form="http://www.w3.org/1999/xhtml" xmlns:th="http://www.w3.org/1999/xhtml">
<head> <head>
</head> </head>
@ -23,15 +23,25 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<form id="contactForm" name="sentMessage" novalidate=""> <form method="post" action="#" th:action="@{/papers/paper}" th:object="${paper}">
<input type="hidden" name="id" th:field="*{id}"
th:value="${id}"
/>
<div class="row"> <div class="row">
<div class="col-md-6 col-sm-12"> <div class="col-md-6 col-sm-12">
<div class="form-group"> <div class="form-group">
<label for="name">Название:</label> <label for="title">Название:</label>
<input class="form-control" id="name" type="text" placeholder="Название статьи"
required="" data-validation-required-message="Введите название статьи"/> <input class="form-control" id="title" name="title" type="text"
placeholder="Название статьи"
required=""
data-validation-required-message="Введите название статьи"
th:value="${title}"
th:field="*{title}"
/>
<p class="help-block text-danger"></p> <p class="help-block text-danger"></p>
</div> </div>
@ -44,16 +54,23 @@
<div class="form-group"> <div class="form-group">
<label for="comment">Комментарий:</label> <label for="comment">Комментарий:</label>
<textarea class="form-control" rows="5" id="comment"></textarea> <textarea class="form-control" rows="5" id="comment"
th:value="${comment}"
th:field="*{comment}"></textarea>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Дедлайн:</label> <label>Дедлайн:</label>
<input type="date" class="form-control" name="deadline"/> <input type="date" class="form-control" name="deadline"
th:value="${deadlineDate}"
th:field="*{deadlineDate}"
/>
</div> </div>
<div class="form-check"> <div class="form-check">
<input type="checkbox" class="form-check-input" id="locked"/> <input type="checkbox" class="form-check-input" id="locked"
th:value="${locked}"
th:field="*{locked}"/>
<label class="form-check-label" for="locked">Заблокирована</label> <label class="form-check-label" for="locked">Заблокирована</label>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -70,7 +87,8 @@
<label>Последнее изменение:</label> <label>Последнее изменение:</label>
<input type="date" class="form-control" name="date-update"/> <input type="date" class="form-control" name="date-update"/>
</div> </div>
<p><a href="#myModal1" class="btn btn-primary" data-toggle="modal">Редактировать авторов <p><a href="#myModal1" class="btn btn-primary" data-toggle="modal">Редактировать
авторов
статьи</a></p> статьи</a></p>
<div id="myModal1" class="modal fade"> <div id="myModal1" class="modal fade">
<div class="modal-dialog"> <div class="modal-dialog">
@ -111,7 +129,8 @@
<div class="dropdown"> <div class="dropdown">
<button class="btn btn-primary dropdown-toggle" <button class="btn btn-primary dropdown-toggle"
type="button" data-toggle="dropdown">Выберите автора type="button" data-toggle="dropdown">Выберите
автора
<span class="caret"></span></button> <span class="caret"></span></button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<input class="form-control" id="myInput" type="text" <input class="form-control" id="myInput" type="text"
@ -156,6 +175,7 @@
Отмена Отмена
</button> </button>
</div> </div>
</div> </div>
</div> </div>
</form> </form>

@ -25,7 +25,7 @@
</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" <a href="./paper?id=0" class="btn btn-light toolbar-button"><i class="fa fa-plus-circle"
aria-hidden="true"></i> aria-hidden="true"></i>
Добавить статью</a> Добавить статью</a>
</div> </div>

Loading…
Cancel
Save