Skip to content

Commit

Permalink
Fix tooltip update on removal
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelGusse committed Aug 15, 2024
1 parent debfa75 commit 7e200b7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
4 changes: 2 additions & 2 deletions exercise/static/exercise/personalized_points_goal.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $(document).ready(function() {
spanElement = doc.createElement('span');
spanElement.className = 'personalized-points-full-text text-nowrap';
doc.body.appendChild(spanElement);
spanElement.innerHTML = "<br>" + $pointsGoalForm.data('personalized-points-goal-tooltip-text') + ": " + response.personalized_points_goal_points;
spanElement.innerHTML = "<br>" + $pointsGoalForm.data('personalized-points-goal-tooltip-text') + ": " + "<span class=\"personalized-points-text text-nowrap\">" + response.personalized_points_goal_points + "</span>";
}
else {
spanElement.textContent = response.personalized_points_goal_points;
Expand Down Expand Up @@ -127,7 +127,7 @@ $(document).ready(function() {

// Update progress-bar style
$progressDiv.find('.progress-bar').removeClass('progress-bar-primary');

$('#remove-success-alert').show();
setTimeout(function() {
$('#remove-success-alert').hide();
Expand Down
2 changes: 1 addition & 1 deletion exercise/templates/exercise/_points_progress.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="progress" data-toggle="tooltip" data-html="true" data-placement="bottom"
title="{% translate 'POINTS' %}: &lt;span class='text-nowrap'&gt;{{ formatted_points }} / {{ max }}&lt;/span&gt;
{% if required %} &lt;br&gt; {% translate 'POINTS_TO_PASS' %}: &lt;span class='text-nowrap'&gt;{{ required }}&lt;/span&gt; {% endif %}
{% if personalized_points_module_goal %} &lt;br&gt;&lt;span class='personalized-points-full-text text-nowrap'&gt;{% translate 'PERSONALIZED_POINTS_GOAL' %}: &lt;span class='personalized-points-text text-nowrap'&gt;&lt;/span&gt;{{ personalized_points_module_goal_points|floatformat:"0" }}&lt;/span&gt;{% endif %}"
{% if personalized_points_module_goal %} &lt;span class='personalized-points-full-text text-nowrap'&gt; &lt;br&gt;{% translate 'PERSONALIZED_POINTS_GOAL' %}: &lt;span class='personalized-points-text text-nowrap'&gt;{{ personalized_points_module_goal_points|floatformat:"0" }}&lt;/span&gt;&lt;/span&gt;{% endif %}"
>
<div class="progress-bar progress-bar-striped progress-bar-{% if full_score %}success{% elif percentage >= personalized_points_module_goal %}primary{% elif passed %}warning{% else %}danger{% endif %}"
rel="progressbar" aria-valuenow="{{ points }}" aria-valuemin="0" aria-valuemax="{{ max }}"
Expand Down
13 changes: 4 additions & 9 deletions exercise/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,14 +620,14 @@ def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> JsonResponse:
module_slug = self.kwargs['module_slug']
points_goal = request.POST.get('personalized_points_goal_input')
delete = request.POST.get('delete')
student = UserProfile.objects.get(id=user_id)
module = CourseModule.objects.get(url=module_slug)
cached_points = CachedPoints(module.course_instance, student, True)
cached_module, _, _, _ = cached_points.find(module)

if delete:
student = UserProfile.objects.get(id=user_id)
module = CourseModule.objects.get(url=module_slug)
try:
StudentModuleGoal.objects.get(student=user_id, module=module.id).delete()
cached_points = CachedPoints(module.course_instance, student, True)
cached_module, _, _, _ = cached_points.find(module)
cached_points.invalidate(module.course_instance, student)
return JsonResponse({"success": "deleted"}, status=200)
except Exception as e:
Expand All @@ -636,11 +636,6 @@ def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> JsonResponse:
if not points_goal.replace('%', '').isdigit() and not points_goal.isdigit():
return JsonResponse({"error": "not_a_number"}, status=400)

# Get the StudentModuleGoal object for the student and module
student = UserProfile.objects.get(id=user_id)
module = CourseModule.objects.get(url=module_slug)
cached_points = CachedPoints(module.course_instance, student, True)
cached_module, _, _, _ = cached_points.find(module)
# Points goal can either be an integer or percentage. If the the points goal is given as a percentage,
# give it to the points goal directly. Otherwise calculate the points goal by taking the integer
# and calculating how much that is of the module's max points
Expand Down

0 comments on commit 7e200b7

Please sign in to comment.