Merge branch '66-attach-exist-article' into 'dev'
Resolve "Прикрепление статьи" Closes #66 See merge request romanov73/ng-tracker!54
This commit is contained in:
commit
0c719d8886
@ -13,10 +13,13 @@ import ru.ulstu.conference.model.ConferenceDto;
|
||||
import ru.ulstu.conference.model.ConferenceFilterDto;
|
||||
import ru.ulstu.conference.service.ConferenceService;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.springframework.util.StringUtils.isEmpty;
|
||||
@ -44,9 +47,13 @@ public class ConferenceController {
|
||||
@GetMapping("/conference")
|
||||
public void getConference(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
||||
if (id != null && id > 0) {
|
||||
modelMap.put("conferenceDto", conferenceService.findOneDto(id));
|
||||
ConferenceDto conferenceDto = conferenceService.findOneDto(id);
|
||||
conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds()));
|
||||
modelMap.put("conferenceDto", conferenceDto);
|
||||
} else {
|
||||
modelMap.put("conferenceDto", new ConferenceDto());
|
||||
ConferenceDto conferenceDto = new ConferenceDto();
|
||||
conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList<Integer>()));
|
||||
modelMap.put("conferenceDto", conferenceDto);
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,6 +94,10 @@ public class ConferenceController {
|
||||
return CONFERENCE_PAGE;
|
||||
}
|
||||
|
||||
public List<Paper> getNotSelectPapers(List<Integer> paperIds) {
|
||||
return conferenceService.getConferencePapers(paperIds);
|
||||
}
|
||||
|
||||
private void filterEmptyDeadlines(ConferenceDto conferenceDto) {
|
||||
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
|
||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
||||
|
@ -60,7 +60,7 @@ public class Conference extends BaseEntity {
|
||||
@JoinTable(name = "paper_conference",
|
||||
joinColumns = {@JoinColumn(name = "conference_id")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "paper_id")})
|
||||
private Set<Paper> papers = new HashSet<>();
|
||||
private List<Paper> papers = new ArrayList<>();
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "users_conference",
|
||||
@ -124,11 +124,11 @@ public class Conference extends BaseEntity {
|
||||
this.deadlines = deadlines;
|
||||
}
|
||||
|
||||
public Set<Paper> getPapers() {
|
||||
public List<Paper> getPapers() {
|
||||
return papers;
|
||||
}
|
||||
|
||||
public void setPapers(Set<Paper> papers) {
|
||||
public void setPapers(List<Paper> papers) {
|
||||
this.papers = papers;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.paper.model.PaperDto;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.user.model.UserDto;
|
||||
|
||||
import javax.persistence.Temporal;
|
||||
@ -39,8 +39,11 @@ public class ConferenceDto {
|
||||
private List<Deadline> deadlines = new ArrayList<>();
|
||||
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
||||
private Set<Integer> userIds = new HashSet<>();
|
||||
private Set<Integer> paperIds = new HashSet<>();
|
||||
private Set<PaperDto> papers = new HashSet<>();
|
||||
private List<Integer> paperIds = new ArrayList<>();
|
||||
private List<Paper> papers = new ArrayList<>();
|
||||
|
||||
|
||||
private List<Paper> notSelectedPapers = new ArrayList<>();
|
||||
private Set<UserDto> users = new HashSet<>();
|
||||
private Integer filterUserId;
|
||||
|
||||
@ -57,9 +60,10 @@ public class ConferenceDto {
|
||||
@JsonProperty("endDate") Date endDate,
|
||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
||||
@JsonProperty("userIds") Set<Integer> userIds,
|
||||
@JsonProperty("paperIds") Set<Integer> paperIds,
|
||||
@JsonProperty("paperIds") List<Integer> paperIds,
|
||||
@JsonProperty("users") Set<UserDto> users,
|
||||
@JsonProperty("papers") Set<PaperDto> papers) {
|
||||
@JsonProperty("papers") List<Paper> papers,
|
||||
@JsonProperty("notSelectedPapers") List<Paper> notSelectedPapers) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
@ -72,6 +76,7 @@ public class ConferenceDto {
|
||||
this.paperIds = paperIds;
|
||||
this.users = users;
|
||||
this.papers = papers;
|
||||
this.notSelectedPapers = notSelectedPapers;
|
||||
}
|
||||
|
||||
public ConferenceDto(Conference conference) {
|
||||
@ -86,7 +91,7 @@ public class ConferenceDto {
|
||||
this.userIds = convert(conference.getUsers(), user -> user.getId());
|
||||
this.paperIds = convert(conference.getPapers(), paper -> paper.getId());
|
||||
this.users = convert(conference.getUsers(), UserDto::new);
|
||||
this.papers = convert(conference.getPapers(), PaperDto::new);
|
||||
this.papers = conference.getPapers();
|
||||
|
||||
}
|
||||
|
||||
@ -162,19 +167,19 @@ public class ConferenceDto {
|
||||
this.userIds = userIds;
|
||||
}
|
||||
|
||||
public Set<Integer> getPaperIds() {
|
||||
public List<Integer> getPaperIds() {
|
||||
return paperIds;
|
||||
}
|
||||
|
||||
public void setPaperIds(Set<Integer> paperIds) {
|
||||
public void setPaperIds(List<Integer> paperIds) {
|
||||
this.paperIds = paperIds;
|
||||
}
|
||||
|
||||
public Set<PaperDto> getPapers() {
|
||||
public List<Paper> getPapers() {
|
||||
return papers;
|
||||
}
|
||||
|
||||
public void setPapers(Set<PaperDto> papers) {
|
||||
public void setPapers(List<Paper> papers) {
|
||||
this.papers = papers;
|
||||
}
|
||||
|
||||
@ -202,4 +207,12 @@ public class ConferenceDto {
|
||||
this.removedDeadlineIds = removedDeadlineIds;
|
||||
}
|
||||
|
||||
public List<Paper> getNotSelectedPapers() {
|
||||
return notSelectedPapers;
|
||||
}
|
||||
|
||||
public void setNotSelectedPapers(List<Paper> notSelectedPapers) {
|
||||
this.notSelectedPapers = notSelectedPapers;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import ru.ulstu.conference.model.Conference;
|
||||
import ru.ulstu.conference.model.ConferenceDto;
|
||||
import ru.ulstu.conference.repository.ConferenceRepository;
|
||||
import ru.ulstu.deadline.service.DeadlineService;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.paper.service.PaperService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@ -20,11 +22,14 @@ public class ConferenceService {
|
||||
|
||||
private final ConferenceRepository conferenceRepository;
|
||||
private final DeadlineService deadlineService;
|
||||
private final PaperService paperService;
|
||||
|
||||
public ConferenceService(ConferenceRepository conferenceRepository,
|
||||
DeadlineService deadlineService) {
|
||||
DeadlineService deadlineService,
|
||||
PaperService paperService) {
|
||||
this.conferenceRepository = conferenceRepository;
|
||||
this.deadlineService = deadlineService;
|
||||
this.paperService = paperService;
|
||||
}
|
||||
|
||||
public List<Conference> findAll() {
|
||||
@ -78,6 +83,10 @@ public class ConferenceService {
|
||||
conferenceDto.getDeadlines().remove((int) deadlineIndex);
|
||||
}
|
||||
|
||||
public List<Paper> getConferencePapers(List<Integer> paperIds) {
|
||||
return paperService.findAllNotSelect(paperIds);
|
||||
}
|
||||
|
||||
private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException {
|
||||
conference.setTitle(conferenceDto.getTitle());
|
||||
conference.setDescription(conferenceDto.getDescription());
|
||||
@ -86,6 +95,10 @@ public class ConferenceService {
|
||||
conference.setBeginDate(conferenceDto.getBeginDate());
|
||||
conference.setEndDate(conferenceDto.getEndDate());
|
||||
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines()));
|
||||
if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) {
|
||||
conferenceDto.getPaperIds().forEach(paperId ->
|
||||
conference.getPapers().add(paperService.findEntityById(paperId)));
|
||||
}
|
||||
return conference;
|
||||
}
|
||||
|
||||
|
@ -12,4 +12,6 @@ public interface PaperRepository extends JpaRepository<Paper, Integer> {
|
||||
|
||||
@Query("SELECT p FROM Paper p WHERE (:author IS NULL OR :author MEMBER OF p.authors) AND (YEAR(p.createDate) = :year OR :year IS NULL)")
|
||||
List<Paper> filter(@Param("author") User author, @Param("year") Integer year);
|
||||
|
||||
List<Paper> findByIdNotIn(List<Integer> paperIds);
|
||||
}
|
||||
|
@ -215,6 +215,19 @@ public class PaperService {
|
||||
return new PaperDto(paperRepository.findOne(paperId));
|
||||
}
|
||||
|
||||
public Paper findEntityById(Integer paperId) {
|
||||
return paperRepository.findOne(paperId);
|
||||
}
|
||||
|
||||
public List<Paper> findAllNotSelect(List<Integer> paperIds) {
|
||||
if (!paperIds.isEmpty()) {
|
||||
return sortPapers(paperRepository.findByIdNotIn(paperIds));
|
||||
} else {
|
||||
return sortPapers(paperRepository.findAll());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<User> getPaperAuthors() {
|
||||
return userService.findAll();
|
||||
}
|
||||
|
@ -7,6 +7,10 @@ body {
|
||||
border-radius: .25rem;
|
||||
}
|
||||
|
||||
.filter-option-inner-inner {
|
||||
color: white;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -49,6 +53,8 @@ body {
|
||||
|
||||
.paper {
|
||||
margin: 0;
|
||||
min-height: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.paper-name {
|
||||
@ -104,13 +110,14 @@ body {
|
||||
float: right;
|
||||
}
|
||||
|
||||
@media (max-width: 1199px) {
|
||||
@media (max-width: 1199px) and (min-width: 768px){
|
||||
.paper-control {
|
||||
display: block!important;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 991px) {
|
||||
|
||||
.dates-panel {
|
||||
display: block!important;
|
||||
}
|
||||
|
@ -62,7 +62,6 @@
|
||||
<input type="submit" class="icon icon-delete grey-border"
|
||||
alt="Удалить" name="removeDeadline" th:value="${rowStat.index}"
|
||||
/>
|
||||
<!--th:onclick="|$(this).parent().remove();|"-->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -136,23 +135,30 @@
|
||||
<div class="form-group">
|
||||
<label for="papers">Статьи:</label>
|
||||
<div class="paper-list form-control list-group" id="papers">
|
||||
<div class="paper d-flex list-group-item p-0">
|
||||
<a class="paper-name" href="/papers/papers">
|
||||
<span>
|
||||
<input th:type="hidden" th:field="*{papers}"/>
|
||||
<div class="paper d-flex list-group-item p-0"
|
||||
th:each="paper, rowStat : *{papers}">
|
||||
<a class="paper-name"
|
||||
th:href="@{'/papers/paper?id=' + *{papers[__${rowStat.index}__].id} + ''}">
|
||||
<span th:text="*{papers[__${rowStat.index}__].title}">
|
||||
Имя статьи
|
||||
</span>
|
||||
<img class="icon-paper" src="/img/conference/paper.png"/>
|
||||
</a>
|
||||
<img class="icon grey-border icon-delete" src="/img/conference/delete.png"
|
||||
alt="Удалить"/>
|
||||
<input type="submit" class="icon icon-delete grey-border"
|
||||
alt="Удалить"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paper-control form-group d-flex justify-content-end">
|
||||
<button id="attach-paper" class="btn btn-primary"
|
||||
type="button">
|
||||
Прикрепить статью
|
||||
</button>
|
||||
<input th:type="hidden" th:field="*{notSelectedPapers}"/>
|
||||
<select class="selectpicker form-control" multiple="true" data-live-search="true"
|
||||
title="Прикрепить статью" data-style="btn-primary" data-size="5"
|
||||
th:field="*{paperIds}">
|
||||
<option th:each="paper: *{notSelectedPapers}" th:value="${paper.id}"
|
||||
th:text="${paper.title}">Status
|
||||
</option>
|
||||
</select>
|
||||
<button id="add-paper" class="btn btn-primary"
|
||||
type="button">
|
||||
Добавить статью
|
||||
|
Loading…
Reference in New Issue
Block a user