#107 add view of the selected papers

This commit is contained in:
T-Midnight 2019-04-23 13:21:13 +04:00
parent eec739a49f
commit d3b8be2cf1
6 changed files with 94 additions and 24 deletions

View File

@ -51,7 +51,9 @@ public class GrantController {
@GetMapping("/grant")
public void getGrant(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
if (id != null && id > 0) {
modelMap.put("grantDto", grantService.findOneDto(id));
GrantDto grantDto = grantService.findOneDto(id);
attachPaper(grantDto);
modelMap.put("grantDto", grantDto);
} else {
modelMap.put("grantDto", new GrantDto());
}
@ -79,6 +81,17 @@ public class GrantController {
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")
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
filterEmptyDeadlines(grantDto);
@ -115,8 +128,8 @@ public class GrantController {
}
@ModelAttribute("allPapers")
public List<Paper> getGrantPapers() {
return grantService.getGrantPapers();
public List<Paper> getAllPapers() {
return grantService.getAllPapers();
}
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.hibernate.validator.constraints.NotEmpty;
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.user.model.UserDto;
@ -34,7 +34,7 @@ public class GrantDto {
private boolean hasAge;
private boolean hasDegree;
private List<Integer> paperIds = new ArrayList<>();
private List<PaperDto> papers = new ArrayList<>();
private List<Paper> papers = new ArrayList<>();
public GrantDto() {
deadlines.add(new Deadline());
@ -54,7 +54,7 @@ public class GrantDto {
@JsonProperty("hasAge") boolean hasAge,
@JsonProperty("hasDegree") boolean hasDegree,
@JsonProperty("paperIds") List<Integer> paperIds,
@JsonProperty("papers") List<PaperDto> papers) {
@JsonProperty("papers") List<Paper> papers) {
this.id = id;
this.title = title;
this.status = status;
@ -86,7 +86,7 @@ public class GrantDto {
this.hasAge = false;
this.hasDegree = false;
this.paperIds = convert(grant.getPapers(), paper -> paper.getId());
this.papers = convert(grant.getPapers(), PaperDto::new);
this.papers = grant.getPapers();
}
public Integer getId() {
@ -208,11 +208,11 @@ public class GrantDto {
this.paperIds = paperIds;
}
public List<PaperDto> getPapers() {
public List<Paper> getPapers() {
return papers;
}
public void setPapers(List<PaperDto> papers) {
public void setPapers(List<Paper> papers) {
this.papers = papers;
}
}

View File

@ -92,9 +92,8 @@ public class GrantService {
grant.setLeader(userService.findById(grantDto.getLeaderId()));
}
grant.getPapers().clear();
if (grantDto.getPaperIds() != null && !grantDto.getAuthorIds().isEmpty()) {
grantDto.getPaperIds().forEach(paperIds ->
grant.getPapers().add(paperService.findEntityById(paperIds)));
if (grantDto.getPaperIds() != null && !grantDto.getPaperIds().isEmpty()) {
grantDto.getPaperIds().forEach(paperIds -> grant.getPapers().add(paperService.findEntityById(paperIds)));
}
return grant;
}
@ -168,7 +167,12 @@ public class GrantService {
.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();
}

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> 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() {
return userService.findAll();
}

View File

@ -146,7 +146,7 @@
<label>Участники гранта:</label>
<select class="selectpicker form-control" multiple="true" data-live-search="true"
title="-- Выберите участников --" id="authors"
th:field="*{authorIds}">
th:field="*{authorIds}" data-size="5">
<option th:each="author : ${allAuthors}" th:value="${author.id}"
th:text="${author.lastName}"> Участник
</option>
@ -154,16 +154,47 @@
</div>
<div class="form-group">
<label>Список статей:</label>
<select class="selectpicker form-control" multiple="true" data-live-search="true"
title="Прикрепить статью" data-style="btn-primary" id="papers"
th:field="*{paperIds}">
<option th:each="paper : ${allPapers}" th:value="${paper.id}"
th:text="${paper.title}"> Статья
</option>
</select>
<!-- <p><a href="./#" class="btn btn-primary"><i class="fa fa-plus-circle"
aria-hidden="true">
</i> Добавить статью</a></p> -->
<div class="row">
<div class="col-8">
<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}"
th:text="${paper.title}">Статья для прикрепления
</option>
</select>
</div>
<div class="col-4">
<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 class="form-group">
<div th:if="*{project} == null">
@ -219,6 +250,22 @@
$("#authors [value='" + lid + "']").attr("disabled", "disabled");
}
</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>
</body>
</html>