complete dashboard

This commit is contained in:
Anton Romanov 2020-04-25 18:45:12 +04:00
parent 708a1a6d32
commit 2cc3008dc5
2 changed files with 127 additions and 13 deletions

View File

@ -1,12 +1,16 @@
package ru.ulstu.paper.controller;
import ru.ulstu.core.util.FacesUtil;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.service.PaperService;
import ru.ulstu.user.service.UserService;
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;
@Named
@ -15,8 +19,15 @@ public class DashboardView {
@Inject
private PaperService paperService;
@Inject
private UserService userService;
private List<Paper> papers;
private List<Paper> selectedPapers = new ArrayList<>();
private String newPaperTitle;
@PostConstruct
public void init() {
papers = paperService.findAllActiveByCurrentUser();
@ -25,4 +36,41 @@ public class DashboardView {
public List<Paper> getPapers() {
return papers;
}
public void create() {
paperService.createByTitle(newPaperTitle);
FacesUtil.showInfoMessage("Статья создана", newPaperTitle);
newPaperTitle = "";
papers = paperService.findAllActiveByCurrentUser();
}
public void deleteSelected() {
paperService.delete(selectedPapers);
papers = paperService.findAllActiveByCurrentUser();
FacesUtil.showInfoMessage("Было удалено статей: " + selectedPapers.size(), "");
}
public List<Paper.PaperStatus> getPaperStatuses() {
return Arrays.asList(Paper.PaperStatus.values());
}
public String getNewPaperTitle() {
return newPaperTitle;
}
public void setNewPaperTitle(String newPaperTitle) {
this.newPaperTitle = newPaperTitle;
}
public List<Paper> getSelectedPapers() {
return selectedPapers;
}
public void setSelectedPapers(List<Paper> selectedPapers) {
this.selectedPapers = selectedPapers;
}
public String getCurrentUser() {
return userService.getCurrentUser().getUserAbbreviate();
}
}

View File

@ -5,19 +5,85 @@
xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:composition template="/basicTemplate.xhtml">
<ui:define name="content">
<p:dataTable value="#{dashboardView.papers}" var="paper" paginator="true" rows="10">
<p:column headerText="Название">
<h:outputLink value="/paper/paper.xhtml">
#{paper.title}
<f:param name="id" value="#{paper.id}"/>
</h:outputLink>
</p:column>
<p:column headerText="Статус">
<ui:include src="paperStatusFragment.xhtml">
<ui:param name="paper" value="#{paper}"/>
</ui:include>
</p:column>
</p:dataTable>
<style>
.ui-datatable .ui-datatable-header {
text-align: right !important;
}
</style>
<p:panel id="panel" header="Активные статьи пользователя #{dashboardView.currentUser}"
style="margin-bottom:10px;">
<div class="ui-fluid">
<div class="ui-g">
<div class="ui-md-5 ui-g-12">
<p:inputText placeholder="Создать новую статью" id="newPaperName"
value="#{dashboardView.newPaperTitle}" required="true"
requiredMessage="Введите название новой статьи"/>
<p:message for="newPaperName"/>
</div>
<div class="ui-md-2 ui-g-12">
<p:commandButton action="#{dashboardView.create}" value="Создать" ajax="true" process="@form"
update="messages @form mainForm:papersTable"/>
</div>
<div class="ui-md-3 ui-g-12">
<p:commandButton value="Удалить выделенные" id="papersRemoveButton"
disabled="#{dashboardView.selectedPapers.isEmpty()}"
action="#{dashboardView.deleteSelected}" ajax="true"
process="mainForm:papersRemoveButton"
update="messages mainForm:papersTable">
<p:confirm header="Подтверждение" message="Удалить выделенные статьи?"
icon="pi pi-exclamation-triangle"/>
</p:commandButton>
</div>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="Да" type="button" styleClass="ui-confirmdialog-yes" icon="pi pi-check"/>
<p:commandButton value="Нет" type="button" styleClass="ui-confirmdialog-no" icon="pi pi-times"/>
</p:confirmDialog>
</div>
<p:dataTable value="#{dashboardView.papers}" var="paper" paginator="true" paginatorPosition="bottom"
rows="10" id="papersTable"
widgetVar="papersTable" emptyMessage="Не найдено подходящих статей"
selection="#{dashboardView.selectedPapers}" rowKey="#{paper.id}">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Поиск:"/>
<p:inputText id="globalFilter" onkeyup="PF('papersTable').filter()" style="width:150px"
placeholder="Строка поиска..."/>
</p:outputPanel>
</f:facet>
<p:ajax event="rowSelect" update="mainForm:papersRemoveButton" process="mainForm:papersTable"/>
<p:ajax event="rowSelectCheckbox" update="mainForm:papersRemoveButton"
process="mainForm:papersTable"/>
<p:ajax event="rowUnselectCheckbox" update="mainForm:papersRemoveButton"
process="mainForm:papersTable"/>
<p:ajax event="rowUnselect" update="mainForm:papersRemoveButton" process="mainForm:papersTable"/>
<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
<p:column headerText="Название" filterBy="#{paper.title}" filterMatchMode="contains">
<h:outputLink value="/paper/paper.xhtml">
#{paper.title}
<f:param name="id" value="#{paper.id}"/>
</h:outputLink>
</p:column>
<p:column headerText="Статус" filterBy="#{paper.status} #{paper.status.statusName}"
filterMatchMode="contains">
<f:facet name="filter">
<p:selectOneMenu onchange="PF('papersTable').filter()" styleClass="custom-filter"
converter="paperStatusConverter">
<f:selectItem itemLabel="Статус" itemValue="#{null}" noSelectionOption="true"/>
<f:selectItems value="#{dashboardView.paperStatuses}" var="status"
itemLabel="#{status.statusName}"
itemValue="#{status}"/>
</p:selectOneMenu>
</f:facet>
<ui:include src="paperStatusFragment.xhtml">
<ui:param name="paper" value="#{paper}"/>
</ui:include>
</p:column>
</p:dataTable>
</div>
</p:panel>
</ui:define>
</ui:composition>
</html>