Commits

OJ Reeves  committed ad94f99 Merge

Merged with Leon's changes after a little bit of a fight thanks to me mucking around too much.

  • Participants
  • Parent commits 8a32a5a, 6921e0b

Comments (0)

Files changed (16)

File CodeSmackdown.Domain/Services/SnippetService.cs

                 UserId = userId,
                 VoteValue = leftOrRight
             };
-            using (var transaction = _session.BeginTransaction())
+            try
             {
-                _session.Save(vote);
-                transaction.Commit();
+                using (var transaction = _session.BeginTransaction())
+                {
+                    _session.Save(vote);
+                    transaction.Commit();
+                }
+            }
+            catch (NHibernate.Exceptions.GenericADOException ex)
+            {
+                //So we don't give them the option to vote twice in the first place.
+                //But if they do vote twice, they end up here.
+                if (ex.InnerException.Message.Contains("Duplicate entry")) {
+                }
+             
             }
         }
     }

File CodeSmackdown.Site/CodeSmackdown.Site.csproj

     <Content Include="Images\pale_back_gradient20.png" />
     <Content Include="Images\silver_back_gradient.png" />
     <Content Include="Images\wmd-buttons.png" />
+    <Content Include="Scripts\color.js" />
     <Content Include="Scripts\csd.js" />
     <Content Include="Scripts\lang-css.js" />
     <Content Include="Scripts\lang-hs.js" />
     <Content Include="Scripts\showdown.js" />
     <Content Include="Scripts\wmd.js" />
     <None Include="Views\Accounts\View.spark" />
-    <None Include="Views\Shared\About.spark" />
+    <None Include="Views\Shared\About.spark">
+      <SubType>Designer</SubType>
+    </None>
     <None Include="Views\Shared\_InformationMessages.spark" />
     <None Include="Views\Shared\_TopMenu.spark" />
     <Content Include="Views\Web.config" />
     <None Include="Views\Shared\_Snippet.spark">
       <SubType>Designer</SubType>
     </None>
-    <None Include="Views\Snippets\Create.spark">
+    <None Include="Views\Snippets\Create.spark" />
+    <None Include="Views\Snippets\View.spark">
       <SubType>Designer</SubType>
     </None>
-    <None Include="Views\Snippets\View.spark" />
   </ItemGroup>
   <ItemGroup />
   <ItemGroup>
       </FlavorProperties>
     </VisualStudio>
   </ProjectExtensions>
-</Project>
+</Project>

File CodeSmackdown.Site/Content/Site.less

     background-image: url(../images/black_header_gradient.png);
 }
 
-td.code { padding: 25px; border: 1px solid #888; background-color: White; font-size: large; }
+td.code { padding: 25px; border: 1px solid #888; background-color: White; font-size: large;
+
+height:200px;
+ }
 
 div.comment
 {
         padding-right: 3px
     }
 }
+
+
+.barStyle
+{
+    background-color:#888;/*CCC;*/ 
+    width:50px; 
+    position:absolute;
+    border-right:2px solid #000;
+	border-bottom:2px solid #000;
+    clear:both;
+}   
+
+#leftSnippet, #rightSnippet {
+       /*width:500px; */
+       position:absolute;
+       top:250px;
+       height:225px;  
+	   
+}

File CodeSmackdown.Site/Controllers/SnippetsController.cs

 using CodeSmackdown.Domain.Services;
 using CodeSmackdown.Site.Extensions;
 using CodeSmackdown.Site.Models;
+using Spark.Web.Mvc;
 
 namespace CodeSmackdown.Site.Controllers
 {
             _snippetService = snippetService;
         }
 
-        [AcceptVerbs(HttpVerbs.Get)]
         public ActionResult Index()
         {
             return ViewSnippet(_snippetService.GetRandomSnippet());
         }
 
