From: <jbo...@li...> - 2006-05-05 23:06:12
|
Author: soh...@jb... Date: 2006-05-05 19:06:00 -0400 (Fri, 05 May 2006) New Revision: 4105 Added: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/PollController.java labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_ballot.xhtml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_result.xhtml Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Constants.java labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumUtil.java labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/classes/ResourceJSF.properties labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums.taglib.xml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml Log: http://jira.jboss.com/jira/browse/JBFORUMS-69 - Post a Vote Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Constants.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Constants.java 2006-05-05 15:25:23 UTC (rev 4104) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Constants.java 2006-05-05 23:06:00 UTC (rev 4105) @@ -46,6 +46,8 @@ public static final String p_poll_title = "POLL_TITLE"; public static final String p_poll_delete = "POLL_DELETE"; public static final String p_attachment = "ATTACHMENT"; + public static final String p_vote = "vote"; + public static final String p_results = "results"; //other constants------------------------------------------------------------------------------------------------------------------------------- public static final String QUOTE = "quote"; Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumUtil.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumUtil.java 2006-05-05 15:25:23 UTC (rev 4104) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumUtil.java 2006-05-05 23:06:00 UTC (rev 4105) @@ -21,8 +21,11 @@ */ package org.jboss.portlet.forums.ui; +import java.text.DecimalFormat; + import javax.portlet.ActionRequest; + /** * @author <a href="mailto:soh...@jb...">Sohil Shah</a> * @@ -56,5 +59,20 @@ parameter = request.getParameter(param); return parameter; + } + + /** + * + * + */ + public static String getPercentStr(double input) + { + String percent = ""; + + DecimalFormat decimalFormat = new DecimalFormat("##.##%"); + percent = decimalFormat.format(input); + + + return percent; } } Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java 2006-05-05 15:25:23 UTC (rev 4104) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java 2006-05-05 23:06:00 UTC (rev 4105) @@ -62,7 +62,9 @@ String attachment = ForumUtil.getParameter(request,Constants.p_attachment); String topicId = ForumUtil.getParameter(request,Constants.p_topicId); String postId = ForumUtil.getParameter(request,Constants.p_postId); - String userId = ForumUtil.getParameter(request,Constants.p_userId); + String userId = ForumUtil.getParameter(request,Constants.p_userId); + String vote = ForumUtil.getParameter(request,Constants.p_vote); + String results = ForumUtil.getParameter(request,Constants.p_results); if(categoryId!=null && categoryId.trim().length()>0) { response.setRenderParameter(Constants.p_categoryId,categoryId); @@ -98,6 +100,14 @@ if(postId!=null && postId.trim().length()>0) { response.setRenderParameter(Constants.p_postId,postId); - } + } + if(vote!=null && vote.trim().length()>0) + { + response.setRenderParameter(Constants.p_vote,vote); + } + if(results!=null && results.trim().length()>0) + { + response.setRenderParameter(Constants.p_results,results); + } } } Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java 2006-05-05 15:25:23 UTC (rev 4104) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java 2006-05-05 23:06:00 UTC (rev 4105) @@ -21,7 +21,6 @@ */ package org.jboss.portlet.forums.ui; -import java.lang.reflect.Field; import java.util.Date; @@ -29,7 +28,6 @@ import java.text.SimpleDateFormat; -import java.util.Iterator; import java.util.Map; import org.apache.log4j.Logger; @@ -58,12 +56,9 @@ import org.jboss.portlet.forums.impl.PollOptionImpl; import org.jboss.portlet.forums.model.Message; import org.jboss.portlet.forums.impl.MessageImpl; -import org.jboss.portlet.forums.model.UploadedFile; -import org.jboss.portlet.forums.impl.UploadedFileImpl; -import org.jboss.portlet.forums.model.Attachment; -import org.jboss.portlet.forums.impl.AttachmentImpl; + /** * @author <a href="mailto:soh...@jb...">Sohil Shah</a> * @author <a href="mailto:rys...@jb...">Ryszard Kozmik</a> @@ -314,4 +309,21 @@ Message message = new MessageImpl(); return message; } + + /** + * + * + */ + public static float getVotePercent(Poll poll,PollOption option) + { + float votePercent = 0; + + float votesSum = poll.getVotesSum(); + if(votesSum>0) + { + votePercent = (option.getVotes()/votesSum); + } + + return votePercent; + } } Added: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/PollController.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/PollController.java 2006-05-05 15:25:23 UTC (rev 4104) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/PollController.java 2006-05-05 23:06:00 UTC (rev 4105) @@ -0,0 +1,95 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2005, JBoss Inc., and individual contributors as indicated +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* This is free software; you can redistribute it and/or modify it +* under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ +package org.jboss.portlet.forums.ui.action; + +import org.jboss.portlet.forums.ui.*; + +import org.jboss.portlet.forums.model.Topic; +import org.jboss.portlet.forums.model.Poll; +import org.jboss.portlet.forums.model.PollOption; +import org.jboss.portlet.forums.model.Poster; + +/* + * Created on May 5, 2006 + * + * @author <a href="mailto:soh...@jb...">Sohil Shah</a> + */ +public class PollController extends ActionController +{ + /** + * + * Created on May 5, 2006 + * + * @author <a href="mailto:soh...@jb...">Sohil Shah</a> + */ + public PollController() + { + } + + /** + * accepts a vote and processes it + * + */ + public String vote() + { + String navState = null; + try + { + String t = ForumUtil.getParameter(Constants.p_topicId); + String vote = ForumUtil.getParameter(Constants.p_vote); + + if(t!=null && t.trim().length()>0) + { + //setup the data needed for this process + int topicId,voteIndex; + try + { + topicId = Integer.parseInt(t); + voteIndex = Integer.parseInt(vote); + } + catch(NumberFormatException e) + { + //dont process a vote + return null; + } + + + Topic topic = this.getForumsModule().findTopicById(new Integer(topicId)); + Poll poll = topic.getPoll(); + PollOption selectedOption = (PollOption)poll.getOptions().get(voteIndex); + Poster poster = PortalUtil.getPoster(); + + //perform the voting on the selected option + if(poster!=null) + { + poll.getVoted().add(poster.getUserId()); + } + selectedOption.incVotes(); + } + } + catch(Exception e) + { + JSFUtil.handleException(e); + } + return navState; + } +} Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java 2006-05-05 15:25:23 UTC (rev 4104) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java 2006-05-05 23:06:00 UTC (rev 4105) @@ -78,6 +78,43 @@ return postDays; } + /** + * + * + */ + public boolean isPollPresent() + { + boolean isPollPresent = false; + + if( this.topic.getPoll()!= null && + this.topic.getPoll().getId() != null && + this.topic.getPoll().getId().intValue()>0 && + this.topic.getPoll().getOptions() != null && + !this.topic.getPoll().getOptions().isEmpty() + ) + { + isPollPresent = true; + } + + return isPollPresent; + } + + /** + * + * + */ + public boolean isBallotView() + { + boolean isBallotView = true; //in ballot view by default + + String result = ForumUtil.getParameter(Constants.p_results); + if(result!=null && result.trim().length()>0) + { + isBallotView = false; + } + + return isBallotView; + } //------------user preferences------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------------------------------- Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/classes/ResourceJSF.properties =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/classes/ResourceJSF.properties 2006-05-05 15:25:23 UTC (rev 4104) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/classes/ResourceJSF.properties 2006-05-05 23:06:00 UTC (rev 4105) @@ -381,6 +381,7 @@ View_previous_topic=View previous topic Submit_vote=Submit Vote View_results=View Results +View_ballot=View Ballot No_newer_topics=There are no newer topics in this forum No_older_topics=There are no older topics in this forum Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml 2006-05-05 15:25:23 UTC (rev 4104) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml 2006-05-05 23:06:00 UTC (rev 4105) @@ -236,7 +236,7 @@ <from-outcome>startEditPost</from-outcome> <to-view-id>/views/topics/posting_edit_body.xhtml</to-view-id> </navigation-case> - </navigation-rule> + </navigation-rule> <!-- managedBean for the jumpbox usecase --> <managed-bean> @@ -277,4 +277,11 @@ <to-view-id>/views/forums/viewforum_body.xhtml</to-view-id> </navigation-case> </navigation-rule> + + <!-- managed bean for the voting/poll stuff --> + <managed-bean> + <managed-bean-name>pollController</managed-bean-name> + <managed-bean-class>org.jboss.portlet.forums.ui.action.PollController</managed-bean-class> + <managed-bean-scope>request</managed-bean-scope> + </managed-bean> </faces-config> \ No newline at end of file Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums.taglib.xml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums.taglib.xml 2006-05-05 15:25:23 UTC (rev 4104) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums.taglib.xml 2006-05-05 23:06:00 UTC (rev 4105) @@ -52,4 +52,23 @@ <function-class>org.jboss.portlet.forums.ui.JSFUtil</function-class> <function-signature>java.lang.String getErrorMsg()</function-signature> </function> + + <!-- + --> + <function> + <function-name>percentStr</function-name> + <function-class>org.jboss.portlet.forums.ui.ForumUtil</function-class> + <function-signature>java.lang.String getPercentStr(double)</function-signature> + </function> + + + <!-- application specific functions --> + <!-- + function calculates the vote percent for the specified poll option + --> + <function> + <function-name>votePercent</function-name> + <function-class>org.jboss.portlet.forums.ui.PortalUtil</function-class> + <function-signature>float getVotePercent(org.jboss.portlet.forums.model.Poll,org.jboss.portlet.forums.model.PollOption)</function-signature> + </function> </facelet-taglib> \ No newline at end of file Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml 2006-05-05 15:25:23 UTC (rev 4104) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml 2006-05-05 23:06:00 UTC (rev 4105) @@ -147,6 +147,7 @@ </table> <table class="forumline" width="100%" cellspacing="1" cellpadding="3" border="0"> + <!-- TODO: hook in the previous/next topic function --> <!--tr align="right"> <td class="catHead" colspan="2" height="28"><span class="nav"><a href="${n:out("U_VIEW_OLDER_TOPIC")}" class="nav">${n:i18n("View_previous_topic")}</a> :: <a href="${n:out("U_VIEW_NEWER_TOPIC")}" class="nav">${n:i18n("View_next_topic")}</a> </span></td> </tr--> @@ -158,10 +159,25 @@ <include page="viewtopic_poll_result.jsp"/> </if> --> - <tr> - <th class="thLeft" width="150" height="26" nowrap="nowrap">${resource.Author}</th> - <th class="thRight" nowrap="nowrap">${resource.Message}</th> - </tr> + <!-- POLL DISPLAY --> + <c:if test="#{topic.pollPresent && topic.ballotView}"> + <ui:include src="/views/topics/viewtopic_poll_ballot.xhtml"> + <ui:param name="t" value="#{topic.topic.id}"/> + <ui:param name="poll" value="#{topic.topic.poll}"/> + </ui:include> + </c:if> + <c:if test="#{topic.pollPresent && !topic.ballotView}"> + <ui:include src="/views/topics/viewtopic_poll_result.xhtml"> + <ui:param name="t" value="#{topic.topic.id}"/> + <ui:param name="poll" value="#{topic.topic.poll}"/> + </ui:include> + </c:if> + + + <tr> + <th class="thLeft" width="150" height="26" nowrap="nowrap">${resource.Author}</th> + <th class="thRight" nowrap="nowrap">${resource.Message}</th> + </tr> <!-- iterate and display each post on this topic in the forum --> <c:forEach items="#{topic.topic.posts}" var="postrow" varStatus="status" > Added: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_ballot.xhtml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_ballot.xhtml 2006-05-05 15:25:23 UTC (rev 4104) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_ballot.xhtml 2006-05-05 23:06:00 UTC (rev 4105) @@ -0,0 +1,88 @@ +<!-- +/* +* JBoss, Home of Professional Open Source +* Copyright 2005, JBoss Inc., and individual contributors as indicated +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* This is free software; you can redistribute it and/or modify it +* under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ +--> + +<div xmlns="http://www.w3.org/1999/xhtml" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:c="http://java.sun.com/jstl/core" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:t="http://myfaces.apache.org/tomahawk" + xmlns:forums="http://www.jboss.com/products/jbossportal/forums" + class="bb" +> + +<ui:composition template="/views/common/common.xhtml"> +<ui:define name="mainContent"> + +<tr> + <td class="row2" colspan="2"><br clear="all"/> + <h:form> + <input type="hidden" name="t" value="#{t}"/> + <table cellspacing="0" cellpadding="4" border="0" align="center"> + <tr> + <td align="center"><span class="gen"><b>#{poll.title}</b></span></td> + </tr> + <tr> + <td align="center"> + <table cellspacing="0" cellpadding="2" border="0"> + <c:forEach items="#{poll.options}" var="optionrow" varStatus="status"> + <tr> + <td> + <input type="radio" name="vote" value="#{(status.index)-1}"/> + &nbsp; + </td> + <td> + <span class="gen">#{optionrow.question}</span> + </td> + </tr> + </c:forEach> + </table> + </td> + </tr> + <tr> + <td align="center"> + <h:commandButton action="#{pollController.vote}" value="${resource.Submit_vote}" styleClass="liteoption"/> + </td> + </tr> + <tr> + <td align="center"><span class="gensmall"> + <b> + <!-- view results link --> + <h:outputLink value="#{forums:outputLink(shared.links['topic'],true)}" styleClass="gensmall"> + <f:param name="t" value="${t}"/> + <f:param name="results" value="1"/> + <h:outputText value="${resource.View_results}"/> + </h:outputLink> + </b></span> + </td> + </tr> + </table> + </h:form> + </td> +</tr> + +</ui:define> +</ui:composition> + +</div> \ No newline at end of file Added: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_result.xhtml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_result.xhtml 2006-05-05 15:25:23 UTC (rev 4104) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_result.xhtml 2006-05-05 23:06:00 UTC (rev 4105) @@ -0,0 +1,111 @@ +<!-- +/* +* JBoss, Home of Professional Open Source +* Copyright 2005, JBoss Inc., and individual contributors as indicated +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* This is free software; you can redistribute it and/or modify it +* under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ +--> + +<div xmlns="http://www.w3.org/1999/xhtml" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:c="http://java.sun.com/jstl/core" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:t="http://myfaces.apache.org/tomahawk" + xmlns:forums="http://www.jboss.com/products/jbossportal/forums" + class="bb" +> + +<ui:composition template="/views/common/common.xhtml"> +<ui:define name="mainContent"> + +<tr> + <td class="row2" colspan="2"><br clear="all"/> + <table cellspacing="0" cellpadding="4" border="0" align="center"> + <!-- title --> + <tr> + <td align="center"><span class="gen"><b>#{poll.title}</b></span></td> + </tr> + <!-- option results --> + <tr> + <td align="center"> + <table cellspacing="0" cellpadding="2" border="0"> + <c:forEach items="#{poll.options}" var="optionrow" varStatus="status"> + <tr> + <td><span class="gen">#{optionrow.question}</span></td> + <td> + <table cellspacing="0" cellpadding="0" border="0"> + <tr> + <td> + <img src="#{forums:themeURL('resourcePollVotingLBar')}" width="4" height="12" alt=""/> + </td> + <td> + <img src="#{forums:themeURL('resourcePollVotingBar')}" + width="#{(forums:votePercent(poll,optionrow))*205}" + height="12" + alt=""/> + </td> + <td> + <img src="#{forums:themeURL('resourcePollVotingRBar')}" width="4" height="12" alt=""/> + </td> + </tr> + </table> + </td> + <td align="center"> + <b> + <span class="gen"> + &nbsp;${forums:percentStr(forums:votePercent(poll,optionrow))}&nbsp; + </span> + </b> + </td> + <td align="center"> + <span class="gen">[ #{optionrow.votes} ]</span> + </td> + </tr> + </c:forEach> + </table> + </td> + </tr> + <!-- total result --> + <tr> + <td colspan="4" align="center"> + <span class="gen"><b>${resource.Total_votes} : #{poll.votesSum}</b></span> + </td> + </tr> + <!-- switch back to the voting screen --> + <tr> + <td align="center"><span class="gensmall"> + <b> + <!-- view results link --> + <h:outputLink value="#{forums:outputLink(shared.links['topic'],true)}" styleClass="gensmall"> + <f:param name="t" value="${t}"/> + <h:outputText value="${resource.View_ballot}"/> + </h:outputLink> + </b> + </span> + </td> + </tr> + </table> + </td> +</tr> + +</ui:define> +</ui:composition> + +</div> \ No newline at end of file |