add dynamic deadlines

This commit is contained in:
Anton Romanov 2020-04-25 01:30:27 +04:00
parent 751195bf96
commit 708a1a6d32
5 changed files with 52 additions and 1 deletions

View File

@ -55,6 +55,13 @@ public class DeadlineService {
return create(deadline); return create(deadline);
} }
public Deadline create(String description, Date date) {
Deadline deadline = new Deadline();
deadline.setDate(date);
deadline.setDescription(description);
return create(deadline);
}
@Transactional @Transactional
public void remove(Integer deadlineId) { public void remove(Integer deadlineId) {
deadlineRepository.deleteById(deadlineId); deadlineRepository.deleteById(deadlineId);

View File

@ -2,6 +2,8 @@ package ru.ulstu.paper.controller;
import ru.ulstu.core.navigation.Page; import ru.ulstu.core.navigation.Page;
import ru.ulstu.core.util.FacesUtil; 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.model.Paper;
import ru.ulstu.paper.service.PaperService; import ru.ulstu.paper.service.PaperService;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
@ -22,6 +24,9 @@ public class PaperView implements Serializable {
@Inject @Inject
private PaperService paperService; private PaperService paperService;
@Inject
private DeadlineService deadlineService;
@Inject @Inject
private UserService userService; private UserService userService;
@ -34,6 +39,8 @@ public class PaperView implements Serializable {
@PostConstruct @PostConstruct
public void init() { public void init() {
paper = paperService.findPaperById(Integer.valueOf(FacesUtil.getRequestParams().get("id"))); paper = paperService.findPaperById(Integer.valueOf(FacesUtil.getRequestParams().get("id")));
newDeadlineDescription = "";
newDeadlineDate = new Date();
FacesUtil.showInfoMessage("Статья открыта", ""); FacesUtil.showInfoMessage("Статья открыта", "");
} }
@ -78,4 +85,14 @@ public class PaperView implements Serializable {
public void setNewDeadlineDescription(String newDeadlineDescription) { public void setNewDeadlineDescription(String newDeadlineDescription) {
this.newDeadlineDescription = 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();
}
} }

View File

@ -216,7 +216,7 @@ public class PaperService {
Paper oldPaper = paperRepository.getOne(newPaper.getId()); Paper oldPaper = paperRepository.getOne(newPaper.getId());
Paper.PaperStatus oldStatus = oldPaper.getStatus(); Paper.PaperStatus oldStatus = oldPaper.getStatus();
Set<User> oldAuthors = new HashSet<>(oldPaper.getAuthors()); Set<User> oldAuthors = new HashSet<>(oldPaper.getAuthors());
newPaper.setUpdateDate(new Date());
newPaper = paperRepository.save(newPaper); newPaper = paperRepository.save(newPaper);
for (User author : newPaper.getAuthors()) { for (User author : newPaper.getAuthors()) {
if (!oldAuthors.contains(author)) { if (!oldAuthors.contains(author)) {

View File

@ -10,6 +10,7 @@
<title><ui:insert name="header">NG-Tracker</ui:insert></title> <title><ui:insert name="header">NG-Tracker</ui:insert></title>
<h:outputStylesheet name="css/style.css"/> <h:outputStylesheet name="css/style.css"/>
<h:outputStylesheet name="css/google/kaushan.css"/> <h:outputStylesheet name="css/google/kaushan.css"/>
<h:outputStylesheet name="primeicons/primeicons.css" library="primefaces"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
</h:head> </h:head>

View File

@ -107,6 +107,12 @@
<div class="ui-md-5 ui-g-12"> <div class="ui-md-5 ui-g-12">
<p:inputText value="#{deadline.description}"/> <p:inputText value="#{deadline.description}"/>
</div> </div>
<div class="ui-md-1 ui-g-12">
<p:commandButton icon="pi pi-times">
<p:ajax update="mainForm" process="@this"
listener="#{paperView.deleteDeadline(deadline)}"/>
</p:commandButton>
</div>
</ui:repeat> </ui:repeat>
<div class="ui-md-5 ui-g-12"> <div class="ui-md-5 ui-g-12">
<p:datePicker value="#{paperView.newDeadlineDate}" placeholder="Введите дату" <p:datePicker value="#{paperView.newDeadlineDate}" placeholder="Введите дату"
@ -116,6 +122,12 @@
<p:inputText value="#{paperView.newDeadlineDescription}" <p:inputText value="#{paperView.newDeadlineDescription}"
placeholder="Описание ключевой даты"/> placeholder="Описание ключевой даты"/>
</div> </div>
<div class="ui-md-1 ui-g-12">
<p:commandButton icon="pi pi-check">
<p:ajax update="mainForm" process="@this"
listener="#{paperView.addDeadline()}"/>
</p:commandButton>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -127,6 +139,20 @@
<p:editor id="comment" widgetVar="editor2" value="#{paperView.paper.comment}" height="300" <p:editor id="comment" widgetVar="editor2" value="#{paperView.paper.comment}" height="300"
style="margin-bottom:10px" placeholder="Комментарий"/> style="margin-bottom:10px" placeholder="Комментарий"/>
</div> </div>
<div class="ui-md-2 ui-g-12">
<p>
Статья создана
<h:outputText value="#{paperView.paper.createDate}">
<f:convertDateTime pattern="dd.MM.yyyy HH:mm"/>
</h:outputText>
</p>
<p>
Статья обновлена
<h:outputText value="#{paperView.paper.updateDate}">
<f:convertDateTime pattern="dd.MM.yyyy HH:mm"/>
</h:outputText>
</p>
</div>
<div class="ui-md-5 ui-g-12"> <div class="ui-md-5 ui-g-12">
<p:commandButton action="#{paperView.save}" value="Сохранить" ajax="true" process="@form" <p:commandButton action="#{paperView.save}" value="Сохранить" ajax="true" process="@form"
update="messages @form"/> update="messages @form"/>