Merge remote-tracking branch 'origin/jsf' into jsf

This commit is contained in:
Anton Romanov 2020-02-14 09:35:42 +04:00
commit 134f75666c
5 changed files with 51 additions and 1 deletions

View File

@ -60,4 +60,10 @@ public class DateUtils {
cal.add(Calendar.YEAR, count);
return cal.getTime();
}
public static LocalDate convertToLocalDate(Date dateToConvert) {
return dateToConvert.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
}
}

View File

@ -2,9 +2,11 @@ package ru.ulstu.deadline.service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.ulstu.core.util.DateUtils;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.deadline.repository.DeadlineRepository;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@ -47,6 +49,12 @@ public class DeadlineService {
return newDeadline;
}
public Deadline create(Date date) {
Deadline deadline = new Deadline();
deadline.setDate(date);
return create(deadline);
}
@Transactional
public void remove(Integer deadlineId) {
deadlineRepository.deleteById(deadlineId);
@ -55,4 +63,8 @@ public class DeadlineService {
public Date findByGrantIdAndDate(Integer id, Date date) {
return deadlineRepository.findByGrantIdAndDate(id, date);
}
public Deadline createWithOffset(Date date, long value, ChronoUnit chronoUnit) {
return create(DateUtils.localDateToDate(DateUtils.convertToLocalDate(date).plus(value, chronoUnit)));
}
}

View File

@ -1,5 +1,6 @@
package ru.ulstu.paper.controller;
import ru.ulstu.core.util.FacesUtil;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.service.PaperService;
@ -18,11 +19,20 @@ public class PapersView {
private List<Paper> papers;
private String newPaperTitle;
@PostConstruct
public void init() {
papers = paperService.findAll();
}
public void create() {
paperService.createByTitle(newPaperTitle);
FacesUtil.showInfoMessage("Статья создана", newPaperTitle);
newPaperTitle = "";
papers = paperService.findAll();
}
public List<Paper.PaperStatus> getPaperStatuses() {
return Arrays.asList(Paper.PaperStatus.values());
}
@ -30,4 +40,12 @@ public class PapersView {
public List<Paper> getPapers() {
return papers;
}
public String getNewPaperTitle() {
return newPaperTitle;
}
public void setNewPaperTitle(String newPaperTitle) {
this.newPaperTitle = newPaperTitle;
}
}

View File

@ -22,6 +22,7 @@ import ru.ulstu.user.service.UserService;
import java.io.IOException;
import java.text.MessageFormat;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
@ -116,6 +117,7 @@ public class PaperService {
@Transactional
public Paper create(Paper paper) {
Paper newPaper = paperRepository.save(paper);
newPaper.setCreateDate(new Date());
paperNotificationService.sendCreateNotification(newPaper);
return newPaper;
}
@ -426,4 +428,13 @@ public class PaperService {
public void ping(int paperId) throws IOException {
pingService.addPing(findPaperById(paperId));
}
public void createByTitle(String newPaperTitle) {
Paper paper = new Paper();
paper.setTitle(newPaperTitle);
paper.setStatus(DRAFT);
paper.getAuthors().add(userService.getCurrentUser());
paper.getDeadlines().add(deadlineService.createWithOffset(new Date(), 1, ChronoUnit.WEEKS));
create(paper);
}
}

View File

@ -26,7 +26,7 @@
</h:outputLink>
</p:column>
<p:column headerText="Статус" filterBy="#{paper.status} #{paper.status.statusName}"
filterMatchMode="contains">'
filterMatchMode="contains">
<f:facet name="filter">
<p:selectOneMenu onchange="PF('papersTable').filter()" styleClass="custom-filter"
converter="paperStatusConverter">
@ -40,6 +40,9 @@
</ui:include>
</p:column>
</p:dataTable>
<p:inputText placeholder="Создать новую статью" value="#{papersView.newPaperTitle}"/>
<p:commandButton action="#{papersView.create}" value="Сохранить" ajax="true" process="@form"
update="messages @form mainForm:papersTable" style="visibility: hidden"/>
</ui:define>
</ui:composition>
</html>