-        [AcceptVerbs(HttpVerbs.Get)]
         public ActionResult View(int id)
         {
             // attempt to see if we were redirected here first
 
             var data = new SnippetViewData
             {
-                CurrentUserVote = null,
+                CurrentUserVote = VoteValue.Left,
                 Snippet = snippet,
                 Votes = new Dictionary<VoteValue, int>
                 {
         public ActionResult VoteLeft(int snippetId)
         {
             _snippetService.Vote(snippetId, VoteValue.Left, CurrentUser.UserId);
-            return RedirectToAction("Results", new { id = snippetId });
+            return RedirectToAction("View", new { id = snippetId });
         }
 
         [Authorize]
         {
             _snippetService.Vote(snippetId, VoteValue.Right, CurrentUser.UserId);
 
-            return RedirectToAction("Results", new { id = snippetId });
+            return RedirectToAction("View", new { id = snippetId });
         }
 
         [Authorize]
         public ActionResult VoteNeither(int snippetId)
         {
             _snippetService.Vote(snippetId, VoteValue.Neither, CurrentUser.UserId);
-
-            return RedirectToAction("Results", new { id = snippetId });
+            return RedirectToAction("View", new { id = snippetId });            
         }
 
-        [Authorize]
-        public ActionResult Results(int id)
-        {
-            var snippet = _snippetService.GetSnippet(id);
+        //[Authorize]
+        //public ActionResult GoVoteLeft(int snippetId)
+        //{
+        //    _snippetService.Vote(snippetId, VoteValue.Left, CurrentUser.UserId);
+        //    var snippet = _snippetService.GetSnippet(snippetId);
             
-            return View();
-        }
+        //    var data = new SnippetData
+        //    {
+        //        //TODO: Get vote information here instead.
+        //        CurrentUserVoted = true,
+        //        CurrentUserVotedSnippet1 = true,
+        //        Snippet = snippet,
+        //        Snippet1Votes = 5,
+        //        Snippet2Votes = 8,
+        //        TotalVotes = 17
+        //    };
+        //    return Json(data, JsonRequestBehavior.AllowGet);
+        //}
+
+           
+
+        //[Authorize]
+        //public ActionResult GoVoteLeftView(int snippetId)
+        //{
+        //    return new JavascriptViewResult { ViewName = "_GoVoteLeft" }; 
+        //}
+
     }
 }

File CodeSmackdown.Site/Global.asax.cs

-using System.Web.Mvc;
+using System.Reflection;
+using System.Web.Mvc;
 using System.Web.Routing;
+using Autofac;
+using Autofac.Integration.Web;
+using Autofac.Integration.Web.Mvc;
+using CodeSmackdown.Domain.Models;
+using CodeSmackdown.Domain.Services;
+using FluentNHibernate.Cfg;
+using FluentNHibernate.Cfg.Db;
+using NHibernate;
 using Spark.Web.Mvc;
-using Autofac.Integration.Web;
-using Autofac;
-using Autofac.Integration.Web.Mvc;
-using System.Reflection;
-using CodeSmackdown.Domain.Services;
-using NHibernate.Cfg;
-using NHibernate;
-using FluentNHibernate.Cfg;
-using CodeSmackdown.Domain.Models;
-using FluentNHibernate.Cfg.Db;
 
 namespace CodeSmackdown.Site
 {

File CodeSmackdown.Site/Scripts/color.js

+/*
+ * jQuery Color Animations
+ * Copyright 2007 John Resig
+ * Released under the MIT and GPL licenses.
+ */
+
+(function(jQuery){
+
+	// We override the animation for all of these color styles
+	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
+		jQuery.fx.step[attr] = function(fx){
+			if ( fx.state == 0 ) {
+				fx.start = getColor( fx.elem, attr );
+				fx.end = getRGB( fx.end );
+			}
+
+			fx.elem.style[attr] = "rgb(" + [
+				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
+				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
+				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
+			].join(",") + ")";
+		}
+	});
+
+	// Color Conversion functions from highlightFade
+	// By Blair Mitchelmore
+	// http://jquery.offput.ca/highlightFade/
+
+	// Parse strings looking for color tuples [255,255,255]
+	function getRGB(color) {
+		var result;
+
+		// Check if we're already dealing with an array of colors
+		if ( color && color.constructor == Array && color.length == 3 )
+			return color;
+
+		// Look for rgb(num,num,num)
+		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
+			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
+
+		// Look for rgb(num%,num%,num%)
+		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
+			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
+
+		// Look for #a0b1c2
+		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
+			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
+
+		// Look for #fff
+		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
+			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
+
+		// Otherwise, we're most likely dealing with a named color
+		return colors[jQuery.trim(color).toLowerCase()];
+	}
+	
+	function getColor(elem, attr) {
+		var color;
+
+		do {
+			color = jQuery.curCSS(elem, attr);
+
+			// Keep going until we find an element that has color, or we hit the body
+			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
+				break; 
+
+			attr = "backgroundColor";
+		} while ( elem = elem.parentNode );
+
+		return getRGB(color);
+	};
+	
+	// Some named colors to work with
+	// From Interface by Stefan Petre
+	// http://interface.eyecon.ro/
+
+	var colors = {
+		aqua:[0,255,255],
+		azure:[240,255,255],
+		beige:[245,245,220],
+		black:[0,0,0],
+		blue:[0,0,255],
+		brown:[165,42,42],
+		cyan:[0,255,255],
+		darkblue:[0,0,139],
+		darkcyan:[0,139,139],
+		darkgrey:[169,169,169],
+		darkgreen:[0,100,0],
+		darkkhaki:[189,183,107],
+		darkmagenta:[139,0,139],
+		darkolivegreen:[85,107,47],
+		darkorange:[255,140,0],
+		darkorchid:[153,50,204],
+		darkred:[139,0,0],
+		darksalmon:[233,150,122],
+		darkviolet:[148,0,211],
+		fuchsia:[255,0,255],
+		gold:[255,215,0],
+		green:[0,128,0],
+		indigo:[75,0,130],
+		khaki:[240,230,140],
+		lightblue:[173,216,230],
+		lightcyan:[224,255,255],
+		lightgreen:[144,238,144],
+		lightgrey:[211,211,211],
+		lightpink:[255,182,193],
+		lightyellow:[255,255,224],
+		lime:[0,255,0],
+		magenta:[255,0,255],
+		maroon:[128,0,0],
+		navy:[0,0,128],
+		olive:[128,128,0],
+		orange:[255,165,0],
+		pink:[255,192,203],
+		purple:[128,0,128],
+		violet:[128,0,128],
+		red:[255,0,0],
+		silver:[192,192,192],
+		white:[255,255,255],
+		yellow:[255,255,0]
+	};
+	
+})(jQuery);

