show grants
parent
2cc3008dc5
commit
5520f19357
@ -0,0 +1,76 @@
|
||||
package ru.ulstu.grant.controller;
|
||||
|
||||
import ru.ulstu.core.util.FacesUtil;
|
||||
import ru.ulstu.grant.model.Grant;
|
||||
import ru.ulstu.grant.service.GrantService;
|
||||
import ru.ulstu.user.service.UserService;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class GrantDashboardView {
|
||||
@Inject
|
||||
private GrantService grantService;
|
||||
|
||||
@Inject
|
||||
private UserService userService;
|
||||
|
||||
private List<Grant> grants;
|
||||
|
||||
private List<Grant> selectedGrants = new ArrayList<>();
|
||||
|
||||
private String newGrantTitle;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
grants = grantService.findAllActiveByCurrentUser();
|
||||
}
|
||||
|
||||
public List<Grant> getGrants() {
|
||||
return grants;
|
||||
}
|
||||
|
||||
public void create() {
|
||||
grantService.createByTitle(newGrantTitle);
|
||||
FacesUtil.showInfoMessage("Статья создана", newGrantTitle);
|
||||
newGrantTitle = "";
|
||||
grants = grantService.findAllActiveByCurrentUser();
|
||||
}
|
||||
|
||||
public void deleteSelected() {
|
||||
grantService.delete(selectedGrants);
|
||||
grants = grantService.findAllActiveByCurrentUser();
|
||||
FacesUtil.showInfoMessage("Было удалено грантов: " + selectedGrants.size(), "");
|
||||
}
|
||||
|
||||
public List<Grant.GrantStatus> getGrantStatuses() {
|
||||
return Arrays.asList(Grant.GrantStatus.values());
|
||||
}
|
||||
|
||||
public String getNewGrantTitle() {
|
||||
return newGrantTitle;
|
||||
}
|
||||
|
||||
public void setNewGrantTitle(String newGrantTitle) {
|
||||
this.newGrantTitle = newGrantTitle;
|
||||
}
|
||||
|
||||
public List<Grant> getSelectedGrants() {
|
||||
return selectedGrants;
|
||||
}
|
||||
|
||||
public void setSelectedGrants(List<Grant> selectedGrants) {
|
||||
this.selectedGrants = selectedGrants;
|
||||
}
|
||||
|
||||
public String getCurrentUser() {
|
||||
return userService.getCurrentUser().getUserAbbreviate();
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package ru.ulstu.grant.controller;
|
||||
|
||||
import ru.ulstu.grant.model.Grant;
|
||||
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.convert.Converter;
|
||||
import javax.faces.convert.FacesConverter;
|
||||
|
||||
@FacesConverter(value = "grantStatusConverter")
|
||||
public class GrantStatusConverter implements Converter {
|
||||
@Override
|
||||
public Object getAsObject(FacesContext context, UIComponent component, String value) {
|
||||
return Grant.GrantStatus.valueOf(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString(FacesContext context, UIComponent component, Object value) {
|
||||
return value == null ? "" : ((Grant.GrantStatus) value).name();
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package ru.ulstu.grant.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.grant.model.Grant;
|
||||
import ru.ulstu.grant.service.GrantService;
|
||||
import ru.ulstu.user.model.User;
|
||||
import ru.ulstu.user.service.UserService;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class GrantView implements Serializable {
|
||||
@Inject
|
||||
private GrantService grantService;
|
||||
|
||||
@Inject
|
||||
private DeadlineService deadlineService;
|
||||
|
||||
@Inject
|
||||
private UserService userService;
|
||||
|
||||
private Grant grant;
|
||||
|
||||
private Date newDeadlineDate;
|
||||
|
||||
private String newDeadlineDescription;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
grant = grantService.findById(Integer.valueOf(FacesUtil.getRequestParams().get("id")));
|
||||
newDeadlineDescription = "";
|
||||
newDeadlineDate = new Date();
|
||||
FacesUtil.showInfoMessage("Статья открыта", "");
|
||||
}
|
||||
|
||||
public Grant getGrant() {
|
||||
return grant;
|
||||
}
|
||||
|
||||
public void setGrant(Grant grant) {
|
||||
this.grant = grant;
|
||||
}
|
||||
|
||||
public List<Grant.GrantStatus> getGrantStatuses() {
|
||||
return Arrays.asList(Grant.GrantStatus.values());
|
||||
}
|
||||
|
||||
public List<User> getAuthors() {
|
||||
return userService.findAll();
|
||||
}
|
||||
|
||||
public String save() {
|
||||
grantService.save(grant);
|
||||
FacesUtil.showInfoMessage("Грант сохранен", "");
|
||||
return Page.GRANT_LIST + "?faces-redirect=true";
|
||||
}
|
||||
|
||||
public Date getNewDeadlineDate() {
|
||||
return newDeadlineDate;
|
||||
}
|
||||
|
||||
public void setNewDeadlineDate(Date newDeadlineDate) {
|
||||
this.newDeadlineDate = newDeadlineDate;
|
||||
}
|
||||
|
||||
public String getNewDeadlineDescription() {
|
||||
return newDeadlineDescription;
|
||||
}
|
||||
|
||||
public void setNewDeadlineDescription(String newDeadlineDescription) {
|
||||
this.newDeadlineDescription = newDeadlineDescription;
|
||||
}
|
||||
|
||||
public void deleteDeadline(Deadline deadline) {
|
||||
grant.getDeadlines().remove(deadline);
|
||||
}
|
||||
|
||||
public void addDeadline() {
|
||||
grant.getDeadlines().add(deadlineService.create(newDeadlineDescription, newDeadlineDate));
|
||||
newDeadlineDescription = "";
|
||||
newDeadlineDate = new Date();
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package ru.ulstu.grant.controller;
|
||||
|
||||
import ru.ulstu.core.util.FacesUtil;
|
||||
import ru.ulstu.grant.model.Grant;
|
||||
import ru.ulstu.grant.service.GrantService;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class GrantsView {
|
||||
@Inject
|
||||
private GrantService grantService;
|
||||
|
||||
private List<Grant> grants;
|
||||
|
||||
private List<Grant> selectedGrants = new ArrayList<>();
|
||||
|
||||
private String newGrantTitle;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
grants = grantService.findAll();
|
||||
}
|
||||
|
||||
public void create() {
|
||||
grantService.createByTitle(newGrantTitle);
|
||||
FacesUtil.showInfoMessage("Статья создана", newGrantTitle);
|
||||
newGrantTitle = "";
|
||||
grants = grantService.findAll();
|
||||
}
|
||||
|
||||
public void deleteSelected() {
|
||||
grantService.delete(selectedGrants);
|
||||
grants = grantService.findAll();
|
||||
FacesUtil.showInfoMessage("Было удалено грантов: " + selectedGrants.size(), "");
|
||||
}
|
||||
|
||||
public List<Grant.GrantStatus> getGrantStatuses() {
|
||||
return Arrays.asList(Grant.GrantStatus.values());
|
||||
}
|
||||
|
||||
public List<Grant> getGrants() {
|
||||
return grants;
|
||||
}
|
||||
|
||||
public String getNewGrantTitle() {
|
||||
return newGrantTitle;
|
||||
}
|
||||
|
||||
public void setNewGrantTitle(String newGrantTitle) {
|
||||
this.newGrantTitle = newGrantTitle;
|
||||
}
|
||||
|
||||
public List<Grant> getSelectedGrants() {
|
||||
return selectedGrants;
|
||||
}
|
||||
|
||||
public void setSelectedGrants(List<Grant> selectedGrants) {
|
||||
this.selectedGrants = selectedGrants;
|
||||
}
|
||||
}
|
@ -0,0 +1,142 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:p="http://primefaces.org/ui"
|
||||
xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
|
||||
>
|
||||
<ui:composition template="/basicTemplate.xhtml">
|
||||
<ui:define name="header">
|
||||
Редактирование гранта
|
||||
</ui:define>
|
||||
<ui:define name="content">
|
||||
<style>
|
||||
#mainForm\:grantStatus > tbody > tr {
|
||||
border: none;
|
||||
}
|
||||
|
||||
#mainForm\:grantStatus > tbody > tr > td {
|
||||
border: none;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#mainForm\:grantPanel > tbody > tr {
|
||||
border: none;
|
||||
}
|
||||
|
||||
#mainForm\:grantPanel > tbody > tr > td {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.ui-editor.ui-widget-content {
|
||||
background: white !important;
|
||||
}
|
||||
</style>
|
||||
<p:panel id="panel" header="Редактирование гранта: #{grantView.grant.title}" style="margin-bottom:10px;">
|
||||
<div class="ui-fluid">
|
||||
<div class="ui-g">
|
||||
<div class="ui-md-3 ui-g-12">
|
||||
<h:outputLabel value="Название:"/>
|
||||
</div>
|
||||
<div class="ui-md-7 ui-g-12">
|
||||
<p:inputText id="name" required="true" value="#{grantView.grant.title}"/>
|
||||
<p:message for="name"/>
|
||||
</div>
|
||||
<div class="ui-md-2 ui-g-12">
|
||||
|
||||
</div>
|
||||
<div class="ui-md-3 ui-g-12">
|
||||
<p:outputLabel for="grantStatus" value="Статус:"/>
|
||||
</div>
|
||||
<div class="ui-md-7 ui-g-12">
|
||||
<p:panelGrid columns="2" id="grantStatus">
|
||||
<p:selectOneMenu id="status" required="true" value="#{grantView.grant.status}"
|
||||
converter="grantStatusConverter">
|
||||
<p:ajax update="mainForm:grantStatus" process="@this"/>
|
||||
<f:selectItems value="#{grantView.grantStatuses}"
|
||||
var="status"
|
||||
itemLabel="#{status.statusName}"
|
||||
itemValue="#{status}"/>
|
||||
</p:selectOneMenu>
|
||||
<ui:include src="grantStatusFragment.xhtml">
|
||||
<ui:param name="grant" value="#{grantView.grant}"/>
|
||||
<ui:param name="shortMode" value="true"/>
|
||||
</ui:include>
|
||||
</p:panelGrid>
|
||||
</div>
|
||||
|
||||
<div class="ui-md-3 ui-g-12">
|
||||
<p:outputLabel for="authors" value="Авторы:"/>
|
||||
</div>
|
||||
<div class="ui-md-7 ui-g-12">
|
||||
<p:selectCheckboxMenu id="authors" value="#{grantView.grant.authors}" multiple="true"
|
||||
converter="#{userConverter}">
|
||||
<f:attribute name="collectionType" value="java.util.HashSet"/>
|
||||
<f:selectItems value="#{grantView.authors}"
|
||||
var="author"
|
||||
itemLabel="#{author.userAbbreviate}"
|
||||
itemValue="#{author}"/>
|
||||
</p:selectCheckboxMenu>
|
||||
</div>
|
||||
<div class="ui-md-3 ui-g-12">
|
||||
<p:outputLabel for="authors" value="Ключевые даты:"/>
|
||||
</div>
|
||||
<div class="ui-md-7 ui-g-12">
|
||||
<div class="ui-fluid">
|
||||
<div class="ui-g">
|
||||
<ui:repeat value="#{grantView.grant.deadlines}" var="deadline">
|
||||
<div class="ui-md-5 ui-g-12">
|
||||
<p:datePicker value="#{deadline.date}" pattern="dd.MM.yyyy"/>
|
||||
</div>
|
||||
<div class="ui-md-5 ui-g-12">
|
||||
<p:inputText value="#{deadline.description}"/>
|
||||
</div>
|
||||
<div class="ui-md-1 ui-g-12">
|
||||
<p:commandButton icon="pi pi-times">
|
||||
<p:ajax update="mainForm" process="@this"
|
||||
listener="#{grantView.deleteDeadline(deadline)}"/>
|
||||
</p:commandButton>
|
||||
</div>
|
||||
</ui:repeat>
|
||||
<div class="ui-md-5 ui-g-12">
|
||||
<p:datePicker value="#{grantView.newDeadlineDate}" placeholder="Введите дату"
|
||||
pattern="dd.MM.yyyy"/>
|
||||
</div>
|
||||
<div class="ui-md-5 ui-g-12">
|
||||
<p:inputText value="#{grantView.newDeadlineDescription}"
|
||||
placeholder="Описание ключевой даты"/>
|
||||
</div>
|
||||
<div class="ui-md-1 ui-g-12">
|
||||
<p:commandButton icon="pi pi-check">
|
||||
<p:ajax update="mainForm" process="@this"
|
||||
listener="#{grantView.addDeadline()}"/>
|
||||
</p:commandButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ui-md-3 ui-g-12">
|
||||
<p:outputLabel for="comment" value="Комментарий:"/>
|
||||
</div>
|
||||
<div class="ui-md-7 ui-g-12">
|
||||
<p:editor id="comment" widgetVar="editor2" value="#{grantView.grant.comment}" height="300"
|
||||
style="margin-bottom:10px" placeholder="Комментарий"/>
|
||||
</div>
|
||||
<div class="ui-md-2 ui-g-12">
|
||||
<p>
|
||||
Грант создан
|
||||
</p>
|
||||
<p>
|
||||
Грант обновлен
|
||||
</p>
|
||||
</div>
|
||||
<div class="ui-md-5 ui-g-12">
|
||||
<p:commandButton action="#{grantView.save}" value="Сохранить" ajax="true" process="@form"
|
||||
update="messages @form"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</p:panel>
|
||||
</ui:define>
|
||||
</ui:composition>
|
||||
</html>
|
@ -0,0 +1,10 @@
|
||||
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:p="http://java.sun.com/jsf/html">
|
||||
<span class="fa-stack fa-1x big-icon" title="#{grant.status.statusName}">
|
||||
<i class="fa fa-circle #{grant.status.elementClass} fa-stack-2x"></i>
|
||||
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
|
||||
</span>
|
||||
<ui:fragment rendered="#{shortMode != true}">
|
||||
<p:outputText value="#{grant.status.statusName}"/>
|
||||
</ui:fragment>
|
||||
</ui:composition>
|
Loading…
Reference in New Issue