edit deadlines

This commit is contained in:
Anton Romanov 2018-12-17 13:46:08 +04:00
parent 54ea705890
commit 59e2c9b544
5 changed files with 75 additions and 88 deletions

View File

@ -2,15 +2,20 @@ package ru.ulstu.deadline.model;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
public class DeadlineDto {
private final Integer id;
private Integer id;
private final String description;
private String description;
private final Date date;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date date;
public DeadlineDto() {
}
@JsonCreator
public DeadlineDto(@JsonProperty("id") Integer id,
@ -38,4 +43,16 @@ public class DeadlineDto {
public Date getDate() {
return date;
}
public void setId(Integer id) {
this.id = id;
}
public void setDescription(String description) {
this.description = description;
}
public void setDate(Date date) {
this.date = date;
}
}

View File

@ -7,19 +7,20 @@ 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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import ru.ulstu.core.model.response.Response;
import ru.ulstu.deadline.model.DeadlineDto;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperFilterDto;
import ru.ulstu.paper.service.PaperService;
import ru.ulstu.user.model.User;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import static org.springframework.util.StringUtils.isEmpty;
@Controller()
@ -45,7 +46,7 @@ public class PaperController {
}
}
@PostMapping("/paper")
@PostMapping(value = "/paper", params = "save")
public String save(@Valid PaperDto paperDto, Errors errors) throws IOException {
if (errors.hasErrors()) {
return "/papers/paper";
@ -54,6 +55,13 @@ public class PaperController {
return "redirect:/papers/papers";
}
@PostMapping(value = "/paper", params = "addDeadline")
public String addDeadline(@Valid PaperDto paperDto) {
filterEmptyDeadlines(paperDto);
paperDto.getDeadlines().add(new DeadlineDto());
return "/papers/paper";
}
@GetMapping("/delete/{paper-id}")
public String delete(@PathVariable("paper-id") Integer paperId) throws IOException {
paperService.delete(paperId);
@ -70,8 +78,9 @@ public class PaperController {
return paperService.getPaperAuthors();
}
@PostMapping("/filter")
public Response<List<PaperDto>> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException {
return new Response<>(paperService.filter(paperFilterDto));
private void filterEmptyDeadlines(PaperDto paperDto) {
paperDto.setDeadlines(paperDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
.collect(Collectors.toList()));
}
}

View File

@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
import ru.ulstu.configuration.Constants;
import ru.ulstu.core.model.response.Response;
import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperFilterDto;
import ru.ulstu.paper.service.PaperService;
import javax.validation.Valid;
@ -55,4 +56,9 @@ public class PaperRestController {
paperService.delete(paperId);
return new Response<>(true);
}
@PostMapping("/filter")
public Response<List<PaperDto>> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException {
return new Response<>(paperService.filter(paperFilterDto));
}
}

View File

@ -20,6 +20,7 @@ public class PaperDto {
private Paper.PaperStatus status;
private Date createDate;
private Date updateDate;
@NotEmpty
private List<DeadlineDto> deadlines;
private String comment;
private Boolean locked;
@ -174,4 +175,8 @@ public class PaperDto {
public void setAuthors(Set<Integer> authors) {
this.authors = authors;
}
public void setDeadlines(List<DeadlineDto> deadlines) {
this.deadlines = deadlines;
}
}

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml">
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<head>
</head>
@ -26,7 +26,7 @@
<div class="row">
<div class="col-lg-12">
<form method="post" th:action="@{'/papers/paper?id='+ *{id == null ? '' : id} + ''}"
<form id="paper-form" method="post" th:action="@{'/papers/paper?id='+ *{id == null ? '' : id} + ''}"
th:object="${paperDto}">
<div class="row">
<div class="col-md-6 col-sm-12">
@ -57,11 +57,33 @@
</div>
<div class="form-group">
<label>Дедлайн:</label>
<input type="date" class="form-control" name="deadline" th:field="*{nextDeadline}"/>
<p th:if="${#fields.hasErrors('nextDeadline')}" th:errors="*{nextDeadline}"
<label>Дедлайны:</label>
<div class="row" th:each="deadline, rowStat : *{deadlines}">
<input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/>
<div class="col-6">
<input type="date" class="form-control" name="deadline"
th:field="*{deadlines[__${rowStat.index}__].date}"/>
</div>
<div class="col-5">
<input class="form-control" type="text" placeholder="Описание"
th:field="*{deadlines[__${rowStat.index}__].description}"/>
</div>
<div class="col-1">
<a class="btn btn-danger float-right"
th:onclick="|$('#deadlines${rowStat.index}\\.description').val('');
$('#deadlines${rowStat.index}\\.date').val('');
$('#addDeadline').click();|"><span
aria-hidden="true"><i class="fa fa-times"/></span>
</a>
</div>
</div>
<p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}"
class="alert alert-danger">Incorrect title</p>
</div>
<div class="form-group">
<input type="submit" id="addDeadline" name="addDeadline" class="btn btn-primary" value="Добавить
дедлайн"/>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="locked"
@ -94,78 +116,6 @@
<p th:if="${#fields.hasErrors('authors')}" th:errors="*{authors}"
class="alert alert-danger">Incorrect title</p>
</div>
<div id="myModal1" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Авторы статьи</h4>
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×
</button>
</div>
<div class="modal-body">
<table class="table">
<thead>
<tr>
<th>Фамилия</th>
<th>Имя</th>
<th>Отчество</th>
</tr>
</thead>
<tbody>
<tr>
<td>Иванов</td>
<td>Иван</td>
<td>Иванович</td>
<td>
<span class="table-remove"><button type="button"
class="btn btn-danger btn-rounded btn-sm my-0">
<i class="fa fa-times"/>
</button>
</span>
</td>
</tr>
<tr>
<td>text</td>
<td>text</td>
<td>text</td>
<td>
<span class="table-remove">
<button type="button"
class="btn btn-danger btn-rounded btn-sm my-0">
<i class="fa fa-times"/>
</button>
</span>
</td>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle"
type="button" data-toggle="dropdown">Выберите
автора
<span class="caret"></span></button>
<ul class="dropdown-menu">
<input class="form-control" id="myInput" type="text"
placeholder="Search.."/>
<li><a href="#">Иванов</a></li>
<li><a href="#">Смирнов</a></li>
<li><a href="#">Кузнецов</a></li>
</ul>
</div>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Сохранить изменения
</button>
<button type="button" class="btn btn-default" data-dismiss="modal">
Отмена
</button>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-3 offset-md-3 col-sm-12 offset-sm-0">
<div class="form-group">
@ -178,7 +128,7 @@
<div class="clearfix"></div>
<div class="col-lg-12">
<div class="form-group">
<button id="sendMessageButton" class="btn btn-success text-uppercase"
<button id="sendMessageButton" name="save" class="btn btn-success text-uppercase"
type="submit">
Сохранить
</button>