Commit e812d13a by Tuomas Riihimäki

Final stream version

1 parent 3d8d4ac1
<!DOCTYPE html <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:poll="http://java.sun.com/jsf/composite/cditools/poll" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui">
xmlns:poll="http://java.sun.com/jsf/composite/cditools/poll" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui"
>
<h:body> <h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml"> <ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<f:metadata> <f:metadata>
<f:event type="preRenderView" listener="#{pollView.initCreate}" /> <f:viewParam name="pollid" value="#{pollView.pollId}" />
<f:event type="preRenderView" listener="#{pollView.initPoll}" />
</f:metadata> </f:metadata>
<ui:param name="thispage" value="page.user.edit" />
<ui:define name="content"> <ui:define name="content">
<poll:edit commitaction="#{pollView.savePollEntity()}" commitvalue="#{i18n['poll.save']}" /> <poll:edit commitaction="#{pollView.savePollEntity()}" commitvalue="#{i18n['poll.save']}" />
......
...@@ -31,9 +31,10 @@ ...@@ -31,9 +31,10 @@
<p:calendar id="end" value="#{pollView.poll.end}" style="simple" pattern="#{sessionHandler.datetimeFormat}" /> <p:calendar id="end" value="#{pollView.poll.end}" style="simple" pattern="#{sessionHandler.datetimeFormat}" />
<h:message for="end" /> <h:message for="end" />
<h:outputLabel for="description" value="#{i18n['poll.name']}" /> <h:outputLabel for="description" value="#{i18n['poll.description']}" />
<h:inputTextarea id="description" name="#{pollView.poll.name}" /> <h:inputTextarea id="description" name="#{pollView.poll.description}" />
<h:message for="description" /> <h:message for="description" />
</h:panelGrid> </h:panelGrid>
<h:commandButton id="commitbtn" action="#{cc.attrs.commitaction}" value="#{cc.attrs.commitvalue}" /> <h:commandButton id="commitbtn" action="#{cc.attrs.commitaction}" value="#{cc.attrs.commitvalue}" />
</h:form> </h:form>
......
...@@ -23,42 +23,56 @@ ...@@ -23,42 +23,56 @@
<f:facet name="header"> <f:facet name="header">
<h:outputText value="Title" /> <h:outputText value="Title" />
</f:facet> </f:facet>
<h:outputText value="#{entry.title}" /> <h:outputText value="#{entry.entry.title}" />
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="Author" /> <h:outputText value="Author" />
</f:facet> </f:facet>
<h:outputText value="#{entry.author}" /> <h:outputText value="#{entry.entry.author}" />
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="notes" /> <h:outputText value="notes" />
</f:facet> </f:facet>
<h:outputText value="#{entry.notes}" /> <h:outputText value="#{entry.entry.notes}" />
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="screenmessage" /> <h:outputText value="screenmessage" />
</f:facet> </f:facet>
<h:outputText value="#{entry.screenMessage}" /> <h:outputText value="#{entry.entry.screenMessage}" />
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="creator" /> <h:outputText value="creator" />
</f:facet> </f:facet>
<h:outputText value="#{entry.creator.user.wholeName} / #{entry.creator.nick}" /> <h:link outcome="/useradmin/edit" value="#{entry.entry.creator.user.nick}">
<f:param name="userid" value="#{entry.entry.creator.user.id}" />
</h:link>
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="sort" /> <h:outputText value="sort" />
</f:facet> </f:facet>
<h:inputText value="#{entry.sort}" /> <h:inputText value="#{entry.entry.sort}" size="4" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Vote total" />
</f:facet>
<h:outputText value="#{entry.votetotal}" />
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header">
<h:outputText value="Vote count" />
</f:facet>
<h:outputText value="#{entry.entry.votes.size()}" />
</h:column>
<h:column>
<h:link outcome="/voting/submitEntry" value="#{i18n['entry.edit']}"> <h:link outcome="/voting/submitEntry" value="#{i18n['entry.edit']}">
<f:param name="entryId" value="#{entry.id}" /> <f:param name="entryId" value="#{entry.entry.id}" />
</h:link> </h:link>
</h:column> </h:column>
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<ui:define name="content"> <ui:define name="content">
<!-- <h:outputStylesheet library="style" name="insomnia2/css/actionlog.css" /> --> <!-- <h:outputStylesheet library="style" name="insomnia2/css/actionlog.css" /> -->
<h1>Vote in compo #{votingDetailsView.compoName}</h1> <h1>Vote in compo #{compoView.compo.name}</h1>
<h:form id="voteform"> <h:form id="voteform">
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
</h:column> </h:column>
</h:dataTable> </h:dataTable>
<h:commandButton action="#{compoView.saveVotes}" value="#{i18n['compo.saveVotes']}" /> <!-- <h:commandButton action="#{compoView.saveVotes}" value="#{i18n['compo.saveVotes']}" /> -->
</h:form> </h:form>
......
...@@ -48,7 +48,7 @@ public class CompoView extends GenericCDIView { ...@@ -48,7 +48,7 @@ public class CompoView extends GenericCDIView {
private Integer entryId; private Integer entryId;
private ListDataModel<VoteWrapper> voteEntries; private ListDataModel<EntryWrapper> voteEntries;
public ListDataModel<CompoWrapper> getCompos() { public ListDataModel<CompoWrapper> getCompos() {
return compolist; return compolist;
...@@ -72,7 +72,7 @@ public class CompoView extends GenericCDIView { ...@@ -72,7 +72,7 @@ public class CompoView extends GenericCDIView {
public String startVote() public String startVote()
{ {
compo = compolist.getRowData().getCompo(); compo = compolist.getRowData().getCompo();
setVoteEntries(VoteWrapper.init(compo.getCompoEntries(), votbean)); setVoteEntries(EntryWrapper.init(compo.getCompoEntries(), votbean, false));
logger.info("Initializing voting with entries {}, {}", compo.getCompoEntries().size(), voteEntries.getRowCount()); logger.info("Initializing voting with entries {}, {}", compo.getCompoEntries().size(), voteEntries.getRowCount());
super.beginConversation(); super.beginConversation();
return "/voting/vote"; return "/voting/vote";
...@@ -80,7 +80,7 @@ public class CompoView extends GenericCDIView { ...@@ -80,7 +80,7 @@ public class CompoView extends GenericCDIView {
public void handleVoteRate(RateEvent rateEvent) public void handleVoteRate(RateEvent rateEvent)
{ {
VoteWrapper row = voteEntries.getRowData(); EntryWrapper row = voteEntries.getRowData();
Integer vote = (Integer) rateEvent.getRating() - 3; Integer vote = (Integer) rateEvent.getRating() - 3;
if (vote < -2 || vote > 2) if (vote < -2 || vote > 2)
{ {
...@@ -91,7 +91,7 @@ public class CompoView extends GenericCDIView { ...@@ -91,7 +91,7 @@ public class CompoView extends GenericCDIView {
} }
public String saveVotes() { public String saveVotes() {
for (VoteWrapper vw : voteEntries) for (EntryWrapper vw : voteEntries)
{ {
votbean.saveVote(vw.getEntry(), vw.getVote()); votbean.saveVote(vw.getEntry(), vw.getVote());
} }
...@@ -193,12 +193,12 @@ public class CompoView extends GenericCDIView { ...@@ -193,12 +193,12 @@ public class CompoView extends GenericCDIView {
this.entryId = entryId; this.entryId = entryId;
} }
public ListDataModel<VoteWrapper> getVoteEntries() { public ListDataModel<EntryWrapper> getVoteEntries() {
logger.info("Getting {} entries ", voteEntries.getRowCount()); logger.info("Getting {} entries ", voteEntries.getRowCount());
return voteEntries; return voteEntries;
} }
public void setVoteEntries(ListDataModel<VoteWrapper> voteEntries) { public void setVoteEntries(ListDataModel<EntryWrapper> voteEntries) {
this.voteEntries = voteEntries; this.voteEntries = voteEntries;
} }
......
...@@ -13,36 +13,45 @@ import fi.insomnia.bortal.beans.VotingBeanLocal; ...@@ -13,36 +13,45 @@ import fi.insomnia.bortal.beans.VotingBeanLocal;
import fi.insomnia.bortal.model.CompoEntry; import fi.insomnia.bortal.model.CompoEntry;
import fi.insomnia.bortal.model.Vote; import fi.insomnia.bortal.model.Vote;
public class VoteWrapper implements Serializable { public class EntryWrapper implements Serializable {
/** /**
* *
*/ */
private static final long serialVersionUID = -8261328741517788115L; private static final long serialVersionUID = -8261328741517788115L;
private Integer votetotal;
private final CompoEntry entry; private final CompoEntry entry;
private Integer vote = 0; private Integer vote = 0;
private static final Logger logger = LoggerFactory.getLogger(VoteWrapper.class); private static final Logger logger = LoggerFactory.getLogger(EntryWrapper.class);
public VoteWrapper(CompoEntry entry, Vote voteEntity) { public EntryWrapper(CompoEntry entry, Vote voteEntity, boolean calcSummary) {
this.entry = entry; this.entry = entry;
if (voteEntity != null) if (voteEntity != null)
{ {
vote = voteEntity.getScore(); vote = voteEntity.getScore();
} }
if (calcSummary) {
votetotal = 0;
for (Vote v : entry.getVotes()) {
votetotal += v.getScore();
}
}
} }
public static ListDataModel<VoteWrapper> init(List<CompoEntry> compoEntries, VotingBeanLocal votbean) { public static ListDataModel<EntryWrapper> init(List<CompoEntry> compoEntries, VotingBeanLocal votbean, boolean calcSummary) {
ArrayList<VoteWrapper> ret = new ArrayList<VoteWrapper>(); ArrayList<EntryWrapper> ret = new ArrayList<EntryWrapper>();
for (CompoEntry entry : compoEntries) for (CompoEntry entry : compoEntries)
{ {
if (entry.getSort() != null && entry.getSort() > 0) if (entry.getSort() != null && entry.getSort() > 0)
{ {
Vote voteEntity = votbean.saveVote(entry, null); Vote voteEntity = votbean.saveVote(entry, null);
ret.add(new VoteWrapper(entry, voteEntity)); EntryWrapper wrap = new EntryWrapper(entry, voteEntity, calcSummary);
ret.add(wrap);
} }
} }
return new ListDataModel<VoteWrapper>(ret); return new ListDataModel<EntryWrapper>(ret);
} }
public CompoEntry getEntry() { public CompoEntry getEntry() {
...@@ -61,12 +70,17 @@ public class VoteWrapper implements Serializable { ...@@ -61,12 +70,17 @@ public class VoteWrapper implements Serializable {
} }
} }
public int getRatingVote() public Integer getVotetotal()
{
return votetotal;
}
public Integer getRatingVote()
{ {
return vote + 3; return vote + 3;
} }
public void setRatingVote(int vot) public void setRatingVote(Integer vot)
{ {
if (vot < 1 || vot > 5) if (vot < 1 || vot > 5)
{ {
......
...@@ -11,7 +11,6 @@ import org.slf4j.LoggerFactory; ...@@ -11,7 +11,6 @@ import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.VotingBeanLocal; import fi.insomnia.bortal.beans.VotingBeanLocal;
import fi.insomnia.bortal.enums.apps.CompoPermission; import fi.insomnia.bortal.enums.apps.CompoPermission;
import fi.insomnia.bortal.model.Compo; import fi.insomnia.bortal.model.Compo;
import fi.insomnia.bortal.model.CompoEntry;
import fi.insomnia.bortal.web.cdiview.GenericCDIView; import fi.insomnia.bortal.web.cdiview.GenericCDIView;
@Named @Named
...@@ -31,7 +30,7 @@ public class VotingDetailsView extends GenericCDIView { ...@@ -31,7 +30,7 @@ public class VotingDetailsView extends GenericCDIView {
private Compo compo; private Compo compo;
private ListDataModel<CompoEntry> entries; private ListDataModel<EntryWrapper> entries;
private static final Logger logger = LoggerFactory.getLogger(VotingDetailsView.class); private static final Logger logger = LoggerFactory.getLogger(VotingDetailsView.class);
...@@ -41,11 +40,11 @@ public class VotingDetailsView extends GenericCDIView { ...@@ -41,11 +40,11 @@ public class VotingDetailsView extends GenericCDIView {
public String saveSort() public String saveSort()
{ {
for (CompoEntry e : entries) for (EntryWrapper e : entries)
{ {
setCompo(votingBean.saveSort(e).getCompo()); setCompo(votingBean.saveSort(e.getEntry()).getCompo());
} }
entries = new ListDataModel<CompoEntry>(getCompo().getCompoEntries()); entries = EntryWrapper.init(getCompo().getCompoEntries(), votingBean, true);
return null; return null;
} }
...@@ -54,7 +53,7 @@ public class VotingDetailsView extends GenericCDIView { ...@@ -54,7 +53,7 @@ public class VotingDetailsView extends GenericCDIView {
this.compoId = compoId; this.compoId = compoId;
} }
public ListDataModel<CompoEntry> getEntries() { public ListDataModel<EntryWrapper> getEntries() {
return entries; return entries;
} }
...@@ -62,7 +61,7 @@ public class VotingDetailsView extends GenericCDIView { ...@@ -62,7 +61,7 @@ public class VotingDetailsView extends GenericCDIView {
if (super.requirePermissions(CompoPermission.MANAGE)) if (super.requirePermissions(CompoPermission.MANAGE))
{ {
setCompo(votingBean.getCompoById(compoId)); setCompo(votingBean.getCompoById(compoId));
entries = new ListDataModel<CompoEntry>(getCompo().getCompoEntries()); entries = EntryWrapper.init(getCompo().getCompoEntries(), votingBean, true);
super.beginConversation(); super.beginConversation();
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!