|
|
@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import ru.ulstu.deadline.model.Deadline;
|
|
|
|
import ru.ulstu.deadline.model.Deadline;
|
|
|
|
import ru.ulstu.grant.model.Grant;
|
|
|
|
import ru.ulstu.grant.model.Grant;
|
|
|
|
import ru.ulstu.grant.model.GrantDto;
|
|
|
|
import ru.ulstu.grant.model.GrantDto;
|
|
|
|
import ru.ulstu.grant.model.GrantUserFilterDto;
|
|
|
|
|
|
|
|
import ru.ulstu.grant.service.GrantService;
|
|
|
|
import ru.ulstu.grant.service.GrantService;
|
|
|
|
import ru.ulstu.user.model.User;
|
|
|
|
import ru.ulstu.user.model.User;
|
|
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
@ -26,7 +25,6 @@ import static org.springframework.util.StringUtils.isEmpty;
|
|
|
|
import static ru.ulstu.core.controller.Navigation.GRANTS_PAGE;
|
|
|
|
import static ru.ulstu.core.controller.Navigation.GRANTS_PAGE;
|
|
|
|
import static ru.ulstu.core.controller.Navigation.GRANT_PAGE;
|
|
|
|
import static ru.ulstu.core.controller.Navigation.GRANT_PAGE;
|
|
|
|
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
|
|
|
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
|
|
|
import static ru.ulstu.core.controller.Navigation.hasErrors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller()
|
|
|
|
@Controller()
|
|
|
@ -50,30 +48,23 @@ public class GrantController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/grant")
|
|
|
|
@GetMapping("/grant")
|
|
|
|
public void getGrant(ModelMap modelMap, GrantUserFilterDto grantUserFilterDto, @RequestParam(value = "id") Integer id) {
|
|
|
|
public void getGrant(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
|
|
|
if (id != null && id > 0) {
|
|
|
|
if (id != null && id > 0) {
|
|
|
|
modelMap.put("grantDto", grantService.findOneDto(id));
|
|
|
|
modelMap.put("grantDto", grantService.findOneDto(id));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
modelMap.put("grantDto", new GrantDto());
|
|
|
|
modelMap.put("grantDto", new GrantDto());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
modelMap.put("filteredAuthors", new GrantUserFilterDto(grantService.filterUsers(grantUserFilterDto), false, false, false));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/grant", params = "save")
|
|
|
|
@PostMapping(value = "/grant", params = "save")
|
|
|
|
public String save(@Valid GrantDto grantDto, GrantUserFilterDto grantUserFilterDto, Errors errors, ModelMap modelMap /*@ModelAttribute List<User> allAuthors*/)
|
|
|
|
public String save(@Valid GrantDto grantDto, Errors errors)
|
|
|
|
throws IOException {
|
|
|
|
throws IOException {
|
|
|
|
filterEmptyDeadlines(grantDto);
|
|
|
|
filterEmptyDeadlines(grantDto);
|
|
|
|
modelMap.put("filteredAuthors", new GrantUserFilterDto(grantService.filterUsers(grantUserFilterDto),
|
|
|
|
|
|
|
|
grantUserFilterDto.isLeader(),
|
|
|
|
|
|
|
|
grantUserFilterDto.isBirthDate(),
|
|
|
|
|
|
|
|
grantUserFilterDto.isDegree()));
|
|
|
|
|
|
|
|
if (grantDto.getDeadlines().isEmpty()) {
|
|
|
|
if (grantDto.getDeadlines().isEmpty()) {
|
|
|
|
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
|
|
|
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (grantDto.getLeaderId().equals(null)) {
|
|
|
|
if (grantDto.getLeaderId().equals(null)) {
|
|
|
|
errors.rejectValue("leader", "errorCode", "Укажите руководителя");
|
|
|
|
errors.rejectValue("leader", "errorCode", "Укажите руководителя");
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// allAuthors.remove(grantDto.getLeaderId());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (errors.hasErrors()) {
|
|
|
|
if (errors.hasErrors()) {
|
|
|
|
return GRANT_PAGE;
|
|
|
|
return GRANT_PAGE;
|
|
|
@ -82,6 +73,11 @@ public class GrantController {
|
|
|
|
return String.format(REDIRECT_TO, GRANTS_PAGE);
|
|
|
|
return String.format(REDIRECT_TO, GRANTS_PAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/grant", params = "filterUsers")
|
|
|
|
|
|
|
|
public String filterUsers() {
|
|
|
|
|
|
|
|
return GRANT_PAGE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/grant", params = "addDeadline")
|
|
|
|
@PostMapping(value = "/grant", params = "addDeadline")
|
|
|
|
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
|
|
|
|
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
|
|
|
|
filterEmptyDeadlines(grantDto);
|
|
|
|
filterEmptyDeadlines(grantDto);
|
|
|
@ -101,12 +97,6 @@ public class GrantController {
|
|
|
|
return GRANT_PAGE;
|
|
|
|
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}")
|
|
|
|
@GetMapping("/delete/{grant-id}")
|
|
|
|
public String delete(@PathVariable("grant-id") Integer grantId) throws IOException {
|
|
|
|
public String delete(@PathVariable("grant-id") Integer grantId) throws IOException {
|
|
|
|
grantService.delete(grantId);
|
|
|
|
grantService.delete(grantId);
|
|
|
@ -119,15 +109,10 @@ public class GrantController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ModelAttribute("allAuthors")
|
|
|
|
@ModelAttribute("allAuthors")
|
|
|
|
public List<User> getAllAuthors() {
|
|
|
|
public List<User> getAllAuthors(GrantDto grantDto) {
|
|
|
|
return grantService.getGrantAuthors();
|
|
|
|
return grantService.getGrantAuthors(grantDto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// @ModelAttribute("allLeaders")
|
|
|
|
|
|
|
|
// public List<User> getAllLeaders() {
|
|
|
|
|
|
|
|
// return grantService.getGrantAuthors();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void filterEmptyDeadlines(GrantDto grantDto) {
|
|
|
|
private void filterEmptyDeadlines(GrantDto grantDto) {
|
|
|
|
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
|
|
|
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
|
|
|
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
|
|
|
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
|
|
|