#42 this don't work
This commit is contained in:
parent
f7d766f02d
commit
bd3513118c
@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.grant.model.Grant;
|
||||
import ru.ulstu.grant.model.GrantDto;
|
||||
import ru.ulstu.grant.model.GrantUserFilterDto;
|
||||
import ru.ulstu.grant.service.GrantService;
|
||||
import ru.ulstu.user.model.User;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
@ -48,23 +49,30 @@ public class GrantController {
|
||||
}
|
||||
|
||||
@GetMapping("/grant")
|
||||
public void getGrant(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
||||
public void getGrant(ModelMap modelMap, GrantUserFilterDto grantUserFilterDto, @RequestParam(value = "id") Integer id) {
|
||||
if (id != null && id > 0) {
|
||||
modelMap.put("grantDto", grantService.findOneDto(id));
|
||||
} else {
|
||||
modelMap.put("grantDto", new GrantDto());
|
||||
}
|
||||
modelMap.put("filteredAuthors", new GrantUserFilterDto(grantService.filterUsers(grantUserFilterDto), false, false, false));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/grant", params = "save")
|
||||
public String save(@Valid GrantDto grantDto, Errors errors) throws IOException {
|
||||
public String save(@Valid GrantDto grantDto, GrantUserFilterDto grantUserFilterDto, Errors errors, ModelMap modelMap /*@ModelAttribute List<User> allAuthors*/)
|
||||
throws IOException {
|
||||
filterEmptyDeadlines(grantDto);
|
||||
// фильтр авторов
|
||||
modelMap.put("filteredAuthors", new GrantUserFilterDto(grantService.filterUsers(grantUserFilterDto),
|
||||
grantUserFilterDto.isLeader(),
|
||||
grantUserFilterDto.isBirthDate(),
|
||||
grantUserFilterDto.isDegree()));
|
||||
if (grantDto.getDeadlines().isEmpty()) {
|
||||
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
||||
}
|
||||
if (grantDto.getLeaderId().equals(null)) {
|
||||
errors.rejectValue("leader", "errorCode", "Укажите руководителя");
|
||||
// } else {
|
||||
// allAuthors.remove(grantDto.getLeaderId());
|
||||
}
|
||||
if (errors.hasErrors()) {
|
||||
return GRANT_PAGE;
|
||||
@ -92,6 +100,12 @@ public class GrantController {
|
||||
return GRANT_PAGE;
|
||||
}
|
||||
|
||||
// @PostMapping(value = "/grant", params = "updateAuthors")
|
||||
// public String updateAuthors(@ModelAttribute List<User> allAuthors, @Valid GrantDto grantDto) {
|
||||
// allAuthors.remove(grantDto.getLeaderId());
|
||||
// return GRANT_PAGE;
|
||||
// }
|
||||
|
||||
@GetMapping("/delete/{grant-id}")
|
||||
public String delete(@PathVariable("grant-id") Integer grantId) throws IOException {
|
||||
grantService.delete(grantId);
|
||||
@ -108,6 +122,11 @@ public class GrantController {
|
||||
return grantService.getGrantAuthors();
|
||||
}
|
||||
|
||||
// @ModelAttribute("allLeaders")
|
||||
// public List<User> getAllLeaders() {
|
||||
// return grantService.getGrantAuthors();
|
||||
// }
|
||||
|
||||
private void filterEmptyDeadlines(GrantDto grantDto) {
|
||||
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
||||
|
54
src/main/java/ru/ulstu/grant/model/GrantUserFilterDto.java
Normal file
54
src/main/java/ru/ulstu/grant/model/GrantUserFilterDto.java
Normal file
@ -0,0 +1,54 @@
|
||||
package ru.ulstu.grant.model;
|
||||
|
||||
import ru.ulstu.user.model.UserDto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GrantUserFilterDto {
|
||||
private List<UserDto> users;
|
||||
private boolean leader;
|
||||
private boolean birthDate;
|
||||
private boolean degree;
|
||||
|
||||
public GrantUserFilterDto() {
|
||||
}
|
||||
|
||||
public GrantUserFilterDto(List<UserDto> users, boolean leader, boolean birthDate, boolean degree) {
|
||||
this.users = users;
|
||||
this.leader = leader;
|
||||
this.birthDate = birthDate;
|
||||
this.degree = degree;
|
||||
}
|
||||
|
||||
public List<UserDto> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(List<UserDto> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
public boolean isLeader() {
|
||||
return leader;
|
||||
}
|
||||
|
||||
public void setLeader(boolean leader) {
|
||||
this.leader = leader;
|
||||
}
|
||||
|
||||
public boolean isBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
public void setBirthDate(boolean birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public boolean isDegree() {
|
||||
return degree;
|
||||
}
|
||||
|
||||
public void setDegree(boolean degree) {
|
||||
this.degree = degree;
|
||||
}
|
||||
}
|
@ -1,8 +1,29 @@
|
||||
package ru.ulstu.grant.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import ru.ulstu.grant.model.Grant;
|
||||
import ru.ulstu.user.model.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface GrantRepository extends JpaRepository<Grant, Integer> {
|
||||
// @Query(value = "SELECT u.last_name " +
|
||||
// "FROM users u, grants g " +
|
||||
// "WHERE (g.leader_id = u.id) " +
|
||||
// "AND (u.birth_date < 35) " +
|
||||
// "AND (u.degree = 'CANDIDATE')" +
|
||||
// "Group by u.last_name",
|
||||
// nativeQuery = true)
|
||||
// List<User> filter(@Param("leader") Integer leader, @Param("birthYear") Date birthYear, @Param("degree") String degree);
|
||||
|
||||
@Query("SELECT u.lastName FROM User u, Grant g WHERE (g.leader = u.id OR :leader IS FALSE) " +
|
||||
"AND (extract(year from interval (age(birth_date::date))) < 35 OR :birthDate IS FALSE) " +
|
||||
"AND (u.degree = 'CANDIDATE' OR :degree IS FALSE)" +
|
||||
"GROUP BY u.lastName")
|
||||
List<User> filterUsers(@Param("leader") boolean leader,
|
||||
@Param("birthDate") boolean birthDate,
|
||||
@Param("degree") boolean degree);
|
||||
|
||||
}
|
||||
|
@ -8,11 +8,13 @@ import ru.ulstu.deadline.service.DeadlineService;
|
||||
import ru.ulstu.file.service.FileService;
|
||||
import ru.ulstu.grant.model.Grant;
|
||||
import ru.ulstu.grant.model.GrantDto;
|
||||
import ru.ulstu.grant.model.GrantUserFilterDto;
|
||||
import ru.ulstu.grant.repository.GrantRepository;
|
||||
import ru.ulstu.project.model.Project;
|
||||
import ru.ulstu.project.model.ProjectDto;
|
||||
import ru.ulstu.project.service.ProjectService;
|
||||
import ru.ulstu.user.model.User;
|
||||
import ru.ulstu.user.model.UserDto;
|
||||
import ru.ulstu.user.service.UserService;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -141,4 +143,9 @@ public class GrantService {
|
||||
public List<User> getGrantAuthors() {
|
||||
return userService.findAll();
|
||||
}
|
||||
|
||||
public List<UserDto> filterUsers(GrantUserFilterDto filterDto) {
|
||||
return convert(grantRepository.filterUsers(
|
||||
filterDto.isLeader(), filterDto.isBirthDate(), filterDto.isDegree()), UserDto::new);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
<div class="container" layout:fragment="content">
|
||||
|
||||
<section id="paper">
|
||||
<section id="grant">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-12 text-center">
|
||||
@ -94,17 +94,22 @@
|
||||
<div class="form-check collapse" id="collapse-filter">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<input class="form-check-input" type="checkbox" id="f1"/>
|
||||
<input class="form-check-input" type="checkbox" id="f1"
|
||||
th:field="${filteredAuthors.leader}" onchange="this.form.submit();"/>
|
||||
<!--path="filteredAuthors.leader"-->
|
||||
<label class="form-check-label" for="f1">Был руководителем проекта</label>
|
||||
</div>
|
||||
<div class="col">
|
||||
<input class="form-check-input" type="checkbox" id="f2"/>
|
||||
<input class="form-check-input" type="checkbox" id="f2"
|
||||
th:value="${filteredAuthors.birthDate}"
|
||||
onchange="this.form.submit();"/>
|
||||
<label class="form-check-label" for="f2">Младше 35 лет</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<input class="form-check-input" type="checkbox" id="f3"/>
|
||||
<input class="form-check-input" type="checkbox" id="f3"
|
||||
th:value="${filteredAuthors.degree}" onchange="this.form.submit();"/>
|
||||
<label class="form-check-label" for="f3">Cтепень к.т.н.</label> <br/>
|
||||
</div>
|
||||
<div class="col">
|
||||
@ -125,27 +130,30 @@
|
||||
</div>
|
||||
<hr/>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Руководитель проекта:</label>
|
||||
<select class="form-control" th:field="*{leaderId}" id="leader">
|
||||
<option th:each="leader : ${allAuthors}" th:value="${leader.id}"
|
||||
<select class="form-control" th:field="*{leaderId}" id="leader"
|
||||
onchange="updateAuthors();">
|
||||
<option th:each="leader : ${filteredAuthors.users}" th:value="${leader.id}"
|
||||
th:text="${leader.lastName}"> Руководитель
|
||||
</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Участники гранта:</label>
|
||||
<select class="selectpicker form-control" multiple="true" data-live-search="true"
|
||||
title="-- Выберите участников --"
|
||||
<select class="selectpicker form-control" multiple="true"
|
||||
title="-- Выберите участников --" id="authors"
|
||||
th:field="*{authorIds}">
|
||||
<option th:each="author: ${allAuthors}" th:value="${author.id}"
|
||||
<option th:each="author: ${filteredAuthors.users}" th:value="${author.id}"
|
||||
th:text="${author.lastName}"> Участник
|
||||
</option>
|
||||
</select>
|
||||
<p th:if="${#fields.hasErrors('authorIds')}" th:errors="*{authorIds}"
|
||||
class="alert alert-danger">Incorrect member</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Список статей:</label>
|
||||
<p><a href="./#" class="btn btn-primary"><i class="fa fa-plus-circle"
|
||||
@ -197,6 +205,20 @@
|
||||
$('.selectpicker').selectpicker();
|
||||
});
|
||||
/*]]>*/
|
||||
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
function updateAuthors() {
|
||||
//document.allAuthors.action = "${pageContext.request.contextPath}/grant";
|
||||
//document.allAuthors.submit();
|
||||
$("#authors").val('default');
|
||||
$("#authors").selectpicker("refresh");
|
||||
$("#authors").children('option:disabled').prop('disabled', false);
|
||||
|
||||
var lidSel = document.getElementById("leader");
|
||||
var autSel = document.getElementById("authors");
|
||||
autSel.options[lidSel.selectedIndex].disabled="disabled";
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
</body>
|
||||
|
Loading…
Reference in New Issue
Block a user