From 10a99d42cfb940fd2052496dd9924a5b6fa73bc9 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 17 Feb 2020 00:02:58 +0400 Subject: [PATCH] add delete papers button --- .../ru/ulstu/paper/controller/PapersView.java | 15 +++++++++++++++ .../java/ru/ulstu/paper/service/PaperService.java | 4 ++++ .../META-INF/resources/paper/papers.xhtml | 5 +++++ 3 files changed, 24 insertions(+) diff --git a/src/main/java/ru/ulstu/paper/controller/PapersView.java b/src/main/java/ru/ulstu/paper/controller/PapersView.java index eca8714..49c2c81 100644 --- a/src/main/java/ru/ulstu/paper/controller/PapersView.java +++ b/src/main/java/ru/ulstu/paper/controller/PapersView.java @@ -8,6 +8,7 @@ import javax.annotation.PostConstruct; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -19,6 +20,8 @@ public class PapersView { private List papers; + private List selectedPapers = new ArrayList<>(); + private String newPaperTitle; @PostConstruct @@ -33,6 +36,10 @@ public class PapersView { papers = paperService.findAll(); } + public void deleteSelected() { + paperService.delete(selectedPapers); + } + public List getPaperStatuses() { return Arrays.asList(Paper.PaperStatus.values()); } @@ -48,4 +55,12 @@ public class PapersView { public void setNewPaperTitle(String newPaperTitle) { this.newPaperTitle = newPaperTitle; } + + public List getSelectedPapers() { + return selectedPapers; + } + + public void setSelectedPapers(List selectedPapers) { + this.selectedPapers = selectedPapers; + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 885bc21..2d83b51 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -437,4 +437,8 @@ public class PaperService { paper.getDeadlines().add(deadlineService.createWithOffset(new Date(), 1, ChronoUnit.WEEKS)); create(paper); } + + public void delete(List papers) { + paperRepository.deleteInBatch(papers); + } } diff --git a/src/main/resources/META-INF/resources/paper/papers.xhtml b/src/main/resources/META-INF/resources/paper/papers.xhtml index a282043..66e1049 100644 --- a/src/main/resources/META-INF/resources/paper/papers.xhtml +++ b/src/main/resources/META-INF/resources/paper/papers.xhtml @@ -40,6 +40,11 @@ +
+ +