#13 rename 'deleted', move creating fileDto to service
This commit is contained in:
parent
c702e2abb4
commit
5da9de1bab
@ -53,9 +53,6 @@ public class FileController {
|
||||
|
||||
@PostMapping("/uploadTmpFile")
|
||||
public Response<FileDataDto> upload(@RequestParam("file") MultipartFile multipartFile) throws IOException {
|
||||
FileDataDto fileDataDto = new FileDataDto();
|
||||
fileDataDto.setFileName(multipartFile.getOriginalFilename());
|
||||
fileDataDto.setTmpFileName(fileService.uploadToTmpDir(multipartFile));
|
||||
return new Response(fileDataDto);
|
||||
return new Response(fileService.createFromMultipartFile(multipartFile));
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ public class FileDataDto {
|
||||
private String fileName;
|
||||
private String tmpFileName;
|
||||
|
||||
private boolean deleteFlag;
|
||||
private boolean deleted;
|
||||
|
||||
public FileDataDto() {
|
||||
}
|
||||
@ -30,6 +30,10 @@ public class FileDataDto {
|
||||
this.name = fileData.getName();
|
||||
}
|
||||
|
||||
public FileDataDto(String fileName, String tmpFileName) {
|
||||
this.fileName = fileName;
|
||||
this.tmpFileName = tmpFileName;
|
||||
}
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
@ -62,12 +66,12 @@ public class FileDataDto {
|
||||
this.tmpFileName = tmpFileName;
|
||||
}
|
||||
|
||||
public boolean isDeleteFlag() {
|
||||
return deleteFlag;
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleteFlag(boolean deleteFlag) {
|
||||
this.deleteFlag = deleteFlag;
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -119,4 +119,8 @@ public class FileService {
|
||||
FileData file = fileRepository.findOne(fileId);
|
||||
fileRepository.delete(file);
|
||||
}
|
||||
|
||||
public FileDataDto createFromMultipartFile(MultipartFile multipartFile) throws IOException {
|
||||
return new FileDataDto(multipartFile.getOriginalFilename(), uploadToTmpDir(multipartFile));
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public class PaperService {
|
||||
paper.setTitle(paperDto.getTitle());
|
||||
paper.setUpdateDate(new Date());
|
||||
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
||||
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream().filter(f -> f.isDeleteFlag() == false).collect(Collectors.toList())));
|
||||
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream().filter(f -> !f.isDeleted()).collect(Collectors.toList())));
|
||||
paper.getAuthors().clear();
|
||||
if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) {
|
||||
paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds)));
|
||||
@ -104,7 +104,7 @@ public class PaperService {
|
||||
Paper.PaperStatus oldStatus = paper.getStatus();
|
||||
Set<User> oldAuthors = new HashSet<>(paper.getAuthors());
|
||||
|
||||
for (FileDataDto file : paperDto.getFiles().stream().filter(f -> f.isDeleteFlag() == true && f.getId() != null).collect(Collectors.toList())) {
|
||||
for (FileDataDto file : paperDto.getFiles().stream().filter(f -> f.isDeleted() && f.getId() != null).collect(Collectors.toList())) {
|
||||
fileService.delete(file.getId());
|
||||
}
|
||||
|
||||
|
@ -96,14 +96,14 @@
|
||||
<label>Файлы:</label>
|
||||
<th:block th:each="file, rowStat : *{files}">
|
||||
<div class="row" th:id="|files${rowStat.index}|"
|
||||
th:style="${file.deleteFlag} ? 'display: none;' :''">
|
||||
th:style="${file.deleted} ? 'display: none;' :''">
|
||||
<input type="hidden" th:field="*{files[__${rowStat.index}__].id}"/>
|
||||
<input type="hidden" th:field="*{files[__${rowStat.index}__].deleteFlag}"/>
|
||||
<input type="hidden" th:field="*{files[__${rowStat.index}__].deleted}"/>
|
||||
<input type="hidden" th:field="*{files[__${rowStat.index}__].name}"/>
|
||||
<input type="hidden" th:field="*{files[__${rowStat.index}__].tmpFileName}"/>
|
||||
<div class="col-2">
|
||||
<a class="btn btn-danger float-right"
|
||||
th:onclick="|$('#files${rowStat.index}\\.deleteFlag').val('true'); $('#files${rowStat.index}').hide(); |">
|
||||
th:onclick="|$('#files${rowStat.index}\\.deleted').val('true'); $('#files${rowStat.index}').hide(); |">
|
||||
<span aria-hidden="true"><i class="fa fa-times"/></span>
|
||||
</a>
|
||||
</div>
|
||||
@ -222,9 +222,9 @@
|
||||
|
||||
var flagInput = $("<input/>")
|
||||
.attr("type", "hidden")
|
||||
.attr("id", "files" + fileNumber + ".deleteFlag")
|
||||
.attr("id", "files" + fileNumber + ".deleted")
|
||||
.attr("value", "false")
|
||||
.attr("name", "files[" + fileNumber + "].deleteFlag");
|
||||
.attr("name", "files[" + fileNumber + "].deleted");
|
||||
newFileRow.append(flagInput);
|
||||
|
||||
var nameInput = $("<input/>")
|
||||
@ -246,7 +246,7 @@
|
||||
|
||||
var nextA = $("<a/>")
|
||||
.addClass("btn btn-danger float-right")
|
||||
.attr("onclick", "$('#files" + fileNumber + "\\\\.deleteFlag').val('true'); $('#files" + fileNumber + "').hide();")
|
||||
.attr("onclick", "$('#files" + fileNumber + "\\\\.deleted').val('true'); $('#files" + fileNumber + "').hide();")
|
||||
.append(($("<span/>").attr("aria-hidden", "true")).append($("<i/>").addClass("fa fa-times")))
|
||||
;
|
||||
nextDiv.append(nextA)
|
||||
|
Loading…
Reference in New Issue
Block a user