Skip to content

Commit

Permalink
fixing submissions on problem view
Browse files Browse the repository at this point in the history
  • Loading branch information
kkatzen committed May 1, 2015
1 parent 364209f commit cc50654
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 31 deletions.
14 changes: 10 additions & 4 deletions api/controllers/SubmissionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,38 @@ module.exports = {
var problem = req.param("id");
var highest = req.param("highest");
var student = req.param("student");
var reverse = req.param("reverse");
var direction = 1;
if(reverse){
direction = -1;
}

if (problem && !student) {
Submission.find({problem: problem, user: req.user.username}).sort({createdAt: 1}).exec(function(err, submissions) {
Submission.find({problem: problem, user: req.user.username}).sort({createdAt: direction}).exec(function(err, submissions) {
if (err) {
console.log("error getting submissions from database");
} else {
res.send(submissions);
}
});
} else if (problem && student) {
Submission.find({problem: problem, user: student}).sort({createdAt: 1}).exec(function(err, submissions) {
Submission.find({problem: problem, user: student}).sort({createdAt: direction}).exec(function(err, submissions) {
if (err) {
console.log("error getting submissions from database");
} else {
res.send(submissions);
}
});
} else if (!problem && student) {
Submission.find({user: student}).sort({createdAt: 1}).exec(function(err, submissions) {
Submission.find({user: student}).sort({createdAt: direction}).exec(function(err, submissions) {
if (err) {
console.log("error getting submissions from database");
} else {
res.send(submissions);
}
});
} else {
Submission.find().sort({createdAt: 1}).exec(function(err, submissions) {
Submission.find().sort({createdAt: direction}).exec(function(err, submissions) {
if (err) {
console.log("error getting submissions from database");
} else {
Expand Down
78 changes: 51 additions & 27 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function getStudentResults(problem) {
numstyle = 0;
numattempted = 0;
numearned = 0;
var tbl = $("<table class='table'><thead><tr><th>Name</th><th># Tries</th><th>Functionality / Style Points</th></tr></thead><tbody id='allStudents1ProblemResults'></tbody></table>");
var tbl = $("<table class='table'><thead><tr><th>Name</th><th class='probStudentSubmissionTableTD'># Tries</th><th class='probStudentSubmissionTableTD'>Functionality</th><th class='probStudentSubmissionTableTD'>Style Points</th></tr></thead><tbody id='allStudents1ProblemResults'></tbody></table>");
$("#allStudents1ProblemTable").empty().append(tbl);
$.post("/user/read/", {}, function(users){
total = users.length;
Expand All @@ -81,6 +81,9 @@ function getStudentResults(problem) {
}

function updateProblemProgressBar(){
if(curProblem == null){
return;
}
problem = curProblem;
numfunct = 0;
numstyle = 0;
Expand Down Expand Up @@ -132,13 +135,29 @@ function updateProblemProgressBar(){

function problemCorrect(user, problem, student, totalStudents){
//check score of a student for a problem
var rsection = $("<td>");
var rsectionF = $("<td>").attr("class","probStudentSubmissionTableTD");
var rsectionS = $("<td>").attr("class","probStudentSubmissionTableTD");

var results = {tried: false, correct: false, style: false};
$.post("/submission/read/" + problem.id, {id: problem.id, student: user.username}, function(submissions){
$.post("/submission/read/" + problem.id, {id: problem.id, student: user.username, reverse: true}, function(submissions){
if(submissions.length == 0){
student.append("<td>" + submissions.length + "</td>");
student.append("<td class='probStudentSubmissionTableTD'>" + submissions.length + "</td>");
} else {
student.append("<td><a data-toggle='collapse' data-parent='#accordion' href='#submissionUser" + user.id + "' >" + submissions.length + "</a></td>");
var myVariable = $("<td>").attr("class","probStudentSubmissionTableTD");
var a = $("<a></a>")
.html(submissions.length)
.click(function (event) {
console.log("angst");
if($(".submissionUser"+user.id).hasClass("hidden")) {
$(".submissionUser"+user.id).removeClass('hidden');
} else {
$(".submissionUser"+user.id).addClass('hidden');
}
});

myVariable.append(a);
student.append(myVariable);

results.tried = true;
submissions.forEach(function(submission) {
if(submission.value.correct == problem.value.correct && submission.value.style == problem.value.style) {
Expand All @@ -155,26 +174,26 @@ function problemCorrect(user, problem, student, totalStudents){
numattempted++;
if(results.correct) {
numfunct++;
rsection.append(problem.value.correct + "f</td><td>");
} else {
rsection.append(problem.value.correct + "f</td><td>");
} if(results.style) {
rsectionF.append(correct("8px"));
}else {
rsectionF.append(wrong("8px"));
}
if(results.style) {
numstyle++;
rsection.append(problem.value.style + "s</td>");
} else {
rsection.append(problem.value.style + "s</td>");
rsectionS.append(correct("8px"));
}else {
rsectionS.append(wrong("8px"));
}
if(results.correct && results.style){
numearned++;
}
}
student.append(rsection);
$("#allStudents1ProblemResults").append(student);

var collapseBody = $("<tr class='collapse out' id='submissionUser" + user.id + "'></tr>");
$("#allStudents1ProblemResults").append(collapseBody);

var myRows = [];
submissions.forEach( function (submission) {
var width = $( "#allStudents1ProblemTable" ).width();
var submissionRow = $("<tr class='hidden submissionUser" + user.id + "'>");
var d = new Date(submission.createdAt);
var a = $("<a></a>")
.attr("href","#submission")
Expand All @@ -183,20 +202,25 @@ function problemCorrect(user, problem, student, totalStudents){
.click(function (event) {
event.preventDefault();
getSubmission(submission,user,problem);
});
$("#submissionUser" + user.id)
.append($("<tr class='attemptProblem'></tr>")
.append($("<td></td>")
.append(a))
.append($("<td></td>")
.append(submission.value.correct + " /"))
.append($("<td></td>")
.append(" " + submission.value.style))

);
});
submissionRow.append("<td>");
submissionRow.append($("<td class='probStudentSubmissionTableTD'></td>").append(a));
var iconF = submission.value.correct == problem.value.correct ? correct("8px") : wrong("8px");
var iconS = submission.value.style == problem.value.style ? correct("8px") : wrong("8px");
submissionRow.append($("<td class='probStudentSubmissionTableTD'></td>").append("<span class='badge'>" + submission.value.correct + "/" + problem.value.correct+ "</span>").append(iconF));
submissionRow.append($("<td class='probStudentSubmissionTableTD'></td>").append("<span class='badge'>" + submission.value.style + "/" + problem.value.style+ "</span>").append(iconS));
myRows.push(submissionRow);
});

console.log("collpasemf");

student.append(rsectionF);
student.append(rsectionS);
$("#allStudents1ProblemResults").append(student);
for (var index = 0; index < myRows.length; index++) {
$("#allStudents1ProblemResults").append(myRows[index]);
}

//update progress labels
$("#function").empty().append(Math.floor((numfunct/total)*100)+"%");
$("#style").empty().append(Math.floor((numstyle/total)*100)+"%");
Expand Down
4 changes: 4 additions & 0 deletions views/home/admin.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ ul {
float:left;
width:50%
}
.probStudentSubmissionTableTD {
width: 15%;
text-align: center;
}
</style>
<script src="lib/codemirror.js"></script>
Expand Down

0 comments on commit cc50654

Please sign in to comment.