Permalink
Browse files

Merge branch 'release/1.6.0'

  • Loading branch information...
2 parents 05bec4e + ed0ab8f commit 9af13a05747593b77ba57d604e5edcdf1ef6822d @amalloy amalloy committed Nov 22, 2011
View
@@ -1,4 +1,4 @@
-(defproject foreclojure "1.5.3"
+(defproject foreclojure "1.6.0"
:description "4clojure - a website for learning Clojure"
:dependencies [[clojure "1.2.1"]
[clojure-contrib "1.2.0"]
@@ -19,7 +19,6 @@
[commons-lang "2.6"]
[org.apache.commons/commons-email "1.2"]]
:dev-dependencies [[lein-ring "0.4.5"]
- [swank-clojure "1.3.3"]
[midje "1.1.1"]]
:main foreclojure.core
:ring {:handler foreclojure.core/app
@@ -0,0 +1,19 @@
+
+
+
+#######################################
+# error messages used in registration #
+# and when updating user settings #
+#######################################
+
+settings.user-exists=User already exists
+settings.uname-alphanum=Username must be alphanumeric
+settings.uname-size=Username must be 4-13 characters long
+settings.npwd-size=New password must be at least seven characters long
+settings.pwd-size=Password must be at least seven characters long
+settings.pwd-match=Passwords don't match
+settings.npwd-match=New password was not entered identically twice
+settings.pwd-incorrect=Current password incorrect
+settings.email-invalid=Please enter a valid email address
+settings.email-exists=User with this email address already exists
+
@@ -419,7 +419,8 @@ div#problems-error {
float: left;
width: 50%;
height: 250px;
- overflow: hidden
+ overflow: hidden;
+ border: 1px solid #aaa;
}
table.my-table {
@@ -0,0 +1,134 @@
+var CodeBox = {
+
+ disableJavascript: null,
+ element: null,
+ submitButtons: null,
+ editor: null,
+ editorSession: null,
+ editorElement: null,
+ cont: true,
+ high: false,
+ animationTime: 800,
+ waitTimePerItem: 500,
+ images: null,
+
+ initialize: function() {
+ this.disableJavascript = $('#disable-javascript-codebox').length > 0
+ || $.browser.mobile;
+ this.element = $("#code-box");
+ this.submitButtons = $("#run-button, #submission-button");
+
+ if(!this.disableJavascript && this.submitButtons.length > 0) {
+ this.setupEditor();
+ }
+
+ this.submitButtons.live("click", $.proxy(this.run, this));
+ },
+
+ setupEditor: function() {
+ this.element.after("<div id=\"code-div\"> <pre id=\"editor\">" +
+ this.element.val() + "</pre></div>");
+
+ this.element.hide();
+ this.editorElement = $("#editor");
+
+ this.editor = ace.edit("editor");
+ this.editor.setTheme("ace/theme/textmate");
+ this.editor.setShowPrintMargin(false);
+
+ var ClojureMode = require("ace/mode/clojure").Mode;
+ this.editorSession = this.editor.getSession();
+ this.editorSession.setMode(new ClojureMode());
+ this.editorSession.setUseSoftTabs(true);
+ this.editorSession.setTabSize(2);
+ this.editorElement.css("font-size", "13px");
+ },
+
+ getCode: function() {
+ if(this.disableJavascript)
+ return $("#code-box").val();
+ else
+ return this.editorSession.getValue();
+ },
+
+ toggle: function() {
+ if(this.disableJavascript)
+ $("#code-box").toggle('fast');
+ else
+ $("#code-div").toggle('fast');
+ },
+
+ run: function(e) {
+ e.preventDefault();
+
+ var text = this.getCode(),
+ id = $('#id').attr("value");
+
+ this.images = $(".testcases").find("img"),
+
+ $.ajax({
+ type: "POST",
+ url: "/rest/problem/"+id,
+ dataType: "json",
+ data: { id: id, code: text, },
+ timeout: 20000, // default clojail timeout is 10000
+ beforeSend: $.proxy(this.beforeSendCallback, this),
+ success: $.proxy(this.successCallback, this),
+ error: function(data, str, error) {
+ $("#message-text").text("An Error occured: "+error);
+ }});
+ },
+
+ beforeSendCallback: function() {
+ var anim = function() {
+ if(this.cont) {
+ this.images.animate({
+ opacity: this.high ? 1.0 : 0.1,
+ }, this.animationTime);
+ this.high = !this.high;
+ setTimeout(anim,this.animationTime);
+ }
+ };
+
+ $("#message-text").text("Executing unit tests...");
+ $("#error-message-text").text("");
+ this.images.each( function(index, element) {
+ setIconColor(element, "blue");
+ });
+ setTimeout(changeToCodeView,0);
+ setTimeout($.proxy(anim, this),0);
+ },
+
+ successCallback: function(data) {
+ var waitTime = this.waitTimePerItem;
+
+ var failingTest = data.failingTest,
+ getColorFor = function(index) {
+ return index === failingTest ? "red" : "green";
+ },
+ testWasExecuted = function(index) {
+ return index <= failingTest;
+ },
+ setColor = function(index,element) {
+ var color = getColorFor(index);
+ waitTime = CodeBox.waitTimePerItem * (index+1);
+ setIconColor(element, color, waitTime);
+ },
+ setMessages = function() {
+ $("#message-text").html(data.message);
+ $("#error-message-text").html(data.error);
+ $("#golfgraph").html(data.golfChart);
+ $("#golfscore").html(data.golfScore);
+ configureGolf();
+ },
+ stopAnimation = function() {
+ this.cont = false;
+ this.images.stop(true);
+ this.images.css({ opacity: 1.0, });
+ };
+
+ setTimeout($.proxy(stopAnimation, this), waitTime);
+ this.images.filter( testWasExecuted ).each(setColor);
+ setTimeout(setMessages, waitTime);
+ },
+}
@@ -3,7 +3,7 @@ var updateProblemCountDelay = 4000; // milliseconds
$(document).ready(function() {
configureDataTables();
- configureCodeBox();
+ CodeBox.initialize();
configureGolf();
if($("#totalcount").length > 0)
@@ -150,7 +150,7 @@ function configureDataTables(){
]
} );
-
+
$('#server-user-table').dataTable( {
"aoColumns": [
null,
@@ -178,126 +178,11 @@ function changeToCodeView() {
$('#graph-link').html("View Chart");
}
-function configureCodeBox(){
- //For no javascript version we have the code-box text area
- //If we have javascript on then we remove it and replace it with
- //the proper div
- var oldBox = $('#code-box');
- var disableJavaScriptCodeBox = $('#disable-javascript-codebox');
- if (disableJavaScriptCodeBox.length){
- return;
- }
- var hiddenCodeInput = "<input type=\"hidden\" value=\"blank\" name=\"code\" id=\"code\">";
- oldBox.replaceWith("<div id=\"code-div\"> <pre id=\"editor\">" + oldBox.val() + "</pre></div>"+hiddenCodeInput);
-
- if ($("#run-button").length || $("#submission-button").length){
- var editor = ace.edit("editor");
- editor.setTheme("ace/theme/textmate");
-
- var ClojureMode = require("ace/mode/clojure").Mode;
- var session = editor.getSession();
-
- var clickHandler = function() {
- var text = session.getValue(),
- id = $('#id').attr("value"),
- images = $(".testcases").find("img"),
- cont = true,
- high = false,
- animationTime = 800,
- waitTimePerItem = 500,
- waitTime = waitTimePerItem,
-
- beforeSendCallback = function(data) {
- var anim = function() {
- if(cont) {
- images.animate({
- opacity: high ? 1.0 : 0.1,
- }, animationTime);
- high = !high;
- setTimeout(anim,animationTime);
- }
- };
-
- $("#message-text").text("Executing unit tests...");
- $("#error-message-text").text("");
- images.each( function(index, element) {
- setIconColor(element, "blue");
- });
- setTimeout(changeToCodeView,0);
- setTimeout(anim,0);
- },
- successCallback = function(data) {
- var failingTest = data.failingTest,
- getColorFor = function(index) {
- return index === failingTest ? "red" : "green";
- },
- testWasExecuted = function(index) {
- return index <= failingTest;
- },
- setColor = function(index,element) {
- var color = getColorFor(index);
- waitTime = waitTimePerItem * (index+1);
- setIconColor(element, color, waitTime);
- },
- setMessages = function() {
- $("#message-text").html(data.message);
- $("#error-message-text").html(data.error);
- $("#golfgraph").html(data.golfChart);
- $("#golfscore").html(data.golfScore);
- configureGolf();
- },
- stopAnimation = function() {
- cont = false;
- images.stop(true);
- images.css({ opacity: 1.0, });
- };
-
- setTimeout(stopAnimation, waitTime);
- images.filter( testWasExecuted ).
- each(setColor);
- setTimeout (setMessages, waitTime);
- };
-
- $.ajax({type: "POST",
- url: "/rest/problem/"+id,
- dataType: "json",
- data: { id: id, code: text, },
- timout: 20000, // default clojail timeout is 10000
- beforeSend: beforeSendCallback,
- success: successCallback,
- error: function(data, str, error) {
- $("#message-text").text("An Error occured: "+error);
- },
- });
- return false;
- };
-
- $("#run-button").click(clickHandler);
-
- session.setMode(new ClojureMode());
- session.setUseSoftTabs(true);
- session.setTabSize(2);
-
- document.getElementById('editor').style.fontSize='13px';
- $("#run-button").click(function(){
- var text = editor.getSession().getValue();
- $('#code').val(text);
- });
-
- $("#submission-button").click(function(){
- var text = editor.getSession().getValue();
- $('#code').val(text);
- });
- }
-}
-
function configureGolf(){
$('#graph-link').show();
$('#golfgraph').hide();
$('#graph-link').click(function() {
- $('#code-div').toggle('fast', function() {
- // Animation complete.
- });
+ CodeBox.toggle();
$('#golfgraph').toggle('fast', function() {
// Animation complete.
});

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,9 @@
+(ns foreclojure.messages)
+
+(defn load-props [file]
+ (into {} (doto (java.util.Properties.)
+ (.load (-> (Thread/currentThread)
+ (.getContextClassLoader)
+ (.getResourceAsStream file))))))
+
+(def err-msgs (load-props "error-messages.properties"))
@@ -6,6 +6,7 @@
[compojure.core :only [defroutes GET POST]]
[foreclojure.utils :only [form-row assuming flash-error plausible-email?]]
[foreclojure.template :only [def-page]]
+ [foreclojure.messages :only [err-msgs]]
[somnium.congomongo :only [insert! fetch-one]]))
(def-page register-page []
@@ -26,20 +27,20 @@
(defn do-register [user pwd repeat-pwd email]
(let [lower-user (.toLowerCase user)]
(assuming [(nil? (fetch-one :users :where {:user lower-user}))
- "User already exists",
+ (err-msgs "settings.user-exists"),
(< 3 (.length lower-user) 14)
- "Username must be 4-13 characters long",
+ (err-msgs "settings.uname-size"),
(= lower-user
(first (re-seq #"[A-Za-z0-9_]+" lower-user)))
- "Username must be alphanumeric"
+ (err-msgs "settings.uname-alphanum")
(< 6 (.length pwd))
- "Password must be at least seven characters long",
+ (err-msgs "settings.pwd-size"),
(= pwd repeat-pwd)
- "Passwords don't match",
+ (err-msgs "settings.pwd-match"),
(plausible-email? email)
- "Please enter a valid email address"
+ (err-msgs "settings.email-invalid")
(nil? (fetch-one :users :where {:email email}))
- "User with this email address already exists"]
+ (err-msgs "settings.email-exists")]
(do
(insert! :users
{:user lower-user
Oops, something went wrong.

0 comments on commit 9af13a0

Please sign in to comment.