Resolve "Ping конференции в списке конференций" #196
@ -7,7 +7,9 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.students.model.Task;
|
import ru.ulstu.students.model.Task;
|
||||||
import ru.ulstu.students.model.TaskDto;
|
import ru.ulstu.students.model.TaskDto;
|
||||||
|
import ru.ulstu.students.model.TaskFilterDto;
|
||||||
import ru.ulstu.students.service.TaskService;
|
import ru.ulstu.students.service.TaskService;
|
||||||
|
import ru.ulstu.tags.model.Tag;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
import springfox.documentation.annotations.ApiIgnore;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
@ -29,23 +31,21 @@ public class TaskController {
|
|||||||
this.taskService = taskService;
|
this.taskService = taskService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/tasks")
|
|
||||||
public void getTasks(ModelMap modelMap) {
|
|
||||||
modelMap.put("tasks", taskService.findAllDto());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/dashboard")
|
@GetMapping("/dashboard")
|
||||||
public void getDashboard(ModelMap modelMap) {
|
public void getDashboard(ModelMap modelMap) {
|
||||||
modelMap.put("tasks", taskService.findAllDto());
|
modelMap.put("tasks", taskService.findAllDto());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/task")
|
@GetMapping("/tasks")
|
||||||
public void getTask(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
public void getTask(ModelMap modelMap) {
|
||||||
if (id != null && id > 0) {
|
modelMap.put("filteredTasks", new TaskFilterDto(taskService.findAllDto(), null, null));
|
||||||
modelMap.put("taskDto", taskService.findOneDto(id));
|
}
|
||||||
} else {
|
|
||||||
modelMap.put("taskDto", new TaskDto());
|
@PostMapping("/tasks")
|
||||||
}
|
public void filterTasks(@Valid TaskFilterDto taskFilterDto, ModelMap modelMap) {
|
||||||
|
modelMap.put("filteredTasks", new TaskFilterDto(taskService.filter(taskFilterDto),
|
||||||
|
taskFilterDto.getStatus(),
|
||||||
|
taskFilterDto.getTag()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/task", params = "save")
|
@PostMapping(value = "/task", params = "save")
|
||||||
@ -83,6 +83,11 @@ public class TaskController {
|
|||||||
return taskService.getTaskStatuses();
|
return taskService.getTaskStatuses();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("allTags")
|
||||||
|
public List<Tag> getTags() {
|
||||||
|
return taskService.getTags();
|
||||||
|
}
|
||||||
|
|
||||||
private void filterEmptyDeadlines(TaskDto taskDto) {
|
private void filterEmptyDeadlines(TaskDto taskDto) {
|
||||||
taskDto.setDeadlines(taskDto.getDeadlines().stream()
|
taskDto.setDeadlines(taskDto.getDeadlines().stream()
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
||||||
|
@ -38,7 +38,7 @@ public class Task extends BaseEntity {
|
|||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
private ru.ulstu.students.model.Task.TaskStatus status = TaskStatus.IN_WORK;
|
private TaskStatus status = TaskStatus.IN_WORK;
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "task_id", unique = true)
|
@JoinColumn(name = "task_id", unique = true)
|
||||||
|
@ -26,7 +26,7 @@ public class TaskDto {
|
|||||||
private Date createDate;
|
private Date createDate;
|
||||||
private Date updateDate;
|
private Date updateDate;
|
||||||
private Set<Integer> tagIds;
|
private Set<Integer> tagIds;
|
||||||
private List<Tag> tags;
|
private List<Tag> tags = new ArrayList<>();
|
||||||
|
|
||||||
public TaskDto() {
|
public TaskDto() {
|
||||||
deadlines.add(new Deadline());
|
deadlines.add(new Deadline());
|
||||||
|
44
src/main/java/ru/ulstu/students/model/TaskFilterDto.java
Normal file
44
src/main/java/ru/ulstu/students/model/TaskFilterDto.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package ru.ulstu.students.model;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TaskFilterDto {
|
||||||
|
|
||||||
|
private List<TaskDto> tasks;
|
||||||
|
private Task.TaskStatus status;
|
||||||
|
private Integer tagId;
|
||||||
|
|
||||||
|
public TaskFilterDto(List<TaskDto> tasks, Task.TaskStatus status, Integer tagId) {
|
||||||
|
this.tasks = tasks;
|
||||||
|
this.status = status;
|
||||||
|
this.tagId = tagId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskFilterDto() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TaskDto> getTasks() {
|
||||||
|
return tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTasks(List<TaskDto> tasks) {
|
||||||
|
this.tasks = tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task.TaskStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Task.TaskStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getTag() {
|
||||||
|
return tagId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTag(Integer tagId) {
|
||||||
|
this.tagId = tagId;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,15 @@
|
|||||||
package ru.ulstu.students.repository;
|
package ru.ulstu.students.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import ru.ulstu.students.model.Task;
|
import ru.ulstu.students.model.Task;
|
||||||
|
import ru.ulstu.tags.model.Tag;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface TaskRepository extends JpaRepository<Task, Integer> {
|
public interface TaskRepository extends JpaRepository<Task, Integer> {
|
||||||
|
|
||||||
|
@Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags)")
|
||||||
|
List<Task> filter(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.students.model.Task;
|
import ru.ulstu.students.model.Task;
|
||||||
import ru.ulstu.students.model.TaskDto;
|
import ru.ulstu.students.model.TaskDto;
|
||||||
|
import ru.ulstu.students.model.TaskFilterDto;
|
||||||
import ru.ulstu.students.repository.TaskRepository;
|
import ru.ulstu.students.repository.TaskRepository;
|
||||||
|
import ru.ulstu.tags.model.Tag;
|
||||||
import ru.ulstu.tags.service.TagService;
|
import ru.ulstu.tags.service.TagService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -48,6 +50,12 @@ public class TaskService {
|
|||||||
return new TaskDto(taskRepository.findOne(id));
|
return new TaskDto(taskRepository.findOne(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<TaskDto> filter(TaskFilterDto filterDto) {
|
||||||
|
return convert(taskRepository.filter(
|
||||||
|
filterDto.getStatus(),
|
||||||
|
filterDto.getTag() == null ? null : tagService.findById(filterDto.getTag())), TaskDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer create(TaskDto taskDto) throws IOException {
|
public Integer create(TaskDto taskDto) throws IOException {
|
||||||
Task newTask = copyFromDto(new Task(), taskDto);
|
Task newTask = copyFromDto(new Task(), taskDto);
|
||||||
@ -94,4 +102,8 @@ public class TaskService {
|
|||||||
return Arrays.asList(Task.TaskStatus.values());
|
return Arrays.asList(Task.TaskStatus.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Tag> getTags() {
|
||||||
|
return tagService.getTags();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,4 +50,12 @@ public class TagService {
|
|||||||
return newTag;
|
return newTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Tag> getTags() {
|
||||||
|
return tagRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tag findById(Integer tagId) {
|
||||||
|
return tagRepository.findOne(tagId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,27 +20,28 @@
|
|||||||
<hr/>
|
<hr/>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-9 col-sm-12">
|
<div class="col-md-9 col-sm-12">
|
||||||
<th:block th:each="task : ${tasks}">
|
<th:block th:each="task : ${filteredTasks.tasks}">
|
||||||
<div th:replace="students/fragments/taskLineFragment :: taskLine(task=${task})"/>
|
<div th:replace="students/fragments/taskLineFragment :: taskLine(task=${task})"/>
|
||||||
</th:block>
|
</th:block>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3 col-sm-12">
|
<div class="col-md-3 col-sm-12">
|
||||||
<div class="filter">
|
<div class="filter">
|
||||||
<h5>Фильтр:</h5>
|
<h5>Фильтр:</h5>
|
||||||
<select class="form-control" id="status"
|
<select class="form-control" th:field="${filteredTasks.status}" id="status"
|
||||||
onchange="this.form.submit();">
|
onchange="this.form.submit();">
|
||||||
<option value="">Все статусы</option>
|
<option value="">Все статусы</option>
|
||||||
<!--<option th:each="author: ${allAuthors}" th:value="${author.id}"-->
|
<option th:each="status: ${allStatuses}" th:value="${status}"
|
||||||
<!--th:text="${author.lastName}">lastName-->
|
th:text="${status.statusName}">
|
||||||
<!--</option>-->
|
status
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<select class="form-control" th:field="${filteredTasks.tag}" id="tags"
|
||||||
|
onchange="this.form.submit();">
|
||||||
|
<option value="">Все теги</option>
|
||||||
|
<option th:each="tag: ${allTags}" th:value="${tag.id}"
|
||||||
|
th:text="${tag.tagName}">tag
|
||||||
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<select class="form-control" id="tags"
|
|
||||||
onchange="this.form.submit();">
|
|
||||||
<option value="">Все типы</option>
|
|
||||||
<!--<option th:each="year: ${allYears}" th:value="${year}"-->
|
|
||||||
<!--th:text="${year}">year-->
|
|
||||||
<!--</option>-->
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user