quick add paper
This commit is contained in:
parent
c36876f7e7
commit
bc48a486ee
@ -60,4 +60,10 @@ public class DateUtils {
|
|||||||
cal.add(Calendar.YEAR, count);
|
cal.add(Calendar.YEAR, count);
|
||||||
return cal.getTime();
|
return cal.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LocalDate convertToLocalDate(Date dateToConvert) {
|
||||||
|
return dateToConvert.toInstant()
|
||||||
|
.atZone(ZoneId.systemDefault())
|
||||||
|
.toLocalDate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,11 @@ package ru.ulstu.deadline.service;
|
|||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.core.util.DateUtils;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.repository.DeadlineRepository;
|
import ru.ulstu.deadline.repository.DeadlineRepository;
|
||||||
|
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -47,6 +49,12 @@ public class DeadlineService {
|
|||||||
return newDeadline;
|
return newDeadline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Deadline create(Date date) {
|
||||||
|
Deadline deadline = new Deadline();
|
||||||
|
deadline.setDate(date);
|
||||||
|
return create(deadline);
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void remove(Integer deadlineId) {
|
public void remove(Integer deadlineId) {
|
||||||
deadlineRepository.deleteById(deadlineId);
|
deadlineRepository.deleteById(deadlineId);
|
||||||
@ -55,4 +63,8 @@ public class DeadlineService {
|
|||||||
public Date findByGrantIdAndDate(Integer id, Date date) {
|
public Date findByGrantIdAndDate(Integer id, Date date) {
|
||||||
return deadlineRepository.findByGrantIdAndDate(id, 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)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ru.ulstu.paper.controller;
|
package ru.ulstu.paper.controller;
|
||||||
|
|
||||||
|
import ru.ulstu.core.util.FacesUtil;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
|
|
||||||
@ -18,11 +19,20 @@ public class PapersView {
|
|||||||
|
|
||||||
private List<Paper> papers;
|
private List<Paper> papers;
|
||||||
|
|
||||||
|
private String newPaperTitle;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
papers = paperService.findAll();
|
papers = paperService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void create() {
|
||||||
|
paperService.createByTitle(newPaperTitle);
|
||||||
|
FacesUtil.showInfoMessage("Статья создана", newPaperTitle);
|
||||||
|
newPaperTitle = "";
|
||||||
|
papers = paperService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
public List<Paper.PaperStatus> getPaperStatuses() {
|
public List<Paper.PaperStatus> getPaperStatuses() {
|
||||||
return Arrays.asList(Paper.PaperStatus.values());
|
return Arrays.asList(Paper.PaperStatus.values());
|
||||||
}
|
}
|
||||||
@ -30,4 +40,12 @@ public class PapersView {
|
|||||||
public List<Paper> getPapers() {
|
public List<Paper> getPapers() {
|
||||||
return papers;
|
return papers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getNewPaperTitle() {
|
||||||
|
return newPaperTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewPaperTitle(String newPaperTitle) {
|
||||||
|
this.newPaperTitle = newPaperTitle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import ru.ulstu.user.service.UserService;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -116,6 +117,7 @@ public class PaperService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public Paper create(Paper paper) {
|
public Paper create(Paper paper) {
|
||||||
Paper newPaper = paperRepository.save(paper);
|
Paper newPaper = paperRepository.save(paper);
|
||||||
|
newPaper.setCreateDate(new Date());
|
||||||
paperNotificationService.sendCreateNotification(newPaper);
|
paperNotificationService.sendCreateNotification(newPaper);
|
||||||
return newPaper;
|
return newPaper;
|
||||||
}
|
}
|
||||||
@ -426,4 +428,13 @@ public class PaperService {
|
|||||||
public void ping(int paperId) throws IOException {
|
public void ping(int paperId) throws IOException {
|
||||||
pingService.addPing(findPaperById(paperId));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
</h:outputLink>
|
</h:outputLink>
|
||||||
</p:column>
|
</p:column>
|
||||||
<p:column headerText="Статус" filterBy="#{paper.status} #{paper.status.statusName}"
|
<p:column headerText="Статус" filterBy="#{paper.status} #{paper.status.statusName}"
|
||||||
filterMatchMode="contains">'
|
filterMatchMode="contains">
|
||||||
<f:facet name="filter">
|
<f:facet name="filter">
|
||||||
<p:selectOneMenu onchange="PF('papersTable').filter()" styleClass="custom-filter"
|
<p:selectOneMenu onchange="PF('papersTable').filter()" styleClass="custom-filter"
|
||||||
converter="paperStatusConverter">
|
converter="paperStatusConverter">
|
||||||
@ -40,6 +40,9 @@
|
|||||||
</ui:include>
|
</ui:include>
|
||||||
</p:column>
|
</p:column>
|
||||||
</p:dataTable>
|
</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:define>
|
||||||
</ui:composition>
|
</ui:composition>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user