Skip to content

Commit

Permalink
Show total score in assignment list
Browse files Browse the repository at this point in the history
  • Loading branch information
KrKOo committed Nov 5, 2024
1 parent 5444ae1 commit 710ff81
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/assignment_list/assignmentlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export class AssignmentList {
private load_list_success(data: string | any[]): void {
this.clear_list(false);

var total_score = 0;
var total_max_score = 0;
var len = data.length;
for (var i=0; i<len; i++) {
var element = document.createElement('div');
Expand All @@ -102,8 +104,16 @@ export class AssignmentList {
} else if (data[i]['status'] === 'submitted') {
this.submitted_element.append(element);
(<HTMLDivElement>this.submitted_element.children.namedItem('submitted_assignments_list_placeholder')).hidden = true;

if (data[i]['score'] != null && data[i]['max_score'] != null) {
total_score += data[i]['score'];
total_max_score += data[i]['max_score'];
}
}
}

var total_score_element = document.getElementById(this.options.get('total_score_id'));
total_score_element.innerText = total_score + '/' + total_max_score;

var assignments = this.fetched_element.getElementsByClassName('assignment-notebooks-link');
for(let a of assignments){
Expand Down Expand Up @@ -365,9 +375,9 @@ class Assignment {
score.setAttribute('style', 'text-align:left');
row.append(score);

var score_heading = document.getElementById(this.options.get('score_heading_id'));
var show_score = score_heading && this.data['score'] != null && this.data['max_score'] != null;
score_heading.style.visibility = show_score ? 'visible' : 'hidden';
var score_heading_element = document.getElementById(this.options.get('score_heading_id'));
var show_score = score_heading_element && this.data['score'] != null && this.data['max_score'] != null;
score_heading_element.style.visibility = show_score ? 'visible' : 'hidden';

var id, element;
var children = document.createElement('div');
Expand Down
5 changes: 5 additions & 0 deletions src/assignment_list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export class AssignmentListWidget extends Widget {
' </div>',
' </div>',
' </div>',
' <div class="panel-heading">',
' <span class="col-sm-6"><b>Total Score</b></span>',
' <b id="total-score"></b>',
' </div>',
' </div>',
' </div> ',
'</div>'
Expand All @@ -110,6 +114,7 @@ export class AssignmentListWidget extends Widget {
let options = new Map();
options.set('base_url',base_url);
options.set('score_heading_id', 'score-heading');
options.set('total_score_id', 'total-score');
var assignment_l = new AssignmentList(this,
'released_assignments_list',
'fetched_assignments_list',
Expand Down

0 comments on commit 710ff81

Please sign in to comment.