show authors

pull/149/head
Anton Romanov 6 years ago
parent c88ce3ac37
commit dc5abe1508

@ -37,6 +37,11 @@ public class PaperController {
modelMap.put("papers", paperService.findAllDto()); modelMap.put("papers", paperService.findAllDto());
} }
@GetMapping("/dashboard")
public void getDashboard(ModelMap modelMap) {
modelMap.put("papers", paperService.findAllDto());
}
@GetMapping("/paper") @GetMapping("/paper")
public void getPapers(ModelMap modelMap, @RequestParam(value = "id") Integer id) { public void getPapers(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
if (id != null && id > 0) { if (id != null && id > 0) {

@ -4,12 +4,14 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.NotEmpty; import org.hibernate.validator.constraints.NotEmpty;
import ru.ulstu.deadline.model.DeadlineDto; import ru.ulstu.deadline.model.DeadlineDto;
import ru.ulstu.user.model.UserDto;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.core.util.StreamApiUtils.convert;
@ -29,7 +31,8 @@ public class PaperDto {
private Integer fileId; private Integer fileId;
private String fileName; private String fileName;
private Date fileCreateDate; private Date fileCreateDate;
private Set<Integer> authors; private Set<Integer> authorIds;
private Set<UserDto> authors;
public PaperDto() { public PaperDto() {
deadlines.add(new DeadlineDto()); deadlines.add(new DeadlineDto());
@ -45,7 +48,8 @@ public class PaperDto {
@JsonProperty("comment") String comment, @JsonProperty("comment") String comment,
@JsonProperty("locked") Boolean locked, @JsonProperty("locked") Boolean locked,
@JsonProperty("tmpFileName") String tmpFileName, @JsonProperty("tmpFileName") String tmpFileName,
@JsonProperty("authors") Set<Integer> authors) { @JsonProperty("authorIds") Set<Integer> authorIds,
@JsonProperty("authors") Set<UserDto> authors) {
this.id = id; this.id = id;
this.title = title; this.title = title;
this.status = status; this.status = status;
@ -74,110 +78,126 @@ public class PaperDto {
this.fileId = paper.getFileData() == null ? null : paper.getFileData().getId(); this.fileId = paper.getFileData() == null ? null : paper.getFileData().getId();
this.fileName = paper.getFileData() == null ? null : paper.getFileData().getName(); this.fileName = paper.getFileData() == null ? null : paper.getFileData().getName();
this.fileCreateDate = paper.getFileData() == null ? null : paper.getFileData().getCreateDate(); this.fileCreateDate = paper.getFileData() == null ? null : paper.getFileData().getCreateDate();
this.authors = convert(paper.getAuthors(), user -> user.getId()); this.authorIds = convert(paper.getAuthors(), user -> user.getId());
this.authors = convert(paper.getAuthors(), UserDto::new);
} }
public Integer getId() { public Integer getId() {
return id; return id;
} }
public void setId(Integer id) {
this.id = id;
}
public String getTitle() { public String getTitle() {
return title; return title;
} }
public void setTitle(String title) {
this.title = title;
}
public Paper.PaperStatus getStatus() { public Paper.PaperStatus getStatus() {
return status; return status;
} }
public void setStatus(Paper.PaperStatus status) {
this.status = status;
}
public Date getCreateDate() { public Date getCreateDate() {
return createDate; return createDate;
} }
public Date getUpdateDate() { public void setCreateDate(Date createDate) {
return updateDate; this.createDate = createDate;
} }
public List<DeadlineDto> getDeadlines() { public Date getUpdateDate() {
return deadlines; return updateDate;
} }
public String getComment() { public void setUpdateDate(Date updateDate) {
return comment; this.updateDate = updateDate;
} }
public Boolean getLocked() { public List<DeadlineDto> getDeadlines() {
return locked; return deadlines;
} }
public String getTmpFileName() { public void setDeadlines(List<DeadlineDto> deadlines) {
return tmpFileName; this.deadlines = deadlines;
} }
public Integer getFileId() { public String getComment() {
return fileId; return comment;
} }
public String getFileName() { public void setComment(String comment) {
return fileName; this.comment = comment;
} }
public Date getFileCreateDate() { public Boolean getLocked() {
return fileCreateDate; return locked;
} }
public Set<Integer> getAuthors() { public void setLocked(Boolean locked) {
return authors; this.locked = locked;
} }
public void setId(Integer id) { public String getTmpFileName() {
this.id = id; return tmpFileName;
} }
public void setTitle(String title) { public void setTmpFileName(String tmpFileName) {
this.title = title; this.tmpFileName = tmpFileName;
} }
public void setStatus(Paper.PaperStatus status) { public Integer getFileId() {
this.status = status; return fileId;
} }
public void setCreateDate(Date createDate) { public void setFileId(Integer fileId) {
this.createDate = createDate; this.fileId = fileId;
} }
public void setUpdateDate(Date updateDate) { public String getFileName() {
this.updateDate = updateDate; return fileName;
} }
public void setComment(String comment) { public void setFileName(String fileName) {
this.comment = comment; this.fileName = fileName;
} }
public void setLocked(Boolean locked) { public Date getFileCreateDate() {
this.locked = locked; return fileCreateDate;
} }
public void setTmpFileName(String tmpFileName) { public void setFileCreateDate(Date fileCreateDate) {
this.tmpFileName = tmpFileName; this.fileCreateDate = fileCreateDate;
} }
public void setFileId(Integer fileId) { public Set<UserDto> getAuthors() {
this.fileId = fileId; return authors;
} }
public void setFileName(String fileName) { public void setAuthors(Set<UserDto> authors) {
this.fileName = fileName; this.authors = authors;
} }
public void setFileCreateDate(Date fileCreateDate) { public Set<Integer> getAuthorIds() {
this.fileCreateDate = fileCreateDate; return authorIds;
} }
public void setAuthors(Set<Integer> authors) { public void setAuthorIds(Set<Integer> authorIds) {
this.authors = authors; this.authorIds = authorIds;
} }
public void setDeadlines(List<DeadlineDto> deadlines) { public String getAuthorsString() {
this.deadlines = deadlines; return authors
.stream()
.map(author -> author.getLastName())
.collect(Collectors.joining(", "));
} }
} }

@ -83,8 +83,8 @@ public class PaperService {
if (paperDto.getTmpFileName() != null) { if (paperDto.getTmpFileName() != null) {
paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName())); paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName()));
} }
if (paperDto.getAuthors() != null && !paperDto.getAuthors().isEmpty()) { if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) {
paperDto.getAuthors().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds))); paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds)));
} else { } else {
paper.getAuthors().clear(); paper.getAuthors().clear();
} }

