remove papers

This commit is contained in:
Anton Romanov 2020-02-17 10:22:26 +04:00
parent 1f5cde4b66
commit 1460e26127
5 changed files with 23 additions and 7 deletions

View File

@ -67,4 +67,8 @@ public class DeadlineService {
public Deadline createWithOffset(Date date, long value, ChronoUnit chronoUnit) { public Deadline createWithOffset(Date date, long value, ChronoUnit chronoUnit) {
return create(DateUtils.localDateToDate(DateUtils.convertToLocalDate(date).plus(value, chronoUnit))); return create(DateUtils.localDateToDate(DateUtils.convertToLocalDate(date).plus(value, chronoUnit)));
} }
public void delete(List<Deadline> deadlines) {
deadlineRepository.deleteInBatch(deadlines);
}
} }

View File

@ -38,6 +38,7 @@ public class PapersView {
public void deleteSelected() { public void deleteSelected() {
paperService.delete(selectedPapers); paperService.delete(selectedPapers);
papers = paperService.findAll();
} }
public List<Paper.PaperStatus> getPaperStatuses() { public List<Paper.PaperStatus> getPaperStatuses() {

View File

@ -99,7 +99,7 @@ public class Paper extends BaseEntity implements UserActivity, EventSource {
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Date updateDate = new Date(); private Date updateDate = new Date();
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
@JoinColumn(name = "paper_id", unique = true) @JoinColumn(name = "paper_id", unique = true)
@Fetch(FetchMode.SUBSELECT) @Fetch(FetchMode.SUBSELECT)
@OrderBy("date") @OrderBy("date")

View File

@ -233,8 +233,7 @@ public class PaperService {
@Transactional @Transactional
public void delete(Integer paperId) { public void delete(Integer paperId) {
Paper paper = paperRepository.getOne(paperId); delete(paperRepository.getOne(paperId));
paperRepository.delete(paper);
} }
public List<Paper.PaperStatus> getPaperStatuses() { public List<Paper.PaperStatus> getPaperStatuses() {
@ -439,6 +438,11 @@ public class PaperService {
} }
public void delete(List<Paper> papers) { public void delete(List<Paper> papers) {
paperRepository.deleteInBatch(papers); papers.forEach(paper -> delete(paper));
}
public void delete(Paper paper) {
deadlineService.delete(paper.getDeadlines());
paperRepository.delete(paper);
} }
} }

View File

@ -11,7 +11,8 @@
} }
</style> </style>
<p:dataTable value="#{papersView.papers}" var="paper" paginator="true" rows="10" id="papersTable" <p:dataTable value="#{papersView.papers}" var="paper" paginator="true" rows="10" id="papersTable"
widgetVar="papersTable" emptyMessage="Не найдено подходящих статей"> widgetVar="papersTable" emptyMessage="Не найдено подходящих статей"
selection="#{papersView.selectedPapers}" rowKey="#{paper.id}">
<f:facet name="header"> <f:facet name="header">
<p:outputPanel> <p:outputPanel>
<h:outputText value="Поиск:"/> <h:outputText value="Поиск:"/>
@ -19,6 +20,11 @@
placeholder="Строка поиска..."/> placeholder="Строка поиска..."/>
</p:outputPanel> </p:outputPanel>
</f:facet> </f:facet>
<p:ajax event="rowSelect" update="mainForm:papersRemoveButton" process="@form"/>
<p:ajax event="rowSelectCheckbox" update="mainForm:papersRemoveButton" process="@form"/>
<p:ajax event="rowUnselectCheckbox" update="mainForm:papersRemoveButton" process="@form"/>
<p:ajax event="rowUnselect" update="mainForm:papersRemoveButton" process="@form"/>
<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
<p:column headerText="Название" filterBy="#{paper.title}" filterMatchMode="contains"> <p:column headerText="Название" filterBy="#{paper.title}" filterMatchMode="contains">
<h:outputLink value="/paper/paper.xhtml"> <h:outputLink value="/paper/paper.xhtml">
#{paper.title} #{paper.title}
@ -41,9 +47,10 @@
</p:column> </p:column>
</p:dataTable> </p:dataTable>
<div class="ui-g-3"> <div class="ui-g-3">
<p:commandButton value="Удалить выделенные" disabled="#{papersView.selectedPapers.isEmpty()}" <p:commandButton value="Удалить выделенные" id="papersRemoveButton"
disabled="#{papersView.selectedPapers.isEmpty()}"
action="#{papersView.deleteSelected}" ajax="true" process="@form" action="#{papersView.deleteSelected}" ajax="true" process="@form"
update="messages @form mainForm:papersTable"/> update="messages @form"/>
</div> </div>
<p:inputText placeholder="Создать новую статью" value="#{papersView.newPaperTitle}"/> <p:inputText placeholder="Создать новую статью" value="#{papersView.newPaperTitle}"/>
<p:commandButton action="#{papersView.create}" value="Сохранить" ajax="true" process="@form" <p:commandButton action="#{papersView.create}" value="Сохранить" ajax="true" process="@form"