save authors
This commit is contained in:
parent
1f264331fa
commit
35a08ab451
@ -116,6 +116,7 @@ dependencies {
|
||||
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
|
||||
|
||||
compile group: 'org.webjars', name: 'bootstrap', version: '4.1.0'
|
||||
compile group: 'org.webjars', name: 'bootstrap-select', version: '1.13.3'
|
||||
compile group: 'org.webjars', name: 'jquery', version: '3.3.1-1'
|
||||
compile group: 'org.webjars.npm', name: 'jquery.easing', version: '1.4.1'
|
||||
compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0'
|
||||
|
@ -15,6 +15,7 @@ import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.paper.model.PaperDto;
|
||||
import ru.ulstu.paper.model.PaperFilterDto;
|
||||
import ru.ulstu.paper.service.PaperService;
|
||||
import ru.ulstu.user.model.User;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
@ -64,6 +65,11 @@ public class PaperController {
|
||||
return paperService.getPaperStatuses();
|
||||
}
|
||||
|
||||
@ModelAttribute("allAuthors")
|
||||
public List<User> getAllAuthors() {
|
||||
return paperService.getPaperAuthors();
|
||||
}
|
||||
|
||||
@PostMapping("/filter")
|
||||
public Response<List<PaperDto>> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException {
|
||||
return new Response<>(paperService.filter(paperFilterDto));
|
||||
|
@ -30,7 +30,7 @@ public class PaperDto {
|
||||
private Integer fileId;
|
||||
private String fileName;
|
||||
private Date fileCreateDate;
|
||||
private Set<UserDto> authors;
|
||||
private Set<Integer> authors;
|
||||
|
||||
public PaperDto() {
|
||||
}
|
||||
@ -48,7 +48,7 @@ public class PaperDto {
|
||||
this.fileId = paper.getFileData() == null ? null : paper.getFileData().getId();
|
||||
this.fileName = paper.getFileData() == null ? null : paper.getFileData().getName();
|
||||
this.fileCreateDate = paper.getFileData() == null ? null : paper.getFileData().getCreateDate();
|
||||
this.authors = convert(paper.getAuthors(), UserDto::new);
|
||||
this.authors = convert(paper.getAuthors(), user -> user.getId());
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
@ -99,7 +99,7 @@ public class PaperDto {
|
||||
return fileCreateDate;
|
||||
}
|
||||
|
||||
public Set<UserDto> getAuthors() {
|
||||
public Set<Integer> getAuthors() {
|
||||
return authors;
|
||||
}
|
||||
|
||||
@ -151,14 +151,7 @@ public class PaperDto {
|
||||
this.fileCreateDate = fileCreateDate;
|
||||
}
|
||||
|
||||
public void setAuthors(Set<UserDto> authors) {
|
||||
public void setAuthors(Set<Integer> authors) {
|
||||
this.authors = authors;
|
||||
}
|
||||
|
||||
public String getAuthorsString() {
|
||||
return authors
|
||||
.stream()
|
||||
.map(author -> author.getLastName() + author.getFirstName())
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,9 @@ public class PaperService {
|
||||
paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName()));
|
||||
}
|
||||
if (paperDto.getAuthors() != null && !paperDto.getAuthors().isEmpty()) {
|
||||
paperDto.getAuthors().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds.getId())));
|
||||
paperDto.getAuthors().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds)));
|
||||
} else {
|
||||
paper.getAuthors().clear();
|
||||
}
|
||||
return paper;
|
||||
}
|
||||
@ -162,4 +164,8 @@ public class PaperService {
|
||||
public PaperDto findById(Integer paperId) {
|
||||
return new PaperDto(paperRepository.findOne(paperId));
|
||||
}
|
||||
|
||||
public List<User> getPaperAuthors() {
|
||||
return userService.findAll();
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<link rel="stylesheet" href="/webjars/bootstrap/4.1.0/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" href="/webjars/bootstrap-select/1.13.3/css/bootstrap-select.min.css"/>
|
||||
<link rel="stylesheet" href="/webjars/font-awesome/4.7.0/css/font-awesome.min.css"/>
|
||||
|
||||
<!-- Custom fonts for this template -->
|
||||
@ -25,6 +26,7 @@
|
||||
<!-- Bootstrap core JavaScript -->
|
||||
<script src="/webjars/jquery/3.3.1-1/jquery.min.js"></script>
|
||||
<script src="/webjars/bootstrap/4.1.0/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="/webjars/bootstrap-select/1.13.3/js/bootstrap-select.min.js"></script>
|
||||
|
||||
<!-- Plugin JavaScript -->
|
||||
<script src="/webjars/jquery.easing/1.4.1/jquery.easing.js"></script>
|
||||
|
@ -82,17 +82,26 @@
|
||||
<label>Последнее изменение:</label>
|
||||
<span th:text="${paperDto.updateDate == null ? '' : #dates.format(paperDto.updateDate, 'dd.MM.yyyy HH:mm')}">text</span>
|
||||
</div>
|
||||
<p><a href="#myModal1" class="btn btn-primary" data-toggle="modal">Редактировать
|
||||
авторов
|
||||
статьи</a></p>
|
||||
<div class="form-group">
|
||||
<label>Редактировать авторов статьи:</label>
|
||||
<select class="selectpicker form-control" multiple="true" data-live-search="true"
|
||||
title="-- Выберите авторов --"
|
||||
th:field="*{authors}">
|
||||
<option th:each="author: ${allAuthors}" th:value="${author.id}"
|
||||
th:text="${author.firstName}">Status
|
||||
</option>
|
||||
</select>
|
||||
<p th:if="${#fields.hasErrors('authors')}" th:errors="*{authors}"
|
||||
class="alert alert-danger">Incorrect title</p>
|
||||
</div>
|
||||
<div id="myModal1" class="modal fade">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">Авторы статьи</h4>
|
||||
<button type="button" class="close" data-dismiss="modal"
|
||||
aria-hidden="true">×
|
||||
</button>
|
||||
<h4 class="modal-title">Авторы статьи</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<table class="table">
|
||||
@ -110,7 +119,10 @@
|
||||
<td>Иванович</td>
|
||||
<td>
|
||||
<span class="table-remove"><button type="button"
|
||||
class="btn btn-danger btn-rounded btn-sm my-0">Remove</button></span>
|
||||
class="btn btn-danger btn-rounded btn-sm my-0">
|
||||
<i class="fa fa-times"/>
|
||||
</button>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -118,8 +130,12 @@
|
||||
<td>text</td>
|
||||
<td>text</td>
|
||||
<td>
|
||||
<span class="table-remove"><button type="button"
|
||||
class="btn btn-danger btn-rounded btn-sm my-0">Remove</button></span>
|
||||
<span class="table-remove">
|
||||
<button type="button"
|
||||
class="btn btn-danger btn-rounded btn-sm my-0">
|
||||
<i class="fa fa-times"/>
|
||||
</button>
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<div class="dropdown">
|
||||
@ -193,6 +209,7 @@
|
||||
console.debug(response);
|
||||
}
|
||||
});
|
||||
$('.selectpicker').selectpicker();
|
||||
});
|
||||
/*]]>*/
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user