Commit 996b6fb6 by Bill Filler

more changes

parent 46aec4aa
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
this.Sequence = (function() { this.Sequence = (function() {
function Sequence(element) { function Sequence(element) {
var self = this; var self = this;
//alert("in Sequence for element" + element); console.log("in Sequence for element" + element);
this.removeBookmarkIconFromActiveNavItem = function(event) { this.removeBookmarkIconFromActiveNavItem = function(event) {
return Sequence.prototype.removeBookmarkIconFromActiveNavItem.apply(self, [event]); return Sequence.prototype.removeBookmarkIconFromActiveNavItem.apply(self, [event]);
}; };
...@@ -63,18 +63,20 @@ ...@@ -63,18 +63,20 @@
this.ajaxUrl = this.el.data('ajax-url'); this.ajaxUrl = this.el.data('ajax-url');
this.nextUrl = this.el.data('next-url'); this.nextUrl = this.el.data('next-url');
this.prevUrl = this.el.data('prev-url'); this.prevUrl = this.el.data('prev-url');
this.gateContent = this.el.data('gate-content'); this.gateContent = this.el.data('gate-content').toLowerCase();
this.prereqUrl = this.el.data('prereq-url'); this.prereqUrl = this.el.data('prereq-url');
this.prereqSectionName = this.el.data('prereq-section-name'); this.prereqSectionName = this.el.data('prereq-section-name');
this.unitName = this.el.data('unit-name'); this.unitName = this.el.data('unit-name');
this.scoreReached = this.el.data('score-reached'); this.scoreReached = this.el.data('score-reached').toLowerCase();
this.calculateScore = this.el.data('calculate-score'); this.calculateScore = this.el.data('calculate-score').toLowerCase();
this.keydownHandler($(element).find('#sequence-list .tab')); this.keydownHandler($(element).find('#sequence-list .tab'));
this.base_page_title = ($('title').data('base-title') || '').trim(); this.base_page_title = ($('title').data('base-title') || '').trim();
this.bind(); this.bind();
this.render(parseInt(this.el.data('position'), 10)); this.render(parseInt(this.el.data('position'), 10));
if (this.calculateScore) { console.log("calculateScore=" + this.calculateScore + " typeof=" + (typeof this.calculateScore));
this.recalcGrade(); if (this.calculateScore == "True" || this.calculateScore == "true") {
// TODO - remove setTimeout, just for testing
setTimeout(this.recalcGrade, 200);
} }
} }
...@@ -111,6 +113,9 @@ ...@@ -111,6 +113,9 @@
self.sr_container = self.$('.sr-is-focusable'); self.sr_container = self.$('.sr-is-focusable');
self.num_contents = self.contents.length; self.num_contents = self.contents.length;
self.bind(); self.bind();
// TODO - for some reason the content only renders for HTML
// And not for Problems/Videos. How to force rendering of
// the Xblocks?
self.render(1); self.render(1);
} }
); );
...@@ -134,14 +139,15 @@ ...@@ -134,14 +139,15 @@
self.gateContent = response.gate_content; self.gateContent = response.gate_content;
self.scoreReached = response.score_reached; self.scoreReached = response.score_reached;
self.calculateScore = response.calculate_score; self.calculateScore = response.calculate_score;
console.log("scoreReached=" + self.scoreReached + " type=" + (typeof self.scoreReached));
$('.ui-loading').hide(); $('.ui-loading').hide();
$('#main-content').html(response.html); $('#main-content').html(response.html);
if (self.scoreReached) { if (self.scoreReached == true) {
// if we reached the score, load the contents // if we reached the score, load the contents
// after a short delay // after a short delay
self.el.find('.icon .fa .fa-lock').removeClass('fa-lock').addClass('fa-unlock'); $('.fa-lock').removeClass('fa-lock').addClass('fa-unlock');
$('#loading-content').show(); $('#loading-content').show();
setTimeout(self.loadSeqContents, 6000); setTimeout(self.loadSeqContents, 3000);
} }
} }
); );
...@@ -240,7 +246,7 @@ ...@@ -240,7 +246,7 @@
* 'new_content_state' is the updated content of the problem. * 'new_content_state' is the updated content of the problem.
* 'new_state' is the updated state of the problem. * 'new_state' is the updated state of the problem.
*/ */
alert("in addToUpdatedProblems for problemId=" + problemId); console.log("in addToUpdatedProblems for problemId=" + problemId);
// initialize for the current sequence if there isn't any updated problem for this position. // initialize for the current sequence if there isn't any updated problem for this position.
if (!this.anyUpdatedProblems(this.position)) { if (!this.anyUpdatedProblems(this.position)) {
this.updatedProblems[this.position] = {}; this.updatedProblems[this.position] = {};
...@@ -325,7 +331,7 @@ ...@@ -325,7 +331,7 @@
if (this.anyUpdatedProblems(newPosition)) { if (this.anyUpdatedProblems(newPosition)) {
$.each(this.updatedProblems[newPosition], function(problemId, latestData) { $.each(this.updatedProblems[newPosition], function(problemId, latestData) {
alert("updating problem index=" + newPosition + " problemId=" + problemId); console.log("updating problem index=" + newPosition + " problemId=" + problemId);
var latestContent, latestResponse; var latestContent, latestResponse;
latestContent = latestData[0]; latestContent = latestData[0];
latestResponse = latestData[1]; latestResponse = latestData[1];
......
...@@ -208,7 +208,6 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule): ...@@ -208,7 +208,6 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule):
elif dispatch == 'recalc_grade': elif dispatch == 'recalc_grade':
# force a grade recalculation # force a grade recalculation
unlock = self._is_prereq_met(True) unlock = self._is_prereq_met(True)
unlock = True
params = { params = {
'gate_content': not unlock, 'gate_content': not unlock,
...@@ -350,8 +349,8 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule): ...@@ -350,8 +349,8 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule):
'prereq_url': milestone_meta_info['url'] if gate_content else None, 'prereq_url': milestone_meta_info['url'] if gate_content else None,
'prereq_section_name': milestone_meta_info['display_name'] if gate_content else None, 'prereq_section_name': milestone_meta_info['display_name'] if gate_content else None,
'unit_name': "My Unit", 'unit_name': "My Unit",
'score_reached': False, 'score_reached': not gate_content,
'calculate_score': True 'calculate_score': gate_content
} }
fragment.add_content(self.system.render_template("seq_module.html", params)) fragment.add_content(self.system.render_template("seq_module.html", params))
......
...@@ -6,6 +6,7 @@ from django.dispatch import receiver ...@@ -6,6 +6,7 @@ from django.dispatch import receiver
from gating import api as gating_api from gating import api as gating_api
from lms.djangoapps.grades.signals.signals import SUBSECTION_SCORE_CHANGED from lms.djangoapps.grades.signals.signals import SUBSECTION_SCORE_CHANGED
from openedx.core.djangoapps.signals.signals import COURSE_GRADE_CHANGED from openedx.core.djangoapps.signals.signals import COURSE_GRADE_CHANGED
import time
@receiver(SUBSECTION_SCORE_CHANGED) @receiver(SUBSECTION_SCORE_CHANGED)
...@@ -21,6 +22,8 @@ def evaluate_subsection_gated_milestones(**kwargs): ...@@ -21,6 +22,8 @@ def evaluate_subsection_gated_milestones(**kwargs):
None None
""" """
subsection_grade = kwargs['subsection_grade'] subsection_grade = kwargs['subsection_grade']
# TODO - for testing, remove
time.sleep(10)
gating_api.evaluate_prerequisite(kwargs['course'], subsection_grade, kwargs.get('user')) gating_api.evaluate_prerequisite(kwargs['course'], subsection_grade, kwargs.get('user'))
......
...@@ -36,7 +36,7 @@ from openedx.core.djangolib.markup import HTML, Text ...@@ -36,7 +36,7 @@ from openedx.core.djangolib.markup import HTML, Text
<p> <p>
% if score_reached: % if score_reached:
<h3> <h3>
<span class="icon fa fa-check-circle-o" aria-hidden="true">&nbsp</span>${_("Congratulations you have unlocked this section!")} <span class="icon fa fa-check-circle-o" style="color:green" aria-hidden="true">&nbsp</span>${_("Congratulations you have unlocked this section!")}
<div id="loading-content" class="ui-loading is-hidden"> <div id="loading-content" class="ui-loading is-hidden">
<p> <p>
<span class="spin"> <span class="spin">
...@@ -54,9 +54,6 @@ from openedx.core.djangolib.markup import HTML, Text ...@@ -54,9 +54,6 @@ from openedx.core.djangolib.markup import HTML, Text
<p> <p>
<button><a href="${prereq_url}">${_("Go to Prerequiste Section")}</a></button> <button><a href="${prereq_url}">${_("Go to Prerequiste Section")}</a></button>
</p> </p>
<p>
<button><span class="recalc-grade">Recalculate Grade</span></button>
</p>
% endif % endif
</p> </p>
</div> </div>
...@@ -371,12 +371,11 @@ def is_prereq_met(course_id, content_id, user_id, recalc_on_unmet=False): ...@@ -371,12 +371,11 @@ def is_prereq_met(course_id, content_id, user_id, recalc_on_unmet=False):
user_id: The id of the user user_id: The id of the user
recalc_on_unmet: Recalculate the grade if prereq has not yet been met recalc_on_unmet: Recalculate the grade if prereq has not yet been met
""" """
# first check source of truth.. the database
#prereq_met = milestones_api.user_has_milestone({'id': user_id}, milestone) #prereq_met = milestones_api.user_has_milestone({'id': user_id}, milestone)
# if unfullfilled milestones exist it means prereq has not been met
unfulfilled_milestones = milestones_api.get_course_content_milestones(course_id, content_id, 'requires', {'id': user_id}) unfulfilled_milestones = milestones_api.get_course_content_milestones(course_id, content_id, 'requires', {'id': user_id})
prereq_met = not unfulfilled_milestones prereq_met = not unfulfilled_milestones
if prereq_met or not recalc_on_unmet: if prereq_met or not recalc_on_unmet:
return prereq_met return prereq_met
...@@ -396,9 +395,11 @@ def is_prereq_met(course_id, content_id, user_id, recalc_on_unmet=False): ...@@ -396,9 +395,11 @@ def is_prereq_met(course_id, content_id, user_id, recalc_on_unmet=False):
subsection_percentage = _get_subsection_percentage(subsection_grade) subsection_percentage = _get_subsection_percentage(subsection_grade)
if subsection_percentage >= min_percentage: if subsection_percentage >= min_percentage:
prereq_met = True prereq_met = True
# TODO - should save to database here or let happen through async listener?
#milestones_helpers.add_user_milestone({'id': user.id}, prereq_milestone) #milestones_helpers.add_user_milestone({'id': user.id}, prereq_milestone)
else: else:
prereq_met = False prereq_met = False
# TODO - should save to database here or let happen through async listener
#milestones_helpers.remove_user_milestone({'id': user.id}, prereq_milestone) #milestones_helpers.remove_user_milestone({'id': user.id}, prereq_milestone)
return prereq_met return prereq_met
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment