Merge branch '115-follow-up-from-resolve' into 'dev'

Resolve "Follow-up from "Resolve "Прикрепление статей к гранту"""

Closes #115

See merge request romanov73/ng-tracker!73
This commit is contained in:
Anton Romanov 2019-04-23 19:17:17 +00:00
commit 3aea19088d
11 changed files with 188 additions and 10 deletions

View File

@ -13,6 +13,7 @@ import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.grant.model.Grant;
import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.grant.service.GrantService;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.user.model.User;
import springfox.documentation.annotations.ApiIgnore;
@ -50,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());
}
@ -78,6 +81,12 @@ public class GrantController {
return GRANT_PAGE;
}
@PostMapping(value = "/grant", params = "attachPaper")
public String attachPaper(GrantDto grantDto) {
grantService.attachPaper(grantDto);
return GRANT_PAGE;
}
@PostMapping(value = "/grant", params = "addDeadline")
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
filterEmptyDeadlines(grantDto);
@ -113,6 +122,11 @@ public class GrantController {
return grantService.getGrantAuthors(grantDto);
}
@ModelAttribute("allPapers")
public List<Paper> getAllPapers() {
return grantService.getAllPapers();
}
private void filterEmptyDeadlines(GrantDto grantDto) {
grantDto.setDeadlines(grantDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))

View File

@ -5,6 +5,7 @@ import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.core.model.UserContainer;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileData;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.project.model.Project;
import ru.ulstu.user.model.User;
@ -14,6 +15,7 @@ import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
@ -83,6 +85,12 @@ public class Grant extends BaseEntity implements UserContainer {
@JoinColumn(name = "leader_id")
private User leader;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "grants_papers",
joinColumns = {@JoinColumn(name = "grant_id")},
inverseJoinColumns = {@JoinColumn(name = "paper_id")})
private List<Paper> papers = new ArrayList<>();
public GrantStatus getStatus() {
return status;
}
@ -152,6 +160,14 @@ public class Grant extends BaseEntity implements UserContainer {
this.leader = leader;
}
public List<Paper> getPapers() {
return papers;
}
public void setPapers(List<Paper> papers) {
this.papers = papers;
}
public Optional<Deadline> getNextDeadline() {
return deadlines
.stream()

View File

@ -5,6 +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.Paper;
import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.user.model.UserDto;
@ -32,6 +33,8 @@ public class GrantDto {
private boolean wasLeader;
private boolean hasAge;
private boolean hasDegree;
private List<Integer> paperIds = new ArrayList<>();
private List<Paper> papers = new ArrayList<>();
public GrantDto() {
deadlines.add(new Deadline());
@ -49,7 +52,9 @@ public class GrantDto {
@JsonProperty("leader") Integer leaderId,
@JsonProperty("wasLeader") boolean wasLeader,
@JsonProperty("hasAge") boolean hasAge,
@JsonProperty("hasDegree") boolean hasDegree) {
@JsonProperty("hasDegree") boolean hasDegree,
@JsonProperty("paperIds") List<Integer> paperIds,
@JsonProperty("papers") List<Paper> papers) {
this.id = id;
this.title = title;
this.status = status;
@ -62,6 +67,8 @@ public class GrantDto {
this.wasLeader = wasLeader;
this.hasAge = hasAge;
this.hasDegree = hasDegree;
this.paperIds = paperIds;
this.papers = papers;
}
public GrantDto(Grant grant) {
@ -78,6 +85,8 @@ public class GrantDto {
this.wasLeader = false;
this.hasAge = false;
this.hasDegree = false;
this.paperIds = convert(grant.getPapers(), paper -> paper.getId());
this.papers = grant.getPapers();
}
public Integer getId() {
@ -190,4 +199,20 @@ public class GrantDto {
public void setHasDegree(boolean hasDegree) {
this.hasDegree = hasDegree;
}
public List<Integer> getPaperIds() {
return paperIds;
}
public void setPaperIds(List<Integer> paperIds) {
this.paperIds = paperIds;
}
public List<Paper> getPapers() {
return papers;
}
public void setPapers(List<Paper> papers) {
this.papers = papers;
}
}

View File

@ -9,6 +9,8 @@ import ru.ulstu.file.service.FileService;
import ru.ulstu.grant.model.Grant;
import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.grant.repository.GrantRepository;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.service.PaperService;
import ru.ulstu.project.model.Project;
import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.project.service.ProjectService;
@ -34,17 +36,20 @@ public class GrantService {
private final DeadlineService deadlineService;
private final FileService fileService;
private final UserService userService;
private final PaperService paperService;
public GrantService(GrantRepository grantRepository,
FileService fileService,
DeadlineService deadlineService,
ProjectService projectService,
UserService userService) {
UserService userService,
PaperService paperService) {
this.grantRepository = grantRepository;
this.fileService = fileService;
this.deadlineService = deadlineService;
this.projectService = projectService;
this.userService = userService;
this.paperService = paperService;
}
public List<Grant> findAll() {
@ -86,6 +91,10 @@ public class GrantService {
if (grantDto.getLeaderId() != null) {
grant.setLeader(userService.findById(grantDto.getLeaderId()));
}
grant.getPapers().clear();
if (grantDto.getPaperIds() != null && !grantDto.getPaperIds().isEmpty()) {
grantDto.getPaperIds().forEach(paperIds -> grant.getPapers().add(paperService.findEntityById(paperIds)));
}
return grant;
}
@ -118,7 +127,7 @@ public class GrantService {
}
@Transactional
public Grant create(String title, Project projectId, Date deadlineDate, User user) {
public Grant create(String title, Project projectId, Date deadlineDate, User user, Paper paper) {
Grant grant = new Grant();
grant.setTitle(title);
grant.setComment("Комментарий к гранту 1");
@ -127,6 +136,7 @@ public class GrantService {
grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн"));
grant.getAuthors().add(user);
grant.setLeader(user);
grant.getPapers().add(paper);
grant = grantRepository.save(grant);
return grant;
}
@ -156,4 +166,22 @@ public class GrantService {
.map(Grant::getLeader)
.collect(Collectors.toList());
}
public List<Paper> getGrantPapers(List<Integer> paperIds) {
return paperService.findAllSelect(paperIds);
}
public List<Paper> getAllPapers() {
return paperService.findAll();
}
public void attachPaper(GrantDto grantDto) {
if (!grantDto.getPaperIds().isEmpty()) {
grantDto.getPapers().clear();
grantDto.setPapers(getGrantPapers(grantDto.getPaperIds()));
} else {
grantDto.getPapers().clear();
}
}
}

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

@ -236,6 +236,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

@ -0,0 +1,17 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet author="tanya" id="20190419_000000-1">
<createTable tableName="grants_papers">
<column name="grant_id" type="integer"/>
<column name="paper_id" type="integer"/>
</createTable>
<addForeignKeyConstraint baseTableName="grants_papers" baseColumnNames="grant_id"
constraintName="fk_grants_grants_papers" referencedTableName="grants"
referencedColumnNames="id"/>
<addForeignKeyConstraint baseTableName="grants_papers" baseColumnNames="paper_id"
constraintName="fk_paper_grants_papers" referencedTableName="paper"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>

View File

@ -30,6 +30,7 @@
<include file="db/common/changelog-20190312_130000-schema.xml"/>
<include file="db/changelog-20190402_000000-schema.xml"/>
<include file="db/changelog-20190404_000000-schema.xml"/>
<include file="db/changelog-20190419_000000-schema.xml"/>
<include file="db/changelog-20190421_000000-schema.xml"/>
<include file="db/changelog-20190422_000000-schema.xml"/>
</databaseChangeLog>

View File

@ -10,3 +10,18 @@
padding-left: 5px;
padding-right: 5px;
}
.div-view-paper {
margin-top: 6px;
}
.div-selected-papers {
border: 0px;
padding-left: 12px;
}
.icon-paper {
height: 22px;
width: 22px;
margin: 3px;
}

View File

@ -144,9 +144,9 @@
</div>
<div class="form-group">
<label>Участники гранта:</label>
<select class="selectpicker form-control" multiple="true"
<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,9 +154,48 @@
</div>
<div class="form-group">
<label>Список статей:</label>
<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 div-view-paper">
<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-selected-papers" id="selected-papers">
<div th:each="paper, rowStat : *{papers}">
<div class="col">
<a th:href="@{'/papers/paper?id=' + *{papers[__${rowStat.index}__].id} + ''}">
<img class="icon-paper" src="/img/conference/paper.png"/>
<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">
@ -213,6 +252,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>

View File

@ -8,7 +8,8 @@
<div th:fragment="filesList (isLatexAttach)" th:remove="tag">
<th:block th:each="file, rowStat : *{files}">
<span th:if="${(!isLatexAttach and file.isLatexAttach == null) or file.isLatexAttach == isLatexAttach}" th:remove="tag">
<span th:if="${(!isLatexAttach and file.isLatexAttach == null) or file.isLatexAttach == isLatexAttach}"
th:remove="tag">
<div class="row" th:id="|files${rowStat.index}|"
th:style="${file.deleted} ? 'display: none;' :''">