add papers dashboard

This commit is contained in:
Anton Romanov 2019-11-26 22:34:24 +04:00
parent 107ddb90ac
commit 5ee1f33de1
3 changed files with 59 additions and 1 deletions

View File

@ -0,0 +1,28 @@
package ru.ulstu.paper.controller;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.service.PaperService;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;
@Named
@ViewScoped
public class DashboardView {
@Inject
private PaperService paperService;
private List<Paper> papers;
@PostConstruct
public void init() {
papers = paperService.findAllActiveByCurrentUser();
}
public List<Paper> getPapers() {
return papers;
}
}

View File

@ -85,13 +85,20 @@ public class PaperService {
return papers; return papers;
} }
private List<Paper> findAllActive() { public List<Paper> findAllActive() {
return findAll() return findAll()
.stream() .stream()
.filter(paper -> paper.getStatus() != COMPLETED && paper.getStatus() != FAILED) .filter(paper -> paper.getStatus() != COMPLETED && paper.getStatus() != FAILED)
.collect(toList()); .collect(toList());
} }
public List<Paper> findAllActiveByCurrentUser() {
return findAllActive()
.stream()
.filter(paper -> paper.getAuthors().contains(userService.getCurrentUser()))
.collect(toList());
}
public List<PaperDto> findAllActiveDto() { public List<PaperDto> findAllActiveDto() {
return convert(findAllActive(), PaperDto::new); return convert(findAllActive(), PaperDto::new);
} }

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:p="http://primefaces.org/ui"
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>
</ui:define>
</ui:composition>
</html>