@ -13,10 +13,11 @@
<div class="col-lg-12 text-center"> <div class="col-lg-12 text-center">
<h2 class="section-heading text-uppercase">Статьи</h2> <h2 class="section-heading text-uppercase">Статьи</h2>
<div th:replace="papers/fragments/paperNavigationFragment"/> <div th:replace="papers/fragments/paperNavigationFragment"/>
</div> </div>
<div class="row justify-content-center" id="dashboard"> <div class="row justify-content-center" id="dashboard">
<th:block th:each="paper : ${papers}">
<div th:replace="papers/fragments/paperDashboardFragment :: titleLine(paper=${paper})"/>
</th:block>
</div> </div>
</div> </div>
</section> </section>

@ -0,0 +1,43 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head th:fragment="headerfiles">
<meta charset="UTF-8"/>
</head>
<body>
<div th:fragment="titleLine (paper)" class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
<div class="row">
<div class="col-2">
<span class="fa-stack fa-1x">
<th:block th:switch="${paper.status.name()}">
<div th:case="'ATTENTION'">
<i class="fa fa-circle fa-stack-2x text-warning"></i>
</div>
<div th:case="'DRAFT'">
<i class="fa fa-circle fa-stack-2x text-draft"></i>
</div>
<div th:case="'ON_PREPARATION'">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
</div>
<div th:case="'ON_REVIEW'">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
</div>
<div th:case="'COMPLETED'">
<i class="fa fa-circle fa-stack-2x text-success"></i>
</div>
<div th:case="'FAILED'">
<i class="fa fa-circle fa-stack-2x text-failed"></i>
</div>
</th:block>
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
</span>
</div>
<div class="col col-10 text-right">
<h7 class="service-heading" th:text="${paper.title}"> title</h7>
<p class="text-muted" th:text="${paper.authorsString}">authors</p>
</div>
</div>
</div>
</body>
</html>

@ -29,7 +29,10 @@
</th:block> </th:block>
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i> <i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
</span> </span>
<a th:href="@{'paper?id='+${paper.id}}"><span th:text="${paper.title}"></span></a> <a th:href="@{'paper?id='+${paper.id}}">
<span class="h6" th:text="${paper.title}"/>
<span class="text-muted" th:text="${paper.authorsString}"/>
</a>
<input class="id-class" type="hidden" th:value="${paper.id}"/> <input class="id-class" type="hidden" th:value="${paper.id}"/>
<a class="remove-paper pull-right d-none" th:href="@{'/papers/delete/'+${paper.id}}" <a class="remove-paper pull-right d-none" th:href="@{'/papers/delete/'+${paper.id}}"
data-confirm="Удалить статью?"> data-confirm="Удалить статью?">

@ -101,12 +101,12 @@
<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="-- Выберите авторов --" title="-- Выберите авторов --"
th:field="*{authors}"> th:field="*{authorIds}">
<option th:each="author: ${allAuthors}" th:value="${author.id}" <option th:each="author: ${allAuthors}" th:value="${author.id}"
th:text="${author.firstName}">Status th:text="${author.lastName}">Status
</option> </option>
</select> </select>
<p th:if="${#fields.hasErrors('authors')}" th:errors="*{authors}" <p th:if="${#fields.hasErrors('authorIds')}" th:errors="*{authorIds}"
class="alert alert-danger">Incorrect title</p> class="alert alert-danger">Incorrect title</p>
</div> </div>
</div> </div>

Loading…
Cancel
Save