From 708a1a6d327b78839899428d8a1c982b4c0b0e1f Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 25 Apr 2020 01:30:27 +0400 Subject: [PATCH] add dynamic deadlines --- .../deadline/service/DeadlineService.java | 7 +++++ .../ru/ulstu/paper/controller/PaperView.java | 17 ++++++++++++ .../ru/ulstu/paper/service/PaperService.java | 2 +- .../META-INF/resources/basicTemplate.xhtml | 1 + .../META-INF/resources/paper/paper.xhtml | 26 +++++++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java index 1fbd69f..42eac92 100644 --- a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java +++ b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java @@ -55,6 +55,13 @@ public class DeadlineService { return create(deadline); } + public Deadline create(String description, Date date) { + Deadline deadline = new Deadline(); + deadline.setDate(date); + deadline.setDescription(description); + return create(deadline); + } + @Transactional public void remove(Integer deadlineId) { deadlineRepository.deleteById(deadlineId); diff --git a/src/main/java/ru/ulstu/paper/controller/PaperView.java b/src/main/java/ru/ulstu/paper/controller/PaperView.java index a6e627f..0a3432a 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperView.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperView.java @@ -2,6 +2,8 @@ package ru.ulstu.paper.controller; import ru.ulstu.core.navigation.Page; import ru.ulstu.core.util.FacesUtil; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; import ru.ulstu.user.model.User; @@ -22,6 +24,9 @@ public class PaperView implements Serializable { @Inject private PaperService paperService; + @Inject + private DeadlineService deadlineService; + @Inject private UserService userService; @@ -34,6 +39,8 @@ public class PaperView implements Serializable { @PostConstruct public void init() { paper = paperService.findPaperById(Integer.valueOf(FacesUtil.getRequestParams().get("id"))); + newDeadlineDescription = ""; + newDeadlineDate = new Date(); FacesUtil.showInfoMessage("Статья открыта", ""); } @@ -78,4 +85,14 @@ public class PaperView implements Serializable { public void setNewDeadlineDescription(String newDeadlineDescription) { this.newDeadlineDescription = newDeadlineDescription; } + + public void deleteDeadline(Deadline deadline) { + paper.getDeadlines().remove(deadline); + } + + public void addDeadline() { + paper.getDeadlines().add(deadlineService.create(newDeadlineDescription, newDeadlineDate)); + newDeadlineDescription = ""; + newDeadlineDate = new Date(); + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 072ed19..3d61c7f 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -216,7 +216,7 @@ public class PaperService { Paper oldPaper = paperRepository.getOne(newPaper.getId()); Paper.PaperStatus oldStatus = oldPaper.getStatus(); Set oldAuthors = new HashSet<>(oldPaper.getAuthors()); - + newPaper.setUpdateDate(new Date()); newPaper = paperRepository.save(newPaper); for (User author : newPaper.getAuthors()) { if (!oldAuthors.contains(author)) { diff --git a/src/main/resources/META-INF/resources/basicTemplate.xhtml b/src/main/resources/META-INF/resources/basicTemplate.xhtml index cca4fd7..2f2ef14 100644 --- a/src/main/resources/META-INF/resources/basicTemplate.xhtml +++ b/src/main/resources/META-INF/resources/basicTemplate.xhtml @@ -10,6 +10,7 @@ <ui:insert name="header">NG-Tracker</ui:insert> + diff --git a/src/main/resources/META-INF/resources/paper/paper.xhtml b/src/main/resources/META-INF/resources/paper/paper.xhtml index 330b247..20f4978 100644 --- a/src/main/resources/META-INF/resources/paper/paper.xhtml +++ b/src/main/resources/META-INF/resources/paper/paper.xhtml @@ -107,6 +107,12 @@
+
+ + + +
+
+ + + +
@@ -127,6 +139,20 @@ +
+

+ Статья создана + + + +

+

+ Статья обновлена + + + +

+