Skip to content

Commit

Permalink
Change points goal saving and modal
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelGusse committed Aug 8, 2024
1 parent 0ecb44c commit 1d124db
Show file tree
Hide file tree
Showing 27 changed files with 324 additions and 274 deletions.
2 changes: 1 addition & 1 deletion assets/css/main.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/css/main.css.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions assets/sass/legacy/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ file for all the components */
}
.progress .required-points {
position: absolute;
height: 20px;
border-left: 1px solid black;
height: 100%;
border-left: 2px solid black;
}
.glyphicon.red {
color: #ff7070;
Expand Down
2 changes: 1 addition & 1 deletion course/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from aplus.api import api_reverse
from exercise.models import SubmissionDraft
from lib.fields import UsersSearchSelectField
from .models import CourseModule, Enrollment, StudentGroup, StudentModuleGoal
from .models import Enrollment, StudentGroup
from userprofile.models import UserProfile


Expand Down
20 changes: 0 additions & 20 deletions course/migrations/0060_coursemodule_personalized_points_goal.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.11 on 2024-06-03 13:02
# Generated by Django 4.2.11 on 2024-08-07 12:27

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -8,7 +8,7 @@ class Migration(migrations.Migration):

dependencies = [
("userprofile", "0008_delete_studentmodulegoal"),
("course", "0061_remove_coursemodule_personalized_points_goal"),
("course", "0059_submissiontag"),
]

operations = [
Expand All @@ -24,7 +24,11 @@ class Migration(migrations.Migration):
verbose_name="ID",
),
),
("personalized_points_goal", models.IntegerField(default=0)),
(
"personalized_points_goal_percentage",
models.FloatField(default=100.0),
),
("personalized_points_goal_points", models.IntegerField(default=0)),
(
"module",
models.ForeignKey(
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion course/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ class StudentModuleGoal(models.Model):
student = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
module = models.ForeignKey(CourseModule, on_delete=models.CASCADE)
personalized_points_goal_percentage = models.FloatField(default=100.0)

personalized_points_goal_points = models.IntegerField(default=0)

class LearningObjectCategory(models.Model):
"""
Expand Down
17 changes: 6 additions & 11 deletions exercise/cache/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,13 +943,12 @@ def _generate_data(
elif entry.submission_count > 0:
self.confirmable_children = True

def _update_personalized_points():
print("Called update_personalized_points")
try:
self.personalized_points_module_goal = StudentModuleGoal.objects.get(module_id=module_id, student_id=user_id).personalized_points_goal_percentage
self.personalized_points_module_goal_points = ((self.personalized_points_module_goal*0.01) * self.max_points)
except StudentModuleGoal.DoesNotExist:
self.personalized_points_module_goal = None
try:
student_module_goal = StudentModuleGoal.objects.get(module_id=module_id, student_id=user_id)
self.personalized_points_module_goal = student_module_goal.personalized_points_goal_percentage
self.personalized_points_module_goal_points = student_module_goal.personalized_points_goal_points
except StudentModuleGoal.DoesNotExist:
pass

def add_points(children):
for entry in children:
Expand All @@ -959,7 +958,6 @@ def add_points(children):
add_points(entry.children)

add_points(self.children)
_update_personalized_points()
self._true_passed = self._true_passed and self._true_points >= self.points_to_pass
self._passed = self._passed and self._points >= self.points_to_pass

Expand All @@ -977,9 +975,6 @@ def add_points(children):
ModuleEntryBase: [self._params[:1]],
LearningObjectPoints: [proxy._params for proxy in self.children],
}

def update_personalized_points(self):
self._generate_data()


CachedPointsDataType = TypeVar("CachedPointsDataType", bound="CachedPointsData")
Expand Down
12 changes: 12 additions & 0 deletions exercise/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,15 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
class Meta:
model = Submission
fields = ['submitters']

class StudentModuleGoalForm(forms.Form):
personalized_points_goal_input = forms.CharField(
label=_('LABEL_POINTS_GOAL_INPUT'),
max_length=10,
widget=forms.TextInput(attrs={'style': 'width: 66px;', 'class': 'form-control'}),
)

class Meta():
fields = [
'personalized_points_goal_input',
]
20 changes: 0 additions & 20 deletions exercise/migrations/0051_baseexercise_personalized_points_goal.py

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions exercise/static/exercise/css/goal_points.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,3 @@
width: 3px;
background: repeating-linear-gradient(#005EB8, #005EB8 2px, transparent 2px, transparent 4px);
}
.progress .required-points {
position: absolute;
height: 100%;
width: 3px;
background: solid black;
}
84 changes: 84 additions & 0 deletions exercise/static/exercise/personalized_points_goal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
$(document).ready(function() {
const $pointsGoalForm = $('#pointsGoalForm');
$pointsGoalForm.on('submit', function(event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: $pointsGoalForm.attr('action'),
data: $pointsGoalForm.serialize(),
success: function(response) {
// Update page dynamically
const $progressElement = $('#progress-' + $pointsGoalForm.data('module-url'));
const $progressDiv = $progressElement.find('.progress');
let $goalPointsElement = $progressElement.find('.goal-points');
if ($goalPointsElement.length === 0) {
// Create the goal points bar if it does not exist
$goalPointsElement = $('<div>', {
id: 'goal-points',
class: 'goal-points',
css: {
left: response.personalized_points_goal_percentage + '%'
}
});
$progressDiv.append($goalPointsElement);
} else {
// Update the existing element
$goalPointsElement.css('left', response.personalized_points_goal_percentage + '%');
}

// Update the tooltip
if ($progressDiv.length) {
const tooltipTitle = $progressDiv.attr('data-original-title');
const $tempDiv = $('<div>').html(tooltipTitle);

// In the div find the span with the class personalized-points-text
let $spanElement = $tempDiv.find('span.personalized-points-text');

// If the span element does not exist, create it
if ($spanElement.length === 0) {
$tempDiv.append($pointsGoalForm.data('personalized-points-goal-text'));

$spanElement = $('<span>', {
class: 'personalized-points-text text-nowrap'
});
$tempDiv.append($spanElement);
}

// Replace the personalized points goal with the new one
$spanElement.html(response.personalized_points_goal_points);
const newTooltipTitle = $tempDiv.html();
$progressDiv.attr('data-original-title', newTooltipTitle);

// Update the progress-bar style
if (response.personalized_points_goal_points <= $pointsGoalForm.data('points')) {
$progressDiv.find('.progress-bar').removeClass('progress-bar-warning');
$progressDiv.find('.progress-bar').addClass('progress-bar-primary');
}
else {
$progressDiv.find('.progress-bar').removeClass('progress-bar-primary');
$progressDiv.find('.progress-bar').addClass('progress-bar-warning');
}
// Show the success alert
$('#success-alert').show();
setTimeout(function() {
$('#success-alert').hide();
}, 5000);
}
},
error: function(xhr, status, error) {
if (xhr.responseJSON.error === 'less_than_required') {
$('#danger-alert').show();
setTimeout(function() {
$('#danger-alert').hide();
}, 5000);
}
else {
$('#warning-alert').show();
setTimeout(function() {
$('#warning-alert').hide();
}, 5000);
}
}
});
});
});
4 changes: 2 additions & 2 deletions 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;{% translate 'PERSONALIZED_POINTS_GOAL' %}: &lt;span class='text-nowrap'&gt;{{ personalized_points_module_goal_points|floatformat:"0" }}&lt;/span&gt;{% endif %}"
{% if personalized_points_module_goal %} &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;{% 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 All @@ -19,6 +19,6 @@
<div class="required-points" style="left:{{ required_percentage }}%"></div>
{% endif %}
{% if personalized_points_module_goal %}
<div class="goal-points" style="left:{{ personalized_points_module_goal|floatformat:0 }}%"></div>
<div id="goal-points" class="goal-points" style="left:{{ personalized_points_module_goal|floatformat:0 }}%"></div>
{% endif %}
</div>
Loading

0 comments on commit 1d124db

Please sign in to comment.