#13 file list on paper page
This commit is contained in:
parent
0764d961fa
commit
cb394edf90
@ -9,12 +9,13 @@ public class FileDataDto {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private long size;
|
||||
|
||||
private Date createDate;
|
||||
private byte[] data;
|
||||
private String fileName;
|
||||
private String tmpFileName;
|
||||
|
||||
private boolean deleteFlag;
|
||||
|
||||
public FileDataDto() {
|
||||
}
|
||||
|
||||
@ -99,4 +100,12 @@ public class FileDataDto {
|
||||
this.tmpFileName = tmpFileName;
|
||||
}
|
||||
|
||||
public boolean isDeleteFlag() {
|
||||
return deleteFlag;
|
||||
}
|
||||
|
||||
public void setDeleteFlag(boolean deleteFlag) {
|
||||
this.deleteFlag = deleteFlag;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -110,4 +110,10 @@ public class FileService {
|
||||
fileData.setSize(fileDataDto.getSize());
|
||||
return fileData;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void delete(Integer fileId) throws IOException {
|
||||
FileData file = fileRepository.findOne(fileId);
|
||||
fileRepository.delete(file);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.deadline.service.DeadlineService;
|
||||
import ru.ulstu.file.model.FileDataDto;
|
||||
import ru.ulstu.file.service.FileService;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.paper.model.PaperDto;
|
||||
@ -80,7 +81,7 @@ public class PaperService {
|
||||
paper.setTitle(paperDto.getTitle());
|
||||
paper.setUpdateDate(new Date());
|
||||
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
||||
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles()));
|
||||
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream().filter(f -> f.isDeleteFlag() == false).collect(Collectors.toList())));
|
||||
paper.getAuthors().clear();
|
||||
if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) {
|
||||
paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds)));
|
||||
@ -93,6 +94,11 @@ public class PaperService {
|
||||
Paper paper = paperRepository.findOne(paperDto.getId());
|
||||
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())) {
|
||||
fileService.delete(file.getId());
|
||||
}
|
||||
|
||||
paperRepository.save(copyFromDto(paper, paperDto));
|
||||
|
||||
paper.getAuthors().forEach(author -> {
|
||||
|
@ -8,16 +8,5 @@
|
||||
<column name="paper_id" type="integer"/>
|
||||
</addColumn>
|
||||
|
||||
<createTable tableName="paper_files">
|
||||
<column name="paper_id" type="integer"/>
|
||||
<column name="file_id" type="integer"/>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseTableName="paper_files" baseColumnNames="paper_id"
|
||||
constraintName="fk_paper_paper_files" referencedTableName="paper"
|
||||
referencedColumnNames="id"/>
|
||||
<addForeignKeyConstraint baseTableName="paper_files" baseColumnNames="file_id"
|
||||
constraintName="fk_file_paper_files" referencedTableName="file"
|
||||
referencedColumnNames="id"/>
|
||||
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
|
@ -91,6 +91,28 @@
|
||||
<p th:if="${#fields.hasErrors('authorIds')}" th:errors="*{authorIds}"
|
||||
class="alert alert-danger">Incorrect title</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Файлы:</label>
|
||||
<th:block th:each="file, rowStat : *{files}">
|
||||
<div class="row" th:id="|files${rowStat.index}|"
|
||||
th:style="${file.deleteFlag} ? '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}__].name}"/>
|
||||
<div class="col-2">
|
||||
<a class="btn btn-danger float-right"
|
||||
th:onclick="|$('#files${rowStat.index}\\.deleteFlag').val('true'); $('#files${rowStat.index}').hide(); |">
|
||||
<span aria-hidden="true"><i class="fa fa-times"/></span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-10">
|
||||
<div th:text="*{files[__${rowStat.index}__].name}"></div>
|
||||
</div>
|
||||
</div>
|
||||
</th:block>
|
||||
</div>
|
||||
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" id="locked"
|
||||
th:field="*{locked}"/>
|
||||
|
Loading…
Reference in New Issue
Block a user