Skip to content

Commit

Permalink
Improved responses from prove(), fixed message issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwholdsworth committed May 11, 2013
1 parent 1b6ceca commit d533c7a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 28 deletions.
14 changes: 7 additions & 7 deletions css/jsprove.css
Expand Up @@ -13,25 +13,25 @@ h1 {
padding:10px;
}

.error, .false {
font-weight:bold;
color:#900;
}

.small {
font-size:0.8em;
}

.true {
.success {
color:#090;
font-weight: bold;
}

.incomplete {
.info {
color:#009;
font-weight:bold;
}

.error, .false {
font-weight:bold;
color:#900;
}

input, select, button {
width: auto;
}
Expand Down
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -83,7 +83,7 @@ <h2>Methods</h2>
<div id="methodList" class="form-horizontal"></div>

<h2>Composition</h2>
<div><label for="shorthand"><abbr title="For single method compositions only. E.g. mhwvf">Shorthand</abbr> (uses first method from selection above)</label><br /><input type="text" value="hhh" name="shorthand" id="shorthand" size="60" /> <input type="button" id="generateShorthand" value="Generate" class="btn btn-primary" /></div>
<div class="form-horizontal"><label for="shorthand"><abbr title="For single method compositions only. E.g. mhwvf">Shorthand</abbr> (uses first method from selection above)</label><br /><input type="text" value="hhh" name="shorthand" id="shorthand" size="60" /> <input type="button" id="generateShorthand" value="Generate" class="btn btn-primary" /></div>
<div><label for="liveProve"><abbr title="Proves for every keystroke. Not great on slower machines.">Live Prove</abbr></label><input type="checkbox" name="liveProve" id="liveProve" checked="checked" /></div>
<div style="overflow:hidden;">
<textarea id="composition" rows="10" cols="40" style="float:left;">YYYYYYY</textarea>
Expand Down
34 changes: 25 additions & 9 deletions js/frontend.js
Expand Up @@ -69,8 +69,12 @@ $("#generateShorthand").click(function() {
return false;
}

generateShorthand(mid.substr(6), [$('#symbol0').val(), $('#callNtn0').val()], [$('#symbol1').val(), $('#callNtn1').val()]);
prove();
try {
generateShorthand(mid.substr(6), [$('#symbol0').val(), $('#callNtn0').val()], [$('#symbol1').val(), $('#callNtn1').val()]);
prove();
} catch (e) {
displayWarning(e, 'error');
}
});

// add more call fields
Expand Down Expand Up @@ -193,14 +197,26 @@ function loadMusicForStage(stage) {
function prove() {
try {
res = do_prove();

if (res.trueTouch === true) {
if (res.complete === true) {
messageType = 'success';
} else {
messageType = 'info';
}
} else {
messageType = 'error';
}

displayWarning(res.status, messageType);
$('#results').html(res.status).attr('class', messageType);
$('#music').html(res.music);
$('#courseEnds').html(res.courses);
$('#atw pre').html(res.atw);
$('#com').html(res.com + ' changes of method');
} catch (e) {
res = "Error: " + e;
displayWarning(e, 'error');
}
$('#results').html(res[0]);
$('#music').html(res[1]);
$('#courseEnds').html(res[2]);
$('#atw pre').html(res[3]);
$('#com').html(res[4] + ' changes of method');
}

/**
Expand Down Expand Up @@ -240,7 +256,7 @@ function displayWarning(message, level, timeout) {
if (timeout === undefined) {
timeout = 4000;
}
$('.alert').addClass('alert-' + level);
$('.alert').attr('class', 'alert alert-' + level);
$('.alert div').html(message);
$('.alert').fadeIn('slow').delay(timeout).fadeOut('slow');
}
Expand Down
42 changes: 31 additions & 11 deletions js/pealprover.js
Expand Up @@ -78,6 +78,16 @@ function do_prove() {
var changes = 0;
var rounds = 0;
var music = MusicBox();
var result = {
trueTouch: false,
complete: false,
length: 0,
status: 'No touch entered',
courses: '',
music: '',
atw: '',
com: 0
};

function test_row(c, le) {
var r;
Expand Down Expand Up @@ -171,6 +181,7 @@ function do_prove() {
leads[i] = lead;
}

// get the course ends for displaying
var courses = "";
var leadNo = 0;
for(c = 0; c < comptext.length; c++) {
Expand All @@ -179,17 +190,28 @@ function do_prove() {
courses += leads[leadNo-1] + "\n";
}
}
result.courses = courses;

if (rounds > 0) {
result.trueTouch = true;
result.length = (changes - rounds);
result.complete = true;

if (rounds != changes) {
res = "<span class=\"true\">Touch is true: " + rounds + " changes (" + (changes - rounds) + " before last course end)</span>";
result.status = "Touch is true: " + rounds + " changes (" + (changes - rounds) + " before last course end)";
} else {
res = "<span class=\"true\">Touch is true: " + rounds + " changes</span>";
result.status = "Touch is true: " + rounds + " changes";
}
} else if (rounds < 0) {
res = "<span class=\"false\">Touch is false: false after " + (-rounds) + " changes</span>";
result.complete = true;
result.trueTouch = false;
result.length = (-rounds);
result.status = "Touch is false: false after " + (-rounds) + " changes";
} else {
res = "<span class=\"incomplete\">Incomplete touch (" + changes + " changes)</span>";
result.complete = false;
result.trueTouch = true;
result.length = changes;
result.status = "Incomplete touch (" + changes + " changes)";
}

musicOutput = "<pre>";
Expand All @@ -204,12 +226,14 @@ function do_prove() {
}
}
musicOutput += "</pre>";
result.music = musicOutput;

var atw = AtwChecker(comp);
atw.getAtw();
outputAtw = formatAtw(atw);
result.atw = formatAtw(atw);
result.com = atw.com;

return [res, musicOutput, courses, outputAtw, atw.com];
return result;
}

function formatAtw(atw) {
Expand Down Expand Up @@ -253,11 +277,7 @@ function generateShorthand(methodID, bob, single) {
var vm = validate_method(methodID);
var s = Shorthand($('#shorthand').val(), vm[1]);

try {
s.run(nothing, bob, single);
} catch (er) {
displayWarning(er);
}
s.run(nothing, bob, single);
$('#composition').val(s.compText);

function nothing() {}
Expand Down

0 comments on commit d533c7a

Please sign in to comment.