Commit 3d8d4ac1 by Tuomas Riihimäki

Compo voting, muokkaus, ym

1 parent a339c322
...@@ -294,13 +294,13 @@ public class TestDataBean implements TestDataBeanLocal { ...@@ -294,13 +294,13 @@ public class TestDataBean implements TestDataBeanLocal {
CompoEntry compoEntry1 = new CompoEntry(); CompoEntry compoEntry1 = new CompoEntry();
compoEntry1.setCompo(compo); compoEntry1.setCompo(compo);
compoEntry1.setCreated(Calendar.getInstance()); compoEntry1.setCreated(Calendar.getInstance());
compoEntry1.setName("Test entry for test compo"); compoEntry1.setTitle("Test entry for test compo");
compoEntryFacade.create(compoEntry1); compoEntryFacade.create(compoEntry1);
CompoEntry compoEntry2 = new CompoEntry(); CompoEntry compoEntry2 = new CompoEntry();
compoEntry2.setCompo(compo); compoEntry2.setCompo(compo);
compoEntry2.setCreated(Calendar.getInstance()); compoEntry2.setCreated(Calendar.getInstance());
compoEntry2.setName("Another test entry for test compo"); compoEntry2.setTitle("Another test entry for test compo");
compoEntryFacade.create(compoEntry2); compoEntryFacade.create(compoEntry2);
} }
......
...@@ -10,6 +10,9 @@ import javax.ejb.EJB; ...@@ -10,6 +10,9 @@ import javax.ejb.EJB;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.enums.apps.CompoPermission; import fi.insomnia.bortal.enums.apps.CompoPermission;
import fi.insomnia.bortal.facade.CompoEntryFacade; import fi.insomnia.bortal.facade.CompoEntryFacade;
import fi.insomnia.bortal.facade.CompoEntryFileFacade; import fi.insomnia.bortal.facade.CompoEntryFileFacade;
...@@ -18,6 +21,7 @@ import fi.insomnia.bortal.facade.VoteFacade; ...@@ -18,6 +21,7 @@ import fi.insomnia.bortal.facade.VoteFacade;
import fi.insomnia.bortal.model.Compo; import fi.insomnia.bortal.model.Compo;
import fi.insomnia.bortal.model.CompoEntry; import fi.insomnia.bortal.model.CompoEntry;
import fi.insomnia.bortal.model.CompoEntryFile; import fi.insomnia.bortal.model.CompoEntryFile;
import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.model.Vote; import fi.insomnia.bortal.model.Vote;
/** /**
...@@ -42,6 +46,7 @@ public class VotingBean implements VotingBeanLocal { ...@@ -42,6 +46,7 @@ public class VotingBean implements VotingBeanLocal {
private EventBean eventBean; private EventBean eventBean;
@EJB @EJB
private PermissionBeanLocal permissionBean; private PermissionBeanLocal permissionBean;
private static final Logger logger = LoggerFactory.getLogger(VotingBean.class);
/** /**
* Default constructor. * Default constructor.
...@@ -116,4 +121,42 @@ public class VotingBean implements VotingBeanLocal { ...@@ -116,4 +121,42 @@ public class VotingBean implements VotingBeanLocal {
return compoEntryFacade.find(entryId); return compoEntryFacade.find(entryId);
} }
@Override
public CompoEntry saveSort(CompoEntry e) {
CompoEntry entry = compoEntryFacade.find(e.getId());
entry.setSort(e.getSort());
return entry;
}
@Override
public Vote saveVote(CompoEntry entry, Integer vote) {
entry = compoEntryFacade.find(entry.getId());
EventUser user = permissionBean.getCurrentUser();
Vote voteEntity = voteFacade.find(entry, user);
if (vote != null)
{
if (voteEntity == null)
{
voteEntity = new Vote();
if (user.getVotes() == null) {
user.setVotes(new ArrayList<Vote>());
}
if (entry.getVotes() == null) {
entry.setVotes(new ArrayList<Vote>());
}
voteEntity.setVoter(user);
user.getVotes().add(voteEntity);
voteEntity.setCompoEntry(entry);
entry.getVotes().add(voteEntity);
voteFacade.create(voteEntity);
}
voteEntity.setScore(vote);
logger.info("Setting vote to {} on {}", vote, voteEntity);
voteEntity.setTime(Calendar.getInstance());
}
return voteEntity;
}
} }
...@@ -2,8 +2,14 @@ package fi.insomnia.bortal.facade; ...@@ -2,8 +2,14 @@ package fi.insomnia.bortal.facade;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import fi.insomnia.bortal.model.CompoEntry;
import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.model.Vote; import fi.insomnia.bortal.model.Vote;
import fi.insomnia.bortal.model.Vote_;
@Stateless @Stateless
@LocalBean @LocalBean
...@@ -13,4 +19,14 @@ public class VoteFacade extends IntegerPkGenericFacade<Vote> { ...@@ -13,4 +19,14 @@ public class VoteFacade extends IntegerPkGenericFacade<Vote> {
super(Vote.class); super(Vote.class);
} }
public Vote find(CompoEntry entry, EventUser user) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Vote> cq = cb.createQuery(Vote.class);
Root<Vote> root = cq.from(Vote.class);
cq.where(cb.equal(root.get(Vote_.voter), user),
cb.equal(root.get(Vote_.compoEntry), entry)
);
return super.getSingleNullableResult(getEm().createQuery(cq));
}
} }
...@@ -7,6 +7,7 @@ import javax.ejb.Local; ...@@ -7,6 +7,7 @@ import javax.ejb.Local;
import fi.insomnia.bortal.model.Compo; import fi.insomnia.bortal.model.Compo;
import fi.insomnia.bortal.model.CompoEntry; import fi.insomnia.bortal.model.CompoEntry;
import fi.insomnia.bortal.model.CompoEntryFile; import fi.insomnia.bortal.model.CompoEntryFile;
import fi.insomnia.bortal.model.Vote;
@Local @Local
public interface VotingBeanLocal { public interface VotingBeanLocal {
...@@ -28,4 +29,8 @@ public interface VotingBeanLocal { ...@@ -28,4 +29,8 @@ public interface VotingBeanLocal {
public CompoEntry findEntry(Integer entryId); public CompoEntry findEntry(Integer entryId);
public CompoEntry saveSort(CompoEntry e);
public Vote saveVote(CompoEntry entry, Integer vote);
} }
...@@ -42,8 +42,11 @@ public class CompoEntry extends GenericEntity { ...@@ -42,8 +42,11 @@ public class CompoEntry extends GenericEntity {
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar created = Calendar.getInstance(); private Calendar created = Calendar.getInstance();
@Column(name = "entry_name", nullable = false) @Column(name = "title", nullable = false)
private String name; private String title;
@Column(name = "author")
private String author;
@Lob @Lob
@Column(name = "notes") @Column(name = "notes")
...@@ -89,14 +92,6 @@ public class CompoEntry extends GenericEntity { ...@@ -89,14 +92,6 @@ public class CompoEntry extends GenericEntity {
this.created = entryCreated; this.created = entryCreated;
} }
public String getName() {
return name;
}
public void setName(String entryName) {
this.name = entryName;
}
public String getNotes() { public String getNotes() {
return notes; return notes;
} }
...@@ -178,4 +173,20 @@ public class CompoEntry extends GenericEntity { ...@@ -178,4 +173,20 @@ public class CompoEntry extends GenericEntity {
return currentFile; return currentFile;
} }
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
} }
...@@ -44,7 +44,7 @@ public class EventUser extends GenericEntity implements IUser { ...@@ -44,7 +44,7 @@ public class EventUser extends GenericEntity implements IUser {
private static final long serialVersionUID = 6042691271548196815L; private static final long serialVersionUID = 6042691271548196815L;
@OneToMany(mappedBy = "voter", cascade = CascadeType.ALL) @OneToMany(mappedBy = "voter")
private List<Vote> votes; private List<Vote> votes;
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL) @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
......
$(document).ready(function() {
$(".rating-cancel").hide();
alert("trying to hide");
});
\ No newline at end of file
...@@ -13,6 +13,18 @@ body,html { ...@@ -13,6 +13,18 @@ body,html {
margin: 0 auto; margin: 0 auto;
} }
td span span div.rating-cancel
{
display: none;
}
#voteform div.rating-cancel
{
display: none;
}
#logo { #logo {
width: 255px; width: 255px;
height: 52px; height: 52px;
......
td span span div.rating-cancel {
display: none;
}
div.rating-cancel {
display: none;
}
\ No newline at end of file
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
</h:outputText> </h:outputText>
</h:column> </h:column>
<h:column> <h:column>
<h:commandButton rendered="#{compo.vote or compoView.manage}" action="#{compoView.vote()}" value="#{i18n['voting.compo.vote']}" /> <h:commandButton rendered="#{compo.vote or compoView.manage}" action="#{compoView.startVote()}" value="#{i18n['voting.compo.vote']}" />
</h:column> </h:column>
<h:column> <h:column>
<h:commandButton rendered="#{compo.submit or compoView.manage}" action="#{compoView.submitEntry()}" value="#{i18n['voting.compo.submit']}" /> <h:commandButton rendered="#{compo.submit or compoView.manage}" action="#{compoView.submitEntry()}" value="#{i18n['voting.compo.submit']}" />
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
</f:metadata> </f:metadata>
<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>Compo: #{votingDetailsView.compoName}</h1> <h1>Compo: #{votingDetailsView.compo.name}</h1>
<p>Infoa compon entryistä</p> <p>Infoa compon entryistä</p>
...@@ -21,9 +21,15 @@ ...@@ -21,9 +21,15 @@
<h:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{votingDetailsView.entries}" var="entry"> <h:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{votingDetailsView.entries}" var="entry">
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="nimi" /> <h:outputText value="Title" />
</f:facet> </f:facet>
<h:outputText value="#{entry.name}" /> <h:outputText value="#{entry.title}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Author" />
</f:facet>
<h:outputText value="#{entry.author}" />
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
...@@ -41,13 +47,13 @@ ...@@ -41,13 +47,13 @@
<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.wholeName}" /> <h:outputText value="#{entry.creator.user.wholeName} / #{entry.creator.nick}" />
</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:outputText value="#{entry.sort}" /> <h:inputText value="#{entry.sort}" />
</h:column> </h:column>
<h:column> <h:column>
...@@ -57,7 +63,7 @@ ...@@ -57,7 +63,7 @@
</h:column> </h:column>
</h:dataTable> </h:dataTable>
<h:commandButton action="#{votingDetailsView.saveSort}" value="#{i18n['compo.savesort']}" />
</h:form> </h:form>
......
...@@ -17,9 +17,15 @@ ...@@ -17,9 +17,15 @@
<h:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{userView.user.compoEntries}" var="entry"> <h:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{userView.user.compoEntries}" var="entry">
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="Name" /> <h:outputText value="Title" />
</f:facet> </f:facet>
<h:outputText value="#{entry.name}" /> <h:outputText value="#{entry.title}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Author" />
</f:facet>
<h:outputText value="#{entry.author}" />
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
......
...@@ -17,10 +17,14 @@ ...@@ -17,10 +17,14 @@
<h:form> <h:form>
<h:panelGrid columns="3"> <h:panelGrid columns="3">
<h:outputLabel value="#{i18n['voting.compoentryadd.entryname']}" for="name" /> <h:outputLabel value="Title" for="name" />
<h:inputText value="#{compoView.entry.name}" id="name" /> <h:inputText value="#{compoView.entry.title}" id="name" />
<h:message for="name" /> <h:message for="name" />
<h:outputLabel value="Author" for="author" />
<h:inputText value="#{compoView.entry.author}" id="author" />
<h:message for="author" />
<h:outputLabel value="#{i18n['voting.compoentryadd.notes']}" for="notes" /> <h:outputLabel value="#{i18n['voting.compoentryadd.notes']}" for="notes" />
<h:inputTextarea value="#{compoView.entry.notes}" id="notes" /> <h:inputTextarea value="#{compoView.entry.notes}" id="notes" />
<h:message for="notes" /> <h:message for="notes" />
......
...@@ -7,53 +7,39 @@ ...@@ -7,53 +7,39 @@
<h:body> <h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml"> <ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<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>Compo: #{votingDetailsView.compoName}</h1> <h1>Vote in compo #{votingDetailsView.compoName}</h1>
<p>Infoa compon entryistä</p>
<h:form> <h:form id="voteform">
<h:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{compoView..entries}" var="entry"> <h:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="votetable" value="#{compoView.voteEntries}" var="entry">
<h:column> <h:column>
<f:facet name="header"> #<h:outputText value="#{entry.entry.sort}" />
<h:outputText value="nimi" />
</f:facet>
<h:outputText value="#{entry.name}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="notes" />
</f:facet>
<h:outputText value="#{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="Title" />
</f:facet> </f:facet>
<h:outputText value="#{entry.screenMessage}" /> <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="creator" /> <h:outputText value="Author" />
</f:facet> </f:facet>
<h:outputText value="#{entry.creator.wholeName}" /> <h:outputText value="#{entry.entry.author}" />
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <p:rating id="vote" value="#{entry.ratingVote}" cancel="true" stars="5" required="true">
<h:outputText value="sort" /> <p:ajax event="rate" listener="#{compoView.handleVoteRate}" update=":voteform" />
</f:facet> </p:rating>
<h:outputText value="#{entry.sort}" />
</h:column> </h:column>
<h:column> <h:column>
<h:link outcome="/voting/submitEntry" value="#{i18n['entry.edit']}"> <h:outputText value="#{entry.vote}" />
<f:param name="entryId" value="#{entry.id}" />
</h:link>
</h:column> </h:column>
</h:dataTable> </h:dataTable>
<h:commandButton action="#{compoView.saveVotes}" value="#{i18n['compo.saveVotes']}" />
</h:form> </h:form>
......
...@@ -72,6 +72,8 @@ cardTemplate.power = Card power ...@@ -72,6 +72,8 @@ cardTemplate.power = Card power
cardTemplate.roles = Associated roles cardTemplate.roles = Associated roles
compo.edit = Edit compo compo.edit = Edit compo
compo.saveVotes = Save votes
compo.votesSaved = Votes saved
compofile.download = Download compofile.download = Download
compofile.download.header = Download file compofile.download.header = Download file
......
...@@ -70,6 +70,8 @@ cardTemplate.power = Teho ...@@ -70,6 +70,8 @@ cardTemplate.power = Teho
cardTemplate.roles = Yhdistetyt roolit cardTemplate.roles = Yhdistetyt roolit
compo.edit = Muokkaa compoa compo.edit = Muokkaa compoa
compo.saveVotes = Tallenna \u00E4\u00E4net
compo.votesSaved = \u00C4\u00E4net tallennettu
compofile.download = lataa compofile.download = lataa
compofile.download.header = Lataa tiedosto compofile.download.header = Lataa tiedosto
......
...@@ -9,6 +9,8 @@ import javax.inject.Inject; ...@@ -9,6 +9,8 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import org.primefaces.model.DefaultStreamedContent; import org.primefaces.model.DefaultStreamedContent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.VotingBeanLocal; import fi.insomnia.bortal.beans.VotingBeanLocal;
import fi.insomnia.bortal.model.CompoEntry; import fi.insomnia.bortal.model.CompoEntry;
...@@ -29,6 +31,7 @@ public class CompoFileDownloadView extends GenericCDIView { ...@@ -29,6 +31,7 @@ public class CompoFileDownloadView extends GenericCDIView {
private CompoEntryFile file; private CompoEntryFile file;
private DefaultStreamedContent dlfile; private DefaultStreamedContent dlfile;
private static final Logger logger = LoggerFactory.getLogger(CompoFileDownloadView.class);
public ListDataModel<CompoEntryFile> getFiles() public ListDataModel<CompoEntryFile> getFiles()
{ {
...@@ -47,7 +50,9 @@ public class CompoFileDownloadView extends GenericCDIView { ...@@ -47,7 +50,9 @@ public class CompoFileDownloadView extends GenericCDIView {
this.file = file; this.file = file;
if (file != null) if (file != null)
{ {
dlfile = new DefaultStreamedContent(new ByteArrayInputStream(file.getFileData()), file.getMimeType(), file.getFileName()); dlfile = new DefaultStreamedContent(new ByteArrayInputStream(file.getFileData()), file.getMimeType(), file.getFileName());
logger.info("Uploading file {}, length {}", file.getFileName(), file.getFileData().length);
} }
} }
......
...@@ -8,6 +8,7 @@ import javax.enterprise.inject.Produces; ...@@ -8,6 +8,7 @@ import javax.enterprise.inject.Produces;
import javax.faces.model.ListDataModel; import javax.faces.model.ListDataModel;
import javax.inject.Named; import javax.inject.Named;
import org.primefaces.event.RateEvent;
import org.primefaces.model.UploadedFile; import org.primefaces.model.UploadedFile;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -47,6 +48,8 @@ public class CompoView extends GenericCDIView { ...@@ -47,6 +48,8 @@ public class CompoView extends GenericCDIView {
private Integer entryId; private Integer entryId;
private ListDataModel<VoteWrapper> voteEntries;
public ListDataModel<CompoWrapper> getCompos() { public ListDataModel<CompoWrapper> getCompos() {
return compolist; return compolist;
} }
...@@ -66,10 +69,34 @@ public class CompoView extends GenericCDIView { ...@@ -66,10 +69,34 @@ public class CompoView extends GenericCDIView {
} }
} }
public String voteCompo() public String startVote()
{ {
compo = compolist.getRowData().getCompo(); compo = compolist.getRowData().getCompo();
return "/votes/vote"; setVoteEntries(VoteWrapper.init(compo.getCompoEntries(), votbean));
logger.info("Initializing voting with entries {}, {}", compo.getCompoEntries().size(), voteEntries.getRowCount());
super.beginConversation();
return "/voting/vote";
}
public void handleVoteRate(RateEvent rateEvent)
{
VoteWrapper row = voteEntries.getRowData();
Integer vote = (Integer) rateEvent.getRating() - 3;
if (vote < -2 || vote > 2)
{
vote = 0;
}
votbean.saveVote(row.getEntry(), vote);
}
public String saveVotes() {
for (VoteWrapper vw : voteEntries)
{
votbean.saveVote(vw.getEntry(), vw.getVote());
}
super.addFaceMessage("compo.votesSaved");
return null;
} }
public String submitEntry() public String submitEntry()
...@@ -98,6 +125,7 @@ public class CompoView extends GenericCDIView { ...@@ -98,6 +125,7 @@ public class CompoView extends GenericCDIView {
{ {
CompoEntryFile cef = new CompoEntryFile(getEntry()); CompoEntryFile cef = new CompoEntryFile(getEntry());
cef.setFileData(this.getUploadedFile().getContents()); cef.setFileData(this.getUploadedFile().getContents());
logger.info("Got file name {} length {}", getUploadedFile().getFileName(), cef.getFileData().length);
cef.setFileName(getUploadedFile().getFileName()); cef.setFileName(getUploadedFile().getFileName());
cef.setMimeType(getUploadedFile().getContentType()); cef.setMimeType(getUploadedFile().getContentType());
if (getEntry().getFiles() == null) { if (getEntry().getFiles() == null) {
...@@ -165,4 +193,13 @@ public class CompoView extends GenericCDIView { ...@@ -165,4 +193,13 @@ public class CompoView extends GenericCDIView {
this.entryId = entryId; this.entryId = entryId;
} }
public ListDataModel<VoteWrapper> getVoteEntries() {
logger.info("Getting {} entries ", voteEntries.getRowCount());
return voteEntries;
}
public void setVoteEntries(ListDataModel<VoteWrapper> voteEntries) {
this.voteEntries = voteEntries;
}
} }
package fi.insomnia.bortal.web.cdiview.voting;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.VotingBeanLocal;
import fi.insomnia.bortal.model.CompoEntry;
import fi.insomnia.bortal.model.Vote;
public class VoteWrapper implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8261328741517788115L;
private final CompoEntry entry;
private Integer vote = 0;
private static final Logger logger = LoggerFactory.getLogger(VoteWrapper.class);
public VoteWrapper(CompoEntry entry, Vote voteEntity) {
this.entry = entry;
if (voteEntity != null)
{
vote = voteEntity.getScore();
}
}
public static ListDataModel<VoteWrapper> init(List<CompoEntry> compoEntries, VotingBeanLocal votbean) {
ArrayList<VoteWrapper> ret = new ArrayList<VoteWrapper>();
for (CompoEntry entry : compoEntries)
{
if (entry.getSort() != null && entry.getSort() > 0)
{
Vote voteEntity = votbean.saveVote(entry, null);
ret.add(new VoteWrapper(entry, voteEntity));
}
}
return new ListDataModel<VoteWrapper>(ret);
}
public CompoEntry getEntry() {
return entry;
}
public Integer getVote() {
return vote;
}
public void setVote(Integer vot) {
if (vot == null) {
this.vote = 0;
} else {
this.vote = vot;
}
}
public int getRatingVote()
{
return vote + 3;
}
public void setRatingVote(int vot)
{
if (vot < 1 || vot > 5)
{
vot = 3;
}
this.vote = vot - 3;
logger.info("setting ratevote {} to realvote {}", vot, vote);
}
}
...@@ -79,7 +79,7 @@ public class VotingCompoAddEntryView { ...@@ -79,7 +79,7 @@ public class VotingCompoAddEntryView {
public void send() { public void send() {
CompoEntry compoEntry = new CompoEntry(); CompoEntry compoEntry = new CompoEntry();
compoEntry.setName(name); compoEntry.setTitle(name);
compoEntry.setNotes(notes); compoEntry.setNotes(notes);
compoEntry.setScreenMessage(screenMessage); compoEntry.setScreenMessage(screenMessage);
compoEntry.setCompo(votingBean.getCompoById(compoId)); compoEntry.setCompo(votingBean.getCompoById(compoId));
...@@ -88,7 +88,7 @@ public class VotingCompoAddEntryView { ...@@ -88,7 +88,7 @@ public class VotingCompoAddEntryView {
cef.setFileName(uploadedFile.getFileName()); cef.setFileName(uploadedFile.getFileName());
votingBean.addEntry(compoEntry, cef); votingBean.addEntry(compoEntry, cef);
} }
public void initView() { public void initView() {
compoName = votingBean.getCompoById(compoId).getName(); compoName = votingBean.getCompoById(compoId).getName();
} }
......
package fi.insomnia.bortal.web.cdiview.voting; package fi.insomnia.bortal.web.cdiview.voting;
import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel;
import javax.inject.Named; import javax.inject.Named;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.VotingBeanLocal; import fi.insomnia.bortal.beans.VotingBeanLocal;
import fi.insomnia.bortal.web.cdiview.GenericCDIView; 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.model.CompoEntry;
import fi.insomnia.bortal.web.cdiview.GenericCDIView;
@Named @Named
@RequestScoped @ConversationScoped
public class VotingDetailsView extends GenericCDIView { public class VotingDetailsView extends GenericCDIView {
/** /**
* *
*/ */
private static final long serialVersionUID = -8373473936336396427L; private static final long serialVersionUID = -8373473936336396427L;
@EJB @EJB
private VotingBeanLocal votingBean; private VotingBeanLocal votingBean;
private Integer compoId; private Integer compoId;
private Integer compoId2;
private String compoName; private String compoName;
private Compo compo; private Compo compo;
private ListDataModel<CompoEntry> entries;
private static final Logger logger = LoggerFactory.getLogger(VotingDetailsView.class); private static final Logger logger = LoggerFactory.getLogger(VotingDetailsView.class);
public Integer getCompoId() { public Integer getCompoId() {
return compoId; return compoId;
} }
public String saveSort()
{
for (CompoEntry e : entries)
{
setCompo(votingBean.saveSort(e).getCompo());
}
entries = new ListDataModel<CompoEntry>(getCompo().getCompoEntries());
return null;
}
public void setCompoId(Integer compoId) { public void setCompoId(Integer compoId) {
this.compoId = compoId; this.compoId = compoId;
} }
public List<CompoEntry> getEntries(){
//return votingBean.getCompoById(compoId).getCompoEntries();
compo = votingBean.getCompoById(compoId);
logger.info("compoId " + compoId);
if(compo == null) {
return null;
}
return compo.getCompoEntries();
}
public void initView() {
compoName = votingBean.getCompoById(compoId).getName();
}
public Integer getCompoId2() { public ListDataModel<CompoEntry> getEntries() {
return compoId2; return entries;
} }
public void initView() {
public void setCompoId2(Integer compoId2) { if (super.requirePermissions(CompoPermission.MANAGE))
this.compoId2 = compoId2; {
setCompo(votingBean.getCompoById(compoId));
entries = new ListDataModel<CompoEntry>(getCompo().getCompoEntries());
super.beginConversation();
}
} }
public String getCompoName() { public String getCompoName() {
return compoName; return compoName;
} }
public void setCompoName(String compoName) { public void setCompoName(String compoName) {
this.compoName = compoName; this.compoName = compoName;
} }
public Compo getCompo() {
return compo;
}
public void setCompo(Compo compo) {
this.compo = compo;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!