add delete papers button

This commit is contained in:
Anton Romanov 2020-02-17 00:02:58 +04:00
parent 90c11c6946
commit 10a99d42cf
3 changed files with 24 additions and 0 deletions

View File

@ -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<Paper> papers;
private List<Paper> 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<Paper.PaperStatus> getPaperStatuses() {
return Arrays.asList(Paper.PaperStatus.values());
}
@ -48,4 +55,12 @@ public class PapersView {
public void setNewPaperTitle(String newPaperTitle) {
this.newPaperTitle = newPaperTitle;
}
public List<Paper> getSelectedPapers() {
return selectedPapers;
}
public void setSelectedPapers(List<Paper> selectedPapers) {
this.selectedPapers = selectedPapers;
}
}

View File

@ -437,4 +437,8 @@ public class PaperService {
paper.getDeadlines().add(deadlineService.createWithOffset(new Date(), 1, ChronoUnit.WEEKS));
create(paper);
}
public void delete(List<Paper> papers) {
paperRepository.deleteInBatch(papers);
}
}

View File

@ -40,6 +40,11 @@
</ui:include>
</p:column>
</p:dataTable>
<div class="ui-g-3">
<p:commandButton value="Удалить выделенные" disabled="#{papersView.selectedPapers.isEmpty()}"
action="#{papersView.deleteSelected}" ajax="true" process="@form"
update="messages @form mainForm:papersTable"/>
</div>
<p:inputText placeholder="Создать новую статью" value="#{papersView.newPaperTitle}"/>
<p:commandButton action="#{papersView.create}" value="Сохранить" ajax="true" process="@form"
update="messages @form mainForm:papersTable" style="visibility: hidden"/>