#97 adding deadlines
This commit is contained in:
parent
53cc947a17
commit
019fe7c652
@ -8,6 +8,8 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.grant.model.GrantDto;
|
||||
import ru.ulstu.project.model.Project;
|
||||
import ru.ulstu.project.model.ProjectDto;
|
||||
import ru.ulstu.project.service.ProjectService;
|
||||
@ -61,11 +63,23 @@ public class ProjectController {
|
||||
if (projectDto.getDeadlines().isEmpty()) {
|
||||
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
||||
}
|
||||
hasErrors(errors, "/projects/project");
|
||||
if (errors.hasErrors()) {
|
||||
return "/projects/project";
|
||||
}
|
||||
projectService.save(projectDto);
|
||||
return String.format("redirect:%s", "/projects/projects");
|
||||
}
|
||||
|
||||
@PostMapping(value = "/project", params = "addDeadline")
|
||||
public String addDeadline(@Valid ProjectDto projectDto, Errors errors) {
|
||||
filterEmptyDeadlines(projectDto);
|
||||
if (errors.hasErrors()) {
|
||||
return "/projects/project";
|
||||
}
|
||||
projectDto.getDeadlines().add(new Deadline());
|
||||
return "/projects/project";
|
||||
}
|
||||
|
||||
private void filterEmptyDeadlines(ProjectDto projectDto) {
|
||||
projectDto.setDeadlines(projectDto.getDeadlines().stream()
|
||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
||||
|
@ -73,11 +73,11 @@
|
||||
<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"
|
||||
<div class="col-6 div-deadline-date">
|
||||
<input type="date" class="form-control form-deadline-date" name="deadline"
|
||||
th:field="*{deadlines[__${rowStat.index}__].date}"/>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="col-4 div-deadline-description">
|
||||
<input class="form-control" type="text" placeholder="Описание"
|
||||
th:field="*{deadlines[__${rowStat.index}__].description}"/>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user