Commit fc433b1d by Antti Tönkyrä

editable foodwaves

1 parent c31db398
...@@ -80,7 +80,8 @@ public class FoodWaveBean implements FoodWaveBeanLocal { ...@@ -80,7 +80,8 @@ public class FoodWaveBean implements FoodWaveBeanLocal {
@Override @Override
public FoodWave merge(FoodWave foodWave) { public FoodWave merge(FoodWave foodWave) {
return foodWaveFacade.merge(foodWave); foodWave = foodWaveFacade.merge(foodWave);
return foodWave;
} }
@Override @Override
......
package fi.insomnia.bortal.facade; package fi.insomnia.bortal.facade;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
...@@ -41,7 +42,7 @@ public class FoodWaveFacade extends IntegerPkGenericFacade<FoodWave> { ...@@ -41,7 +42,7 @@ public class FoodWaveFacade extends IntegerPkGenericFacade<FoodWave> {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<FoodWave> cq = cb.createQuery(FoodWave.class); CriteriaQuery<FoodWave> cq = cb.createQuery(FoodWave.class);
Root<FoodWave> root = cq.from(FoodWave.class); Root<FoodWave> root = cq.from(FoodWave.class);
cq.where(cb.greaterThan(root.get(FoodWave_.time), Calendar.getInstance()), cb.isFalse(root.get(FoodWave_.closed)), cb.equal(root.get(FoodWave_.template).get(FoodWaveTemplate_.event), eventBean.getCurrentEvent())); cq.where(cb.greaterThan(root.get(FoodWave_.time), new Date()), cb.isFalse(root.get(FoodWave_.closed)), cb.equal(root.get(FoodWave_.template).get(FoodWaveTemplate_.event), eventBean.getCurrentEvent()));
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
} }
......
...@@ -419,7 +419,7 @@ public class Bill extends GenericEntity { ...@@ -419,7 +419,7 @@ public class Bill extends GenericEntity {
boolean ret = false; boolean ret = false;
for (BillLine bl : billLines) for (BillLine bl : billLines)
{ {
if (bl.getFoodwave() != null && (bl.getFoodwave().getClosed() || bl.getFoodwave().getTime().before(Calendar.getInstance()))) if (bl.getFoodwave() != null && (bl.getFoodwave().getClosed() || bl.getFoodwave().getTime().before(new Date())))
{ {
ret = true; ret = true;
break; break;
......
...@@ -6,6 +6,7 @@ package fi.insomnia.bortal.model; ...@@ -6,6 +6,7 @@ package fi.insomnia.bortal.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
import javax.persistence.Column; import javax.persistence.Column;
...@@ -42,7 +43,7 @@ public class FoodWave extends GenericEntity { ...@@ -42,7 +43,7 @@ public class FoodWave extends GenericEntity {
@Column(name = "wave_time") @Column(name = "wave_time")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar time; private Date time;
@Column(name = "max_foods") @Column(name = "max_foods")
private Integer maximumFoods; private Integer maximumFoods;
...@@ -86,11 +87,11 @@ public class FoodWave extends GenericEntity { ...@@ -86,11 +87,11 @@ public class FoodWave extends GenericEntity {
this.description = waveDescription; this.description = waveDescription;
} }
public Calendar getTime() { public Date getTime() {
return time; return time;
} }
public void setTime(Calendar waveTime) { public void setTime(Date waveTime) {
this.time = waveTime; this.time = waveTime;
} }
...@@ -143,7 +144,7 @@ public class FoodWave extends GenericEntity { ...@@ -143,7 +144,7 @@ public class FoodWave extends GenericEntity {
return false; return false;
} }
if (getTime().before(Calendar.getInstance())) { if (getTime().before(new Date())) {
return false; return false;
} }
......
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
value="#{foodWaveView.template.products}" var="product" value="#{foodWaveView.template.products}" var="product"
editable="true"> editable="true">
<p:ajax event="rowEdit" listener="#{foodWaveView.onEdit}" /> <p:ajax event="rowEdit" listener="#{foodWaveView.onEdit}" />
<p:column headerText="#{i18n['foodwavetemplate.productname']}"> <p:column headerText="#{i18n['foodwavetemplate.productname']}">
......
...@@ -21,16 +21,24 @@ ...@@ -21,16 +21,24 @@
<h1>#{i18n['foodWave.list']}</h1> <h1>#{i18n['foodWave.list']}</h1>
</ui:define> </ui:define>
<ui:define name="content"> <ui:define name="content">
<h:form>
<p:dataTable styleClass="bordertable" <p:dataTable styleClass="bordertable" value="#{foodWaveView.foodWaves}" var="foodwave" editable="true">
value="#{foodWaveView.foodWaves}" var="foodwave"> <p:ajax event="rowEdit" listener="#{foodWaveView.onEditFoodWave}" />
<p:column> <p:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="${i18n['foodWave.time']}" /> <h:outputText value="${i18n['foodWave.time']}" />
</f:facet> </f:facet>
<h:outputText value="#{foodwave.time.time}"> <p:cellEditor>
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" /> <f:facet name="output">
</h:outputText> <h:outputText value="#{foodwave.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText>
</f:facet>
<f:facet name="input">
<p:calendar id="startTime" value="#{foodwave.time}" pattern="#{sessionHandler.datetimeFormat}" />
</f:facet>
</p:cellEditor>
</p:column> </p:column>
<p:column> <p:column>
<f:facet name="header"> <f:facet name="header">
...@@ -42,8 +50,15 @@ ...@@ -42,8 +50,15 @@
<f:facet name="header"> <f:facet name="header">
<h:outputLabel id="name" value="${i18n['foodWave.name']}" /> <h:outputLabel id="name" value="${i18n['foodWave.name']}" />
</f:facet> </f:facet>
<p:cellEditor>
<h:outputText value="#{foodwave.name}" /> <f:facet name="output">
<h:outputText value="#{foodwave.name}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{foodwave.name}" style="width:100%"
required="true" requiredMessage="Name required" />
</f:facet>
</p:cellEditor>
</p:column> </p:column>
<p:column styleClass="text-center"> <p:column styleClass="text-center">
<f:facet name="header"> <f:facet name="header">
...@@ -69,7 +84,12 @@ ...@@ -69,7 +84,12 @@
value="#{i18n['foodWave.show']}"> value="#{i18n['foodWave.show']}">
<f:param name="foodwaveid" value="#{foodwave.id}" /> <f:param name="foodwaveid" value="#{foodwave.id}" />
</h:link> </h:link>
</p:column><!-- </p:column>
<p:column>
<p:rowEditor />
</p:column>
<!--
<p:column> <p:column>
<h:outputText value="#{foodwave.closed.toString()}" /> <h:outputText value="#{foodwave.closed.toString()}" />
<p:commandButton rendered="#{foodwave.closed}" <p:commandButton rendered="#{foodwave.closed}"
...@@ -80,8 +100,7 @@ ...@@ -80,8 +100,7 @@
action="#{foodwave.toggleClosed}" /> action="#{foodwave.toggleClosed}" />
</p:column> --> </p:column> -->
</p:dataTable> </p:dataTable>
</h:form>
</ui:define> </ui:define>
......
...@@ -67,7 +67,7 @@ public class FoodWaveView extends GenericCDIView { ...@@ -67,7 +67,7 @@ public class FoodWaveView extends GenericCDIView {
private Integer foodWaveId; private Integer foodWaveId;
private ListDataModel<AccountEvent> accountEventLines; private ListDataModel<AccountEvent> accountEventLines;
private List<FoodWave> foodWaves; private ListDataModel<FoodWave> foodWaves;
private static final Logger logger = LoggerFactory.getLogger(FoodWaveView.class); private static final Logger logger = LoggerFactory.getLogger(FoodWaveView.class);
public List<Product> getProducts() { public List<Product> getProducts() {
...@@ -79,6 +79,11 @@ public class FoodWaveView extends GenericCDIView { ...@@ -79,6 +79,11 @@ public class FoodWaveView extends GenericCDIView {
public void onEdit() { public void onEdit() {
this.foodWaveBean.saveTemplate(template); this.foodWaveBean.saveTemplate(template);
} }
public void onEditFoodWave() {
FoodWave fw = foodWaves.getRowData();
this.foodWaveBean.merge(fw);
}
public void initTemplateList() { public void initTemplateList() {
super.requirePermissions(ShopPermission.SHOP_FOODWAVE); super.requirePermissions(ShopPermission.SHOP_FOODWAVE);
...@@ -87,7 +92,11 @@ public class FoodWaveView extends GenericCDIView { ...@@ -87,7 +92,11 @@ public class FoodWaveView extends GenericCDIView {
public void initFoodwaveManagerList() { public void initFoodwaveManagerList() {
if (super.requirePermissions(ShopPermission.MANAGE_FOODWAVES)) if (super.requirePermissions(ShopPermission.MANAGE_FOODWAVES))
{ {
foodWaves = foodWaveBean.getEventFoodWaves(); if(foodWaves == null) {
super.beginConversation();
foodWaves = new ListDataModel<FoodWave>(foodWaveBean.getEventFoodWaves());
}
} }
} }
...@@ -95,7 +104,7 @@ public class FoodWaveView extends GenericCDIView { ...@@ -95,7 +104,7 @@ public class FoodWaveView extends GenericCDIView {
public String createFoodwave() { public String createFoodwave() {
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
c.setTime(startDate); c.setTime(startDate);
selectedFoodWave.setTime(c); selectedFoodWave.setTime(c.getTime());
foodWaveBean.createFoodWave(selectedFoodWave); foodWaveBean.createFoodWave(selectedFoodWave);
initFoodwaveManagerList(); initFoodwaveManagerList();
...@@ -110,9 +119,9 @@ public class FoodWaveView extends GenericCDIView { ...@@ -110,9 +119,9 @@ public class FoodWaveView extends GenericCDIView {
if (templateId != null) if (templateId != null)
{ {
template = foodWaveBean.findTemplate(templateId); template = foodWaveBean.findTemplate(templateId);
foodWaves = template.getFoodwaves(); foodWaves = new ListDataModel<FoodWave>(template.getFoodwaves());
} else { } else {
foodWaves = foodWaveBean.getOpenFoodWaves(); foodWaves = new ListDataModel<FoodWave>(foodWaveBean.getOpenFoodWaves());
} }
super.beginConversation(); super.beginConversation();
} }
...@@ -335,11 +344,11 @@ public class FoodWaveView extends GenericCDIView { ...@@ -335,11 +344,11 @@ public class FoodWaveView extends GenericCDIView {
this.billLines = billLines; this.billLines = billLines;
} }
public void setFoodWaves(List<FoodWave> foodWaves) { public void setFoodWaves(ListDataModel<FoodWave> foodWaves) {
this.foodWaves = foodWaves; this.foodWaves = foodWaves;
} }
public List<FoodWave> getFoodWaves() { public ListDataModel<FoodWave> getFoodWaves() {
return foodWaves; return foodWaves;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!