From 5ee1f33de11e0b0f93c432873266b4ddc61fd49a Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 26 Nov 2019 22:34:24 +0400 Subject: [PATCH] add papers dashboard --- .../ulstu/paper/controller/DashboardView.java | 28 +++++++++++++++++++ .../ru/ulstu/paper/service/PaperService.java | 9 +++++- .../META-INF/resources/paper/dashboard.xhtml | 23 +++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ru/ulstu/paper/controller/DashboardView.java create mode 100644 src/main/resources/META-INF/resources/paper/dashboard.xhtml diff --git a/src/main/java/ru/ulstu/paper/controller/DashboardView.java b/src/main/java/ru/ulstu/paper/controller/DashboardView.java new file mode 100644 index 0000000..fd7fa28 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/controller/DashboardView.java @@ -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 papers; + + @PostConstruct + public void init() { + papers = paperService.findAllActiveByCurrentUser(); + } + + public List getPapers() { + return papers; + } +} diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 28e3274..b3738ce 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -85,13 +85,20 @@ public class PaperService { return papers; } - private List findAllActive() { + public List findAllActive() { return findAll() .stream() .filter(paper -> paper.getStatus() != COMPLETED && paper.getStatus() != FAILED) .collect(toList()); } + public List findAllActiveByCurrentUser() { + return findAllActive() + .stream() + .filter(paper -> paper.getAuthors().contains(userService.getCurrentUser())) + .collect(toList()); + } + public List findAllActiveDto() { return convert(findAllActive(), PaperDto::new); } diff --git a/src/main/resources/META-INF/resources/paper/dashboard.xhtml b/src/main/resources/META-INF/resources/paper/dashboard.xhtml new file mode 100644 index 0000000..6137a8f --- /dev/null +++ b/src/main/resources/META-INF/resources/paper/dashboard.xhtml @@ -0,0 +1,23 @@ + + + + + + + + + #{paper.title} + + + + + + + + + + + +