#76 adding sorting
This commit is contained in:
parent
3698d31bc8
commit
7248a84c30
@ -45,7 +45,7 @@ public class TaskController {
|
||||
|
||||
@GetMapping("/tasks")
|
||||
public void getTask(ModelMap modelMap) {
|
||||
modelMap.put("filteredTasks", new TaskFilterDto(taskService.findAllDto(), null, null));
|
||||
modelMap.put("filteredTasks", new TaskFilterDto(taskService.findAllDto(), null, null, null));
|
||||
}
|
||||
|
||||
@GetMapping("/task")
|
||||
@ -61,7 +61,8 @@ public class TaskController {
|
||||
public void filterTasks(@Valid TaskFilterDto taskFilterDto, ModelMap modelMap) {
|
||||
modelMap.put("filteredTasks", new TaskFilterDto(taskService.filter(taskFilterDto),
|
||||
taskFilterDto.getStatus(),
|
||||
taskFilterDto.getTag()));
|
||||
taskFilterDto.getTag(),
|
||||
taskFilterDto.getOrder()));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/task", params = "save")
|
||||
|
@ -7,11 +7,13 @@ public class TaskFilterDto {
|
||||
private List<TaskDto> tasks;
|
||||
private Task.TaskStatus status;
|
||||
private Integer tagId;
|
||||
private String order;
|
||||
|
||||
public TaskFilterDto(List<TaskDto> tasks, Task.TaskStatus status, Integer tagId) {
|
||||
public TaskFilterDto(List<TaskDto> tasks, Task.TaskStatus status, Integer tagId, String order) {
|
||||
this.tasks = tasks;
|
||||
this.status = status;
|
||||
this.tagId = tagId;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public TaskFilterDto() {
|
||||
@ -41,4 +43,12 @@ public class TaskFilterDto {
|
||||
public void setTag(Integer tagId) {
|
||||
this.tagId = tagId;
|
||||
}
|
||||
|
||||
public String getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(String order) {
|
||||
this.order = order;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,9 @@ import java.util.List;
|
||||
|
||||
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);
|
||||
@Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date DESC")
|
||||
List<Task> filterNew(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag);
|
||||
|
||||
@Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date ASC")
|
||||
List<Task> filterOld(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ru.ulstu.students.service;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulstu.deadline.service.DeadlineService;
|
||||
@ -29,15 +30,15 @@ public class TaskService {
|
||||
private final DeadlineService deadlineService;
|
||||
private final TagService tagService;
|
||||
|
||||
public TaskService(TaskRepository grantRepository,
|
||||
public TaskService(TaskRepository taskRepository,
|
||||
DeadlineService deadlineService, TagService tagService) {
|
||||
this.taskRepository = grantRepository;
|
||||
this.taskRepository = taskRepository;
|
||||
this.deadlineService = deadlineService;
|
||||
this.tagService = tagService;
|
||||
}
|
||||
|
||||
public List<Task> findAll() {
|
||||
return taskRepository.findAll();
|
||||
return taskRepository.findAll(new Sort(Sort.Direction.DESC, "createDate"));
|
||||
}
|
||||
|
||||
public List<TaskDto> findAllDto() {
|
||||
@ -51,9 +52,15 @@ public class TaskService {
|
||||
}
|
||||
|
||||
public List<TaskDto> filter(TaskFilterDto filterDto) {
|
||||
return convert(taskRepository.filter(
|
||||
if (filterDto.getOrder().compareTo("new") == 0) {
|
||||
return convert(taskRepository.filterNew(
|
||||
filterDto.getStatus(),
|
||||
filterDto.getTag() == null ? null : tagService.findById(filterDto.getTag())), TaskDto::new);
|
||||
} else {
|
||||
return convert(taskRepository.filterOld(
|
||||
filterDto.getStatus(),
|
||||
filterDto.getTag() == null ? null : tagService.findById(filterDto.getTag())), TaskDto::new);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
@ -24,6 +24,10 @@
|
||||
line-height: 25px;
|
||||
}
|
||||
|
||||
.sorting .bootstrap-select{
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.input-tag-name {
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
|
@ -25,6 +25,19 @@
|
||||
</th:block>
|
||||
</div>
|
||||
<div class="col-md-3 col-sm-12">
|
||||
<div class="sorting">
|
||||
<h5>Сортировать:</h5>
|
||||
<select class="form-control selectpicker" size="auto" th:field="${filteredTasks.order}"
|
||||
id="order"
|
||||
onchange="this.form.submit();">
|
||||
<option th:value="new">
|
||||
Сначала новые
|
||||
</option>
|
||||
<option th:value="old">
|
||||
Сначала старые
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter">
|
||||
<h5>Фильтр:</h5>
|
||||
<select class="form-control selectpicker" size="auto" th:field="${filteredTasks.status}"
|
||||
|
Loading…
Reference in New Issue
Block a user