File CodeSmackdown.Site/Scripts/csd.js

         target.before("<span>" + messages[i] + "</span>");
     }
 }
+
+ function drawGraph(leftVotes, rightVotes)
+ {
+    var maxVotes, minVotes, winner, loser;
+
+    if (leftVotes > rightVotes) {
+      maxVotes = leftVotes;
+      minVotes = rightVotes;
+      winner = 'leftBar';
+      loser = 'rightBar';
+    } else {
+      minVotes = leftVotes;
+      maxVotes = rightVotes;
+      loser = 'leftBar';
+      winner = 'rightBar';
+    }
+
+    //The winner is always the height of a code snippet.
+    maxHeight = $("#leftSnippet")[0].offsetHeight;
+
+    //The loser is scaled down accordingly
+    minHeight = Math.round((minVotes / maxVotes) * maxHeight);
+
+    //remove any existing bars...
+    $("#leftSnippet").children(".barStyle").remove();
+    $("#rightSnippet").children(".barStyle").remove();
+
+    
+    leftPadding = $("#snippetRow").width() / 4 - 50;
+
+    var rightBar = document.createElement("div");
+    rightBar.id = 'rightBar';
+    rightBar.className = 'barStyle';
+    rightBar.style.bottom = '4px';
+    rightBar.style.left = leftPadding + 'px';
+
+    var leftBar = document.createElement("div");
+    leftBar.id = 'leftBar';
+    leftBar.className = 'barStyle bars';
+    leftBar.style.bottom = '4px';
+    leftBar.style.left = leftPadding + 'px';
+
+    $("#leftSnippet").append(leftBar);
+    $("#rightSnippet").append(rightBar);
+
+    //Make em both grow to minimum height
+    $(".bars").animate(
+    {
+        height: minHeight + "px",
+    }, 600);
+
+    //Now three things happen at once.
+
+    //the code panels fade slightly
+    $(".code").animate(
+    {
+        backgroundColor: "#FAFAFA"
+    }, 600);
+
+
+    //We have the loser turn red, while...
+    $("#" + loser).animate(
+    {
+        backgroundColor: "#FF0000"
+    }, 600);
+
+    //...while the winner stretches taller and turns green
+    $("#" + winner).animate(
+    {
+        backgroundColor: "green",
+        height: maxHeight + "px"
+    }, 900);
+}

