Widget:WikidocBoardReview: Difference between revisions
Jump to navigation
Jump to search
Matt Pijoan (talk | contribs) No edit summary |
Matt Pijoan (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
<includeonly> | <includeonly> | ||
<script src="http://wikidoc.org/includes/jquery.timer.js"></script> | <script src="http://wikidoc.org/includes/jquery.timer.js"></script> | ||
<script type="text/javascript" src="http://wikidoc.org/includes/raty/lib/jquery.raty.js"></script> | |||
<style type="text/css"> | <style type="text/css"> | ||
.boxed{ | .boxed{ | ||
Line 88: | Line 89: | ||
timer : null, | timer : null, | ||
qbank : null, | qbank : null, | ||
searchMethod : null, | |||
timer : null, | timer : null, | ||
examType : '', | examType : '', | ||
Line 138: | Line 140: | ||
buttons = "<div id='Tutor' class='noSelect WBRButton ToE'><br />Tutor Mode</div><div id='Exam' class='noSelect WBRButton ToE'><br />Exam Mode</div><br /><br /><br />"; | buttons = "<div id='Tutor' class='noSelect WBRButton ToE'><br />Tutor Mode</div><div id='Exam' class='noSelect WBRButton ToE'><br />Exam Mode</div><br /><br /><br />"; | ||
$("#exam").append(buttons); | $("#exam").append(buttons); | ||
$('.ToE').click(event.data, timerToggle); | $('.ToE').click(event.data, categoryOrKeyword); | ||
} | |||
function categoryOrKeyword(event) { | |||
event.data.examType = $(this).attr('id'); | |||
var buttons = ''; | |||
buttons = "<div id='Category' class='noSelect WBRButton CoK'><br />Category</div><div id='Keyword' class='noSelect WBRButton CoK'><br />Keyword</div><br /><br /><br />"; | |||
$("#exam").append(buttons); | |||
$('.CoK').click(event.data, timerToggle); | |||
} | } | ||
function timerToggle(event) { | function timerToggle(event) { | ||
event.data. | event.data.searchMethod = $(this).attr('id'); | ||
var form = null; | var form = null; | ||
form = "<div id='yes' class='noSelect WBRButton stepThree'><br />Enable Timer</div><div id='nop' class='noSelect WBRButton stepThree'><br />Disable Timer</div><br /><br /><br />"; | form = "<div id='yes' class='noSelect WBRButton stepThree'><br />Enable Timer</div><div id='nop' class='noSelect WBRButton stepThree'><br />Disable Timer</div><br /><br /><br />"; | ||
Line 148: | Line 157: | ||
} | } | ||
$('#yes').click(event.data, timerDuration); | $('#yes').click(event.data, timerDuration); | ||
$('#nop').click(event.data, selectCats); | |||
if(event.data.searchMethod === "Category"){ | |||
$('#nop').click(event.data, selectCats); | |||
} else { | |||
$('#nop').click(event.data, Keywords); | |||
} | |||
} | } | ||
function timerDuration(event) { | function timerDuration(event) { | ||
Line 157: | Line 171: | ||
$("#exam").append(form); | $("#exam").append(form); | ||
} | } | ||
if(event.data.searchMethod === "Category"){ | |||
$('.stepFour').click(event.data, selectCats); | $('.stepFour').click(event.data, selectCats); | ||
} else { | |||
$('.stepFour').click(event.data, Keywords); | |||
} | |||
} | |||
function Keywords(event) { | |||
var stuffs ="To search via keywords, place individual terms within the text boxes.<br />Clicking OR will add a box on a different line while clicking AND will add a box on the same line.<br />Boxes on different lines will use the 'OR' operator, while boxes on the same line will use the 'AND' Operator.<br />Click SHOW to count the number of questions returned.<div id='formSpace'></div><div class='WBRButton' id='orOp'><br />OR</div><div class='WBRButton' id='andOp'><br />AND</div><div class='WBRButton' id='showQueries'><br />SHOW</div><br /><br /><br />"; | |||
$("#exam").append(stuffs); | |||
var orBox = "<div class='query'> <input type='text' class='queryString' /> </div><br />"; | |||
var andBox = " <input type='text' class='queryString' /> "; | |||
$("#formSpace").html(orBox); | |||
$(".queryString").focus(function () { | |||
$(".focused").removeClass("focused"); | |||
$(this).parent().addClass("focused"); | |||
$(".queryString").focusout(function () { | |||
if ($(this).val().length <= 1) { | |||
$(this).remove(); | |||
} | |||
}); | |||
}); | |||
$("#orOp").click(function () { | |||
$("#formSpace").append(orBox); | |||
$(".queryString").focus(function () { | |||
$(".focused").removeClass("focused"); | |||
$(this).parent().addClass("focused"); | |||
$(".queryString").focusout(function () { | |||
if ($(this).val().length <= 1) { | |||
$(this).remove(); | |||
} | |||
}); | |||
}); | |||
}); | |||
$("#andOp").click(function () { | |||
var andBox = "<input type='text' class='queryString' />"; | |||
$(".focused").append(andBox); | |||
$(".queryString").focus(function () { | |||
$(".focused").removeClass("focused"); | |||
$(this).parent().addClass("focused"); | |||
$(".queryString").focusout(function () { | |||
if ($(this).val().length <= 1) { | |||
$(this).remove(); | |||
} | |||
}); | |||
}); | |||
}); | |||
$("#showQueries").click(event.data, showQueries); | |||
function showQueries(event) { | |||
$("#removeNum").remove(); | |||
event.data.queries = []; | |||
event.data.questionListAll = []; | |||
event.data.keyword = {}; | |||
event.data.keyword.iterator = 0; | |||
$.each($(".query"),function (index, value) { | |||
event.data.queries[index] = "[[ExamType::" + event.data.examtype + "]]"; | |||
$.each($(this).children(), function(ind, val){ | |||
event.data.queries[index] += "[[WBRKeyword::" + $(this).val() + "]]"; | |||
}); | |||
}); | |||
runQueries(event.data); | |||
} | |||
function runQueries(obj) { | |||
var api = new mw.Api(); | |||
api.get({ | |||
action : 'ask', | |||
query : obj.queries[obj.keyword.iterator], | |||
format : 'json' | |||
}) | |||
.always(function (data) { | |||
$.each(data.query.results, function(index, value){ | |||
obj.questionListAll.push(value.fulltext); | |||
}); | |||
if ((obj.keyword.iterator+1) < obj.queries.length) { | |||
obj.keyword.iterator++; | |||
runQueries(obj); | |||
} else { | |||
removeDuplicates(obj); | |||
} | |||
}); | |||
} | |||
function removeDuplicates(obj){ | |||
for(var i=0;i<obj.questionListAll.length;i++){ | |||
$.each(obj.questionListAll, function(index, value){ | |||
if(obj.questionListAll[i] === value && i != index){ | |||
obj.questionListAll.splice(index, 1); | |||
return false; | |||
} | |||
}); | |||
} | |||
var maxQ; | |||
if(obj.questionListAll.length >= 45){ | |||
maxQ = 45; | |||
} else { | |||
maxQ = obj.questionListAll.length; | |||
} | |||
var output = "<div id='removeNum'><b>Choose the number of questions you would like to answer. The maximum number of questions you can select is <span id='countShow'>" + maxQ + "</span>.</b><br /><br /><br />Number of questions:<input type='text' id='numQues' /><br /><br /><div id='Go' class='noSelect WBRButton'>Click here to begin the exam</div></div>"; | |||
if ($("#exam").find('#numQues').length == 0) { | |||
$("#exam").append(output); | |||
} else { | |||
alert('Please ensure you have valid keywords entered'); | |||
} | |||
$("#Go").click(obj, TNG); | |||
} | |||
} | |||
function TNG(event){ | |||
event.data.numQuestion = $("#numQues").val(); | |||
loadNextQuestion(event.data); | |||
} | } | ||
function selectCats(event) { | function selectCats(event) { | ||
Line 277: | Line 403: | ||
} else { | } else { | ||
alert('Please ensure you have both a main and a sub category selected'); | alert('Please ensure you have both a main and a sub category selected'); | ||
} | }} | ||
} | |||
function inputValidation(event) { | function inputValidation(event) { | ||
if ($("#numQues").val().length > 0 && parseInt($("#numQues").val(), 10) <= parseInt($("#countShow").html(), 10) && parseInt($("#numQues").val(), 10) > 0) { | if ($("#numQues").val().length > 0 && parseInt($("#numQues").val(), 10) <= parseInt($("#countShow").html(), 10) && parseInt($("#numQues").val(), 10) > 0) { | ||
Line 324: | Line 448: | ||
function loadNextQuestion(event) { | function loadNextQuestion(event) { | ||
console.log(event.questionListAll); | |||
var rand = null; | var rand = null; | ||
rand = Math.floor(Math.random() * event.questionListAll.length); | rand = Math.floor(Math.random() * event.questionListAll.length); | ||
Line 448: | Line 573: | ||
parseQuestions(exam); | parseQuestions(exam); | ||
} else { | } else { | ||
$("#examSpace").append("<br /><a href='http://www.wikidoc.org/index.php/Talk:"+obj.PageName+"' target='_blank'>Click here to discuss this question!</a><br />"); | |||
var htmlStuff = "<b>Author:</b> " + obj.PageAuthor + "<br /><br /><b>Question " + (exam.currentQuestion - -1) + " / " + (exam.examQuestions.length) + "</b><br /><br />" + obj.Prompt + "<br />"; | var htmlStuff = "<b>Author:</b> " + obj.PageAuthor + "<br /><br /><b>Question " + (exam.currentQuestion - -1) + " / " + (exam.examQuestions.length) + "</b><br /><br />" + obj.Prompt + "<br />"; | ||
if (obj.AnswerA && obj.AnswerA.length > 0) { | if (obj.AnswerA && obj.AnswerA.length > 0) { | ||
Line 480: | Line 607: | ||
} | } | ||
$("#examSpace").html(htmlStuff); | $("#examSpace").html(htmlStuff); | ||
addRatyRating(exam); | |||
if(exam.examQuestions[exam.currentQuestion].selectedAnswer && exam.examQuestions[exam.currentQuestion].RightAnswer == exam.examQuestions[exam.currentQuestion].selectedAnswer){ | if(exam.examQuestions[exam.currentQuestion].selectedAnswer && exam.examQuestions[exam.currentQuestion].RightAnswer == exam.examQuestions[exam.currentQuestion].selectedAnswer){ | ||
$("#" + exam.examQuestions[exam.currentQuestion].RightAnswer).addClass("boxed"); | $("#" + exam.examQuestions[exam.currentQuestion].RightAnswer).addClass("boxed"); | ||
Line 501: | Line 629: | ||
$("#examSpace").append("<div id='finish' class='noSelect WBRButton'><br />Finish</div>"); | $("#examSpace").append("<div id='finish' class='noSelect WBRButton'><br />Finish</div>"); | ||
$("#finish").click(function () { | $("#finish").click(function () { | ||
window.location.replace("http://wikidoc.org/index.php?title=Special:UserLogin&returnto= | window.location.replace("http://wikidoc.org/index.php?title=Special:UserLogin&returnto=Board_Review"); | ||
}); | }); | ||
} | } | ||
} | |||
function addRatyRating(exam){ | |||
var ratyLayers = "<center>Rate this question!</center><br /><span style='position:relative; float:left;'>Difficulty: <div id='star1'></div></span><span style='position:relative; float:left;left:33%;'>High Yield: <div id='star2'></div></span><span style='position:relative; float:left;left:66%'>Quality: <div id='star3'></div></span><br /><br /><br />" | |||
$("#examSpace").prepend(ratyLayers); | |||
$("#star1").raty({ | |||
path : 'http://www.wikidoc.org/includes/raty/lib/img/', | |||
click : function (score, event) { | |||
submitRating("difficulty", score, "Buh") | |||
}, | |||
score : function (event) { | |||
getRating("difficulty",exam.examQuestions[exam.currentQuestion].PageName); | |||
}, | |||
hints: ['Very Poor', 'Poor', 'Average', 'Good', 'Very Good'] | |||
}); | |||
$("#star2").raty({ | |||
path : 'http://www.wikidoc.org/includes/raty/lib/img/', | |||
click : function (score, event) { | |||
submitRating("yield", score, "Buh") | |||
}, | |||
score : function (event) { | |||
getRating("yield",exam.examQuestions[exam.currentQuestion].PageName); | |||
}, | |||
hints: ['Very Poor', 'Poor', 'Average', 'Good', 'Very Good'] | |||
}); | |||
$("#star3").raty({ | |||
path : 'http://www.wikidoc.org/includes/raty/lib/img/', | |||
click : function (score, event) { | |||
submitRating("quality", score, "Buh") | |||
}, | |||
score : function (event) { | |||
getRating("quality",exam.examQuestions[exam.currentQuestion].PageName); | |||
}, | |||
hints: ['Very Poor', 'Poor', 'Average', 'Good', 'Very Good'] | |||
}); | |||
} | } | ||
Line 509: | Line 673: | ||
$(".answer").removeClass("boxed"); | $(".answer").removeClass("boxed"); | ||
event.data.examQuestions[event.data.currentQuestion].selectedAnswer = $(this).attr("id"); | event.data.examQuestions[event.data.currentQuestion].selectedAnswer = $(this).attr("id"); | ||
if (event.data.examQuestions[event.data.currentQuestion].creditRecieved | if (!event.data.examQuestions[event.data.currentQuestion].creditRecieved && event.data.examQuestions[event.data.currentQuestion].selectedAnswer === event.data.examQuestions[event.data.currentQuestion].RightAnswer) { | ||
event.data.answeredRight += 1; | event.data.answeredRight += 1; | ||
event.data.examQuestions[event.data.currentQuestion].creditRecieved = true; | event.data.examQuestions[event.data.currentQuestion].creditRecieved = true; | ||
Line 518: | Line 682: | ||
} | } | ||
$("div.answer").unbind('click'); | $("div.answer").unbind('click'); | ||
var api = new mw.Api(); | |||
api.get({ | |||
action : 'wbrinsertmetric', | |||
username : mw.user.getName(), | |||
question : event.data.examQuestions[event.data.currentQuestion].PageName, | |||
selectedAnswer : event.data.examQuestions[event.data.currentQuestion].selectedAnswer, | |||
format : 'json' | |||
}) | |||
.done(function (data) { | |||
console.log('API result:', data); | |||
}); | |||
if (event.data.examType === "Exam") { | if (event.data.examType === "Exam") { | ||
$("#" + event.data.examQuestions[event.data.currentQuestion].selectedAnswer).addClass("boxed"); | $("#" + event.data.examQuestions[event.data.currentQuestion].selectedAnswer).addClass("boxed"); | ||
Line 524: | Line 699: | ||
$("#" + event.data.examQuestions[event.data.currentQuestion].selectedAnswer).addClass("boxed"); | $("#" + event.data.examQuestions[event.data.currentQuestion].selectedAnswer).addClass("boxed"); | ||
$("#" + event.data.examQuestions[event.data.currentQuestion].RightAnswer).addClass("redBoxed"); | $("#" + event.data.examQuestions[event.data.currentQuestion].RightAnswer).addClass("redBoxed"); | ||
addRatyRating(event.data); | |||
} | } | ||
if (event.data.currentQuestion > 0) { | if (event.data.currentQuestion > 0) { | ||
Line 574: | Line 750: | ||
$("#examSpace").html(""); | $("#examSpace").html(""); | ||
var datas; | var datas; | ||
datas = "You answered " + event.data.answeredRight + " out of " + event.data.examQuestions.length + " correctly.<br /> Your percentage score is: "; | datas = ""; | ||
datas += "<br />You answered " + event.data.answeredRight + " out of " + event.data.examQuestions.length + " correctly.<br /> Your percentage score is: "; | |||
var percent = (event.data.answeredRight / event.data.numQuestion) * 100; | var percent = (event.data.answeredRight / event.data.numQuestion) * 100; | ||
datas += percent + "%<br /><br />Click the Navigation Buttons on the left to review the questions you answered."; | datas += percent + "%<br /><br />Click the Navigation Buttons on the left to review the questions you answered."; | ||
var api = new mw.Api(); | |||
api.get({ | |||
action : 'wbrinsertexam', | |||
username : mw.user.getName(), | |||
size : event.data.examQuestions.length, | |||
score : percent, | |||
format : 'json' | |||
}) | |||
.done(function (data) { | |||
console.log('API result:', data); | |||
}); | |||
$("#examSpace").append(datas); | $("#examSpace").append(datas); | ||
$(".navPaneButton").unbind('click'); | $(".navPaneButton").unbind('click'); | ||
$(".navPaneButton").click(event.data, questionReviewNavigation); | $(".navPaneButton").click(event.data, questionReviewNavigation); | ||
} | } | ||
function submitRating(type, score, page) { | |||
var api = new mw.Api(); | |||
api.get({ | |||
action : 'wbrinsertrating', | |||
username : mw.user.getName(), | |||
question : page, | |||
quality : 5, | |||
format : 'json' | |||
}, { | |||
ok : function (res) { | |||
} | |||
}); | |||
} | |||
function getRating(type, page) { | |||
var api = new mw.Api(); | |||
api.get({ | |||
action : 'wbrgetrating', | |||
question : page, | |||
format : 'json' | |||
}, { | |||
ok : function (res) { | |||
if (type === "difficulty") { | |||
return res.difficulty; | |||
} | |||
if (type === "quality") { | |||
return res.quality; | |||
} | |||
if (type === "yield") { | |||
return res.yield; | |||
} | |||
}}); | |||
} | |||
function parseQuestions(examObj) { | function parseQuestions(examObj) { | ||
var tobeParsed = null; | var tobeParsed = null; | ||
Line 623: | Line 849: | ||
tobeParsed = examObj.examQuestions[q].AnswerEExp; | tobeParsed = examObj.examQuestions[q].AnswerEExp; | ||
break; | break; | ||
case 12: | |||
tobeParsed = examObj.examQuestions[q].Author | |||
} | } | ||
if (tobeParsed && tobeParsed.length > 0) { | if (tobeParsed && tobeParsed.length > 0) { | ||
Line 673: | Line 901: | ||
examObj.examQuestions[q].AnswerEExp = parsed; | examObj.examQuestions[q].AnswerEExp = parsed; | ||
break; | break; | ||
case 12: | |||
examObj.examQuestions[q].Author = parsed; | |||
break | |||
} | } | ||
if (examObj.examQuestions[q].lastParsed < | if (examObj.examQuestions[q].lastParsed < 13) { | ||
examObj.examQuestions[q].lastParsed += 1; | examObj.examQuestions[q].lastParsed += 1; | ||
parseQuestions(examObj); | parseQuestions(examObj); |