From 710ff81e8df395bac2a710b22d09996aaa4b0d4a Mon Sep 17 00:00:00 2001 From: KrKOo Date: Tue, 5 Nov 2024 14:15:15 +0100 Subject: [PATCH] Show total score in assignment list --- src/assignment_list/assignmentlist.ts | 16 +++++++++++++--- src/assignment_list/index.ts | 5 +++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/assignment_list/assignmentlist.ts b/src/assignment_list/assignmentlist.ts index b7e11f85e..a59b6b6ff 100644 --- a/src/assignment_list/assignmentlist.ts +++ b/src/assignment_list/assignmentlist.ts @@ -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; ithis.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){ @@ -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'); diff --git a/src/assignment_list/index.ts b/src/assignment_list/index.ts index 6f12afe1a..58f6d9949 100644 --- a/src/assignment_list/index.ts +++ b/src/assignment_list/index.ts @@ -98,6 +98,10 @@ export class AssignmentListWidget extends Widget { ' ', ' ', ' ', + '
', + ' Total Score', + ' ', + '
', ' ', ' ', '' @@ -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',