File CodeSmackdown.Site/Scripts/wmd.js

     position.getTop = function(elem, isInner) {
         var result = elem.offsetTop;
         if (!isInner) {
-            while (elem = elem.offsetParent) {
+            while (elem == elem.offsetParent) { /* used to say '=' ?? */
                 result += elem.offsetTop;
             }
         }

File CodeSmackdown.Site/Views/Layouts/Application.spark

     <script src="~/Scripts/color.js" type="text/javascript"></script>
     <script src="~/Scripts/showdown.js" type="text/javascript"></script>
     <script src="~/Scripts/csd.js" type="text/javascript"></script>
-    
+    <script type="text/javascript" src="~/Snippets/GoVoteLeftView"></script>
+    <script type="text/javascript" src="~/Scripts/color.js"></script>
+
     <script type="text/javascript">
         $(document).ready(function() {
 

File CodeSmackdown.Site/Views/Shared/About.spark

             </ul>
         </p>
         <p>
-            (We recently heard of a similar site -- <a href='http://slickorslack.com/'>SlickOrSlack</a> -- by the venerable <a href='http://chadfowler.com/2008/4/1/slick-or-slack'>Chad Fowler</a>. Parallel evolution, etc. In any case, it doesn't seem to be around any more.)
+            (We have heard of a similar site -- 'SlickOrSlack' -- by the venerable <a href='http://chadfowler.com/2008/4/1/slick-or-slack'>Chad Fowler</a>. It doesn't seem to be around any more.)
         </p>
         <p>
             This site is a work in progress and is being used as a learning exercise. If you're interested in helping out,

File CodeSmackdown.Site/Views/Shared/_Snippet.spark

             Total of <b>!{model.TotalVotes}</b> Vote!{(model.TotalVotes == 1) ? "" : "s"}
         </td>
     </tr>
-    <tr if="model.CurrentUserVote.HasValue">
-        <if condition="model.Votes[VoteValue.Left] > model.Votes[VoteValue.Right]">
-            <td class="vote winner">!{model.Votes[VoteValue.Left]} Votes</td>
-            <td class="vote loser" align="right">!{model.Votes[VoteValue.Right]} Votes</td>
-        </if>
-        <else if="model.Votes[VoteValue.Left] < model.Votes[VoteValue.Right]">
-            <td class="vote loser">!{model.Votes[VoteValue.Left]} Votes</td>
-            <td class="vote winner" align="right">!{model.Votes[VoteValue.Right]} Votes</td>
-        </else>
-        <else>
-            <td class="vote even">!{model.Votes[VoteValue.Left]} Votes</td>
-            <td class="vote even" align="right">!{model.Votes[VoteValue.Right]} Votes</td>
-        </else>
-    </tr>
-    <tr>
+    <tr id="snippetRow">
         <td class="code" width="50%">
-            <div>
+            <div class="placeHolder" >  </div>
+            <div id="leftSnippet">
                 <pre><code>!{H(model.Snippet.Left)}</code></pre>
             </div>
         </td>
         <td class="code" width="50%">
-            <div>
+            <div class="placeHolder" >  </div>
+            <div id="rightSnippet">
                 <pre><code>!{H(model.Snippet.Right)}</code></pre>
             </div>
         </td>
                 <input id="voteHot" name="vote" type="submit" value="^^ That is hot! " class="hotbutton" /></span>
             !{Html.Hidden("snippetId", model.Snippet.SnippetId)}
         #Html.EndForm();
-        #Html.BeginForm("VoteRight", "Snippets");
+        #Html.BeginForm("VoteSnippet2", "Snippets");
             <span style="float: right; padding-right: 120px; padding-top: 10px">
                 <input id="voteHot" name="vote" type="submit" value="No, this is hot! ^^" class="hotbutton" /></span>
             !{Html.Hidden("snippetId", model.Snippet.SnippetId)}
     </tr>
     <tr elseif="true">
         <td align="center" colspan="2">
-            Please !{Html.ActionLink("login", "Logon", "Accounts", new {}, new {})} to vote.
+            Please !{Html.ActionLink("sign in", "Logon", "Accounts", new {}, new {})} to vote.
         </td>
     </tr>
+  <var leftVotes="model.Votes[VoteValue.Left]" />
+  <var rightVotes="model.Votes[VoteValue.Right]" />
+  
+  <script type="text/javascript">
+    <if condition="model.CurrentUserVote.HasValue">
+      $(document).ready(function() {
+        drawGraph(!{leftVotes}, !{rightVotes} );
+      });
+    </if>
+  </script>
+  
 </table>

File CodeSmackdown.Site/Views/Shared/_TopMenu.spark

             !{Html.ActionLink(CurrentUser.DisplayName, "View", "Accounts",
             new { id = CurrentUser.UserId }, null)}
         </strong>!
-        | !{Html.ActionLink("Logoff", "Logoff", "Accounts")} | !{Html.ActionLink("Submit your snippets!", "Create", "Snippets")}
+        | !{Html.ActionLink("Sign out", "Logoff", "Accounts")} | !{Html.ActionLink("Submit your snippets!", "Create", "Snippets")}
     </if>
     <else>
-        !{Html.ActionLink("Logon", "Logon", "Accounts")} with OpenID
+        !{Html.ActionLink("Sign in", "Logon", "Accounts")} with OpenID
     </else>
     | !{Html.ActionLink("About", "About", "CodeSmackdown")}
 </div>

File designideas/mercurial_workflow.pptx

Binary file modified.

File designideas/mercurial_workflow.zip

Binary file added.

File designideas/mercurial_workflow_image.png

Old
Old image
New
New image

File designideas/mercurial_workflow_image_th.png

Added
New image