Skip to content

Instantly share code, notes, and snippets.

@Synvox
Last active February 19, 2016 19:41
Show Gist options
  • Save Synvox/f52165e3e4ef33ee0d92 to your computer and use it in GitHub Desktop.
Save Synvox/f52165e3e4ef33ee0d92 to your computer and use it in GitHub Desktop.
Quiz Results
$(function() {
var getAttempts = function(url, cb){
$.get(url, function(result) {
var dom = $(result),
text = dom.find('label').eq(9).text().split(',')
attempts = text[0].split(' - ')[1],
completed = text[1].split(' - ')[1],
remaining = parseInt(attempts) - parseInt(completed.split(' ')[0])
cb(remaining, completed)
})
}
var getGrades = function(cb){
var orgUnitId = Number(window.location.href.split('/')[5].split('-')[0])
$.getJSON('/d2l/api/le/1.5/'+orgUnitId+'/grades/values/myGradeValues/', function(result) {
cb(result)
})
}
var getGrade = function(name, cb) {
getGrades(function(result){
for (var i in result) {
var item = result[i]
if (item.GradeObjectName.indexOf(name) === 0) {
var text = item.DisplayedGrade + ' (' + item.PointsNumerator + '/' + item.PointsDenominator + ')'
cb(text)
return;
}
}
})
}
var tables = $('table.homework')
tables.each(function(ind, ele){
var table = $(ele),
rows = table.find('tr')
table.find('th').last().after($('<th>').text('Completed'))
table.find('th').last().after($('<th>').text('Score'))
rows.each(function(ind2,ele2){
var row = $(ele2)
var url = row.find('a').attr('href'),
name = row.find('input[type="button"]').attr('title')
if (!url || !name) return // This table isn't set up.
var attempts = row.find('td').last(),
completed = $('<td>').css('text-align', 'center').insertAfter(attempts),
score = $('<td>').css('text-align', 'center').insertAfter(completed)
getAttempts(url, function(att, comp){
attempts.text(att)
completed.text(comp)
})
getGrade(name, function(text){
score.text(text)
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment