Resolve "Ping конференции в списке конференций" #196

Merged
VladimirZarayskiy merged 44 commits from 68-ping-conf into dev 2019-04-25 14:00:36 +04:00
6 changed files with 94 additions and 24 deletions
Showing only changes of commit d3b8be2cf1 - Show all commits

View File

@ -51,7 +51,9 @@ public class GrantController {
@GetMapping("/grant") @GetMapping("/grant")
public void getGrant(ModelMap modelMap, @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)); GrantDto grantDto = grantService.findOneDto(id);
attachPaper(grantDto);
modelMap.put("grantDto", grantDto);
} else { } else {
modelMap.put("grantDto", new GrantDto()); modelMap.put("grantDto", new GrantDto());
} }
@ -79,6 +81,17 @@ public class GrantController {
return GRANT_PAGE; return GRANT_PAGE;
} }
@PostMapping(value = "/grant", params = "attachPaper")
public String attachPaper(GrantDto grantDto) {
if (!grantDto.getPaperIds().isEmpty()) {
grantDto.getPapers().clear();
grantDto.setPapers(grantService.getGrantPapers(grantDto.getPaperIds()));
} else {
grantDto.getPapers().clear();
}
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);
@ -115,8 +128,8 @@ public class GrantController {
} }
@ModelAttribute("allPapers") @ModelAttribute("allPapers")
public List<Paper> getGrantPapers() { public List<Paper> getAllPapers() {
return grantService.getGrantPapers(); return grantService.getAllPapers();
} }
private void filterEmptyDeadlines(GrantDto grantDto) { private void filterEmptyDeadlines(GrantDto grantDto) {

View File

@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotEmpty; import org.hibernate.validator.constraints.NotEmpty;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.Paper;
import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
@ -34,7 +34,7 @@ public class GrantDto {
private boolean hasAge; private boolean hasAge;
private boolean hasDegree; private boolean hasDegree;
private List<Integer> paperIds = new ArrayList<>(); private List<Integer> paperIds = new ArrayList<>();
private List<PaperDto> papers = new ArrayList<>(); private List<Paper> papers = new ArrayList<>();
public GrantDto() { public GrantDto() {
deadlines.add(new Deadline()); deadlines.add(new Deadline());
@ -54,7 +54,7 @@ public class GrantDto {
@JsonProperty("hasAge") boolean hasAge, @JsonProperty("hasAge") boolean hasAge,
@JsonProperty("hasDegree") boolean hasDegree, @JsonProperty("hasDegree") boolean hasDegree,
@JsonProperty("paperIds") List<Integer> paperIds, @JsonProperty("paperIds") List<Integer> paperIds,
@JsonProperty("papers") List<PaperDto> papers) { @JsonProperty("papers") List<Paper> papers) {
this.id = id; this.id = id;
this.title = title; this.title = title;
this.status = status; this.status = status;
@ -86,7 +86,7 @@ public class GrantDto {
this.hasAge = false; this.hasAge = false;
this.hasDegree = false; this.hasDegree = false;
this.paperIds = convert(grant.getPapers(), paper -> paper.getId()); this.paperIds = convert(grant.getPapers(), paper -> paper.getId());
this.papers = convert(grant.getPapers(), PaperDto::new); this.papers = grant.getPapers();
} }
public Integer getId() { public Integer getId() {
@ -208,11 +208,11 @@ public class GrantDto {
this.paperIds = paperIds; this.paperIds = paperIds;
} }
public List<PaperDto> getPapers() { public List<Paper> getPapers() {
return papers; return papers;
} }
public void setPapers(List<PaperDto> papers) { public void setPapers(List<Paper> papers) {
this.papers = papers; this.papers = papers;
} }
} }

View File

@ -92,9 +92,8 @@ public class GrantService {
grant.setLeader(userService.findById(grantDto.getLeaderId())); grant.setLeader(userService.findById(grantDto.getLeaderId()));
} }
grant.getPapers().clear(); grant.getPapers().clear();
if (grantDto.getPaperIds() != null && !grantDto.getAuthorIds().isEmpty()) { if (grantDto.getPaperIds() != null && !grantDto.getPaperIds().isEmpty()) {
grantDto.getPaperIds().forEach(paperIds -> grantDto.getPaperIds().forEach(paperIds -> grant.getPapers().add(paperService.findEntityById(paperIds)));
grant.getPapers().add(paperService.findEntityById(paperIds)));
} }
return grant; return grant;
} }
@ -168,7 +167,12 @@ public class GrantService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public List<Paper> getGrantPapers() { public List<Paper> getGrantPapers(List<Integer> paperIds) {
return paperService.findAllSelect(paperIds);
}
public List<Paper> getAllPapers() {
return paperService.findAll(); return paperService.findAll();
} }

View File

@ -14,4 +14,6 @@ public interface PaperRepository extends JpaRepository<Paper, Integer> {
List<Paper> filter(@Param("author") User author, @Param("year") Integer year); List<Paper> filter(@Param("author") User author, @Param("year") Integer year);
List<Paper> findByIdNotIn(List<Integer> paperIds); List<Paper> findByIdNotIn(List<Integer> paperIds);
List<Paper> findAllByIdIn(List<Integer> paperIds);
} }

