fix saving paper
This commit is contained in:
parent
b99a5e9f06
commit
a9fb97bd2e
@ -27,6 +27,7 @@ import ru.ulstu.user.service.UserService;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -131,9 +132,11 @@ public class PaperService {
|
|||||||
paper.setUpdateDate(new Date());
|
paper.setUpdateDate(new Date());
|
||||||
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
||||||
paper.setReferences(saveOrCreateReferences(paperDto.getReferences()));
|
paper.setReferences(saveOrCreateReferences(paperDto.getReferences()));
|
||||||
|
if (paperDto.getFiles() != null) {
|
||||||
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream()
|
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream()
|
||||||
.filter(f -> !f.isDeleted())
|
.filter(f -> !f.isDeleted())
|
||||||
.collect(toList())));
|
.collect(toList())));
|
||||||
|
}
|
||||||
paper.getAuthors().clear();
|
paper.getAuthors().clear();
|
||||||
if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) {
|
if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) {
|
||||||
paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds)));
|
paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds)));
|
||||||
@ -142,7 +145,9 @@ public class PaperService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<Reference> saveOrCreateReferences(List<ReferenceDto> references) {
|
private List<Reference> saveOrCreateReferences(List<ReferenceDto> references) {
|
||||||
return references
|
return references == null
|
||||||
|
? Collections.emptyList()
|
||||||
|
: references
|
||||||
.stream()
|
.stream()
|
||||||
.filter(reference -> !reference.getDeleted())
|
.filter(reference -> !reference.getDeleted())
|
||||||
.map(reference -> reference.getId() != null ? updateReference(reference) : createReference(reference))
|
.map(reference -> reference.getId() != null ? updateReference(reference) : createReference(reference))
|
||||||
@ -182,17 +187,21 @@ public class PaperService {
|
|||||||
Paper.PaperStatus oldStatus = paper.getStatus();
|
Paper.PaperStatus oldStatus = paper.getStatus();
|
||||||
Set<User> oldAuthors = new HashSet<>(paper.getAuthors());
|
Set<User> oldAuthors = new HashSet<>(paper.getAuthors());
|
||||||
|
|
||||||
|
if (paperDto.getFiles() != null) {
|
||||||
for (FileDataDto file : paperDto.getFiles().stream()
|
for (FileDataDto file : paperDto.getFiles().stream()
|
||||||
.filter(f -> f.isDeleted() && f.getId() != null)
|
.filter(f -> f.isDeleted() && f.getId() != null)
|
||||||
.collect(toList())) {
|
.collect(toList())) {
|
||||||
fileService.delete(file.getId());
|
fileService.delete(file.getId());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
paperRepository.save(copyFromDto(paper, paperDto));
|
paperRepository.save(copyFromDto(paper, paperDto));
|
||||||
|
if (paperDto.getReferences() != null) {
|
||||||
for (ReferenceDto referenceDto : paperDto.getReferences().stream()
|
for (ReferenceDto referenceDto : paperDto.getReferences().stream()
|
||||||
.filter(f -> f.getDeleted() && f.getId() != null)
|
.filter(f -> f.getDeleted() && f.getId() != null)
|
||||||
.collect(toList())) {
|
.collect(toList())) {
|
||||||
referenceRepository.deleteById(referenceDto.getId());
|
referenceRepository.deleteById(referenceDto.getId());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
eventService.updatePaperDeadlines(paper);
|
eventService.updatePaperDeadlines(paper);
|
||||||
|
|
||||||
paper.getAuthors().forEach(author -> {
|
paper.getAuthors().forEach(author -> {
|
||||||
|
@ -56,8 +56,22 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function axiosPut(url, data, resolv, reject) {
|
||||||
|
axios.put(url, JSON.stringify(data), axiosConfig)
|
||||||
|
.then(function (result) {
|
||||||
|
errorHandler(result, resolv, reject);
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
setTimeout(function () {
|
||||||
|
throw Error(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
get: axiosGet,
|
get: axiosGet,
|
||||||
post: axiosPost
|
post: axiosPost,
|
||||||
|
put: axiosPut
|
||||||
};
|
};
|
||||||
});
|
});
|
@ -9,8 +9,7 @@
|
|||||||
<hr/>
|
<hr/>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<form name="paperform" id="paper-form" method="post"
|
<form @submit.prevent="savePaper">
|
||||||
action="/papers/paper">
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-7 col-sm-12">
|
<div class="col-md-7 col-sm-12">
|
||||||
<nav>
|
<nav>
|
||||||
@ -28,7 +27,8 @@
|
|||||||
aria-labelledby="nav-main-tab">
|
aria-labelledby="nav-main-tab">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="title">Название:</label>
|
<label for="title">Название:</label>
|
||||||
<input class="form-control" id="title" type="text" :value="paper.title"
|
<input class="form-control" id="title" type="text"
|
||||||
|
:value="paper.title"
|
||||||
placeholder="Название статьи"/>
|
placeholder="Название статьи"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@ -149,6 +149,15 @@
|
|||||||
if (date) {
|
if (date) {
|
||||||
return moment(String(new Date(date))).format('DD.MM.YYYY hh:mm')
|
return moment(String(new Date(date))).format('DD.MM.YYYY hh:mm')
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
savePaper: function (event) {
|
||||||
|
if (this.$route.query.id && Number.isInteger(parseInt(this.$route.query.id)) && parseInt(this.$route.query.id) != 0) {
|
||||||
|
axiosEx.put(appConfig.paper, this.paper);
|
||||||
|
} else {
|
||||||
|
axiosEx.post(appConfig.paper, this.paper);
|
||||||
|
}
|
||||||
|
this.$store.dispatch("addSuccessMessage", "Статья успешно сохранена!");
|
||||||
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user