View File

@ -229,6 +229,10 @@ public class PaperService {
} }
public List<Paper> findAllSelect(List<Integer> paperIds) {
return sortPapers(paperRepository.findAllByIdIn(paperIds));
}
public List<User> getPaperAuthors() { public List<User> getPaperAuthors() {
return userService.findAll(); return userService.findAll();
} }

View File

@ -146,7 +146,7 @@
<label>Участники гранта:</label> <label>Участники гранта:</label>
<select class="selectpicker form-control" multiple="true" data-live-search="true" <select class="selectpicker form-control" multiple="true" data-live-search="true"
title="-- Выберите участников --" id="authors" title="-- Выберите участников --" id="authors"
th:field="*{authorIds}"> th:field="*{authorIds}" data-size="5">
<option th:each="author : ${allAuthors}" th:value="${author.id}" <option th:each="author : ${allAuthors}" th:value="${author.id}"
th:text="${author.lastName}"> Участник th:text="${author.lastName}"> Участник
</option> </option>
@ -154,16 +154,47 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Список статей:</label> <label>Список статей:</label>
<select class="selectpicker form-control" multiple="true" data-live-search="true" <div class="row">
title="Прикрепить статью" data-style="btn-primary" id="papers" <div class="col-8">
th:field="*{paperIds}"> <select class="selectpicker form-control" multiple="true"
data-live-search="true"
title="Прикрепить статью" id="allPapers"
th:field="*{paperIds}" data-size="5">
<option th:each="paper : ${allPapers}" th:value="${paper.id}" <option th:each="paper : ${allPapers}" th:value="${paper.id}"
th:text="${paper.title}"> Статья th:text="${paper.title}">Статья для прикрепления
</option> </option>
</select> </select>
<!-- <p><a href="./#" class="btn btn-primary"><i class="fa fa-plus-circle" </div>
aria-hidden="true"> <div class="col-4">
</i> Добавить статью</a></p> --> <a th:onclick="|$('#attachPaper').click();|">
<span aria-hidden="true">
<label>Отобразить</label>
</span>
</a>
</div>
<input type="submit" hidden="hidden" id="attachPaper" name="attachPaper"
value="Отобразить прикрепленную статью"/>
</div>
<div class="row">
<input th:type="hidden" th:field="*{papers}"/>
<div class="form-control list-group">
<div th:each="paper, rowStat : *{papers}">
<div class="col">
<a th:href="@{'/papers/paper?id=' + *{papers[__${rowStat.index}__].id} + ''}">
<span th:text="*{papers[__${rowStat.index}__].title}">
Название статьи
</span>
</a>
</div>
<div class="col">
<label>Статус: </label>
<span th:text="*{papers[__${rowStat.index}__].status.statusName}">
Статус статьи
</span>
</div>
</div>
</div>
</div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div th:if="*{project} == null"> <div th:if="*{project} == null">
@ -219,6 +250,22 @@
$("#authors [value='" + lid + "']").attr("disabled", "disabled"); $("#authors [value='" + lid + "']").attr("disabled", "disabled");
} }
</script> </script>
<script>
function viewdiv(id) {
var el = document.getElementById(id);
var link = document.getElementById('toggleLink');
if (el.style.display == "block") {
el.style.display = "none";
link.innerText = link.getAttribute('data-text-hide');
} else {
el.style.display = "block";
link.innerText = link.getAttribute('data-text-show');
}
}
</script>
</div> </div>
</body> </body>
</html> </html>