Show finished learningSequences in LearningPathDiagram

This commit is contained in:
Daniel Egger 2022-07-04 12:15:49 +02:00
parent cbbf4e42a2
commit 2557d478c9
9 changed files with 31 additions and 14 deletions

View File

@ -174,9 +174,10 @@ export default {
let pieWeights = new Array(Math.max(circle.learningSequences.length, 1)).fill(1)
let pieGenerator = d3.pie()
let pieData = pieGenerator(pieWeights)
// _.forEach(pieData, function(pie) {
// pie.done = circle.learning_sequences.length === 0 ? false : circle.learning_sequences[parseInt(pie.index)].done
// })
pieData.forEach((pie) => {
const lp = circle.learningSequences[parseInt(pie.index)];
pie.done = circle.someFinishedInLearningSequence(lp.translation_key);
});
circle.pieData = pieData
});
return internalCircles

View File

@ -22,7 +22,10 @@ export const useLearningPathStore = defineStore({
actions: {
async loadLearningPath(slug: string) {
try {
this.learningPath = await itGet(`/learnpath/api/learningpath/${slug}/`);
const learningPathData = await itGet(`/learnpath/api/learningpath/${slug}/`);
const completionData = await itGet(`/api/completion/learning_path/${learningPathData.translation_key}/`);
this.learningPath = learningPathData;
this.learningPath.topics = [];
const emptyTopic: Topic = {
id: 0,
@ -43,6 +46,7 @@ export const useLearningPathStore = defineStore({
}
if (page.type === 'learnpath.Circle') {
const circle = Circle.fromJson(page);
circle.parseCompletionData(completionData);
topic.circles.push(circle);
}

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2022-06-22 16:53
# Generated by Django 3.2.13 on 2022-07-04 09:58
from django.conf import settings
from django.db import migrations, models
@ -23,6 +23,7 @@ class Migration(migrations.Migration):
('page_key', models.UUIDField()),
('page_type', models.CharField(blank=True, default='', max_length=255)),
('circle_key', models.UUIDField()),
('learning_path_key', models.UUIDField()),
('completed', models.BooleanField(default=False)),
('json_data', models.JSONField(blank=True, default=dict)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),

View File

@ -15,6 +15,7 @@ class CircleCompletion(models.Model):
page_key = models.UUIDField()
page_type = models.CharField(max_length=255, default='', blank=True)
circle_key = models.UUIDField()
learning_path_key = models.UUIDField()
completed = models.BooleanField(default=False)
json_data = models.JSONField(default=dict, blank=True)

View File

@ -8,6 +8,6 @@ class CircleCompletionSerializer(serializers.ModelSerializer):
model = CircleCompletion
fields = [
'id', 'created_at', 'updated_at', 'user', 'page_key', 'page_type', 'circle_key',
'completed', 'json_data',
'learning_path_key', 'completed', 'json_data',
]

View File

@ -1,8 +1,10 @@
from django.urls import path
from vbv_lernwelt.completion.views import request_circle_completion, mark_circle_completion
from vbv_lernwelt.completion.views import request_circle_completion, mark_circle_completion, \
request_learning_path_completion
urlpatterns = [
path(r"circle/<uuid:circle_key>/", request_circle_completion, name="request_circle_completion"),
path(r"learning_path/<uuid:learning_path_key>/", request_learning_path_completion, name="request_learning_path_completion"),
path(r"circle/mark/", mark_circle_completion, name="mark_circle_completion"),
]

View File

@ -5,7 +5,7 @@ from wagtail.models import Page
from vbv_lernwelt.completion.models import CircleCompletion
from vbv_lernwelt.completion.serializers import CircleCompletionSerializer
from vbv_lernwelt.learnpath.models import Circle
from vbv_lernwelt.learnpath.models import Circle, LearningPath
from vbv_lernwelt.learnpath.utils import get_wagtail_type
logger = structlog.get_logger(__name__)
@ -21,6 +21,16 @@ def request_circle_completion(request, circle_key):
return Response(status=200, data=response_data)
@api_view(['GET'])
def request_learning_path_completion(request, learning_path_key):
response_data = CircleCompletionSerializer(
CircleCompletion.objects.filter(user=request.user, learning_path_key=learning_path_key),
many=True,
).data
return Response(status=200, data=response_data)
@api_view(['POST'])
def mark_circle_completion(request):
page_key = request.data.get('page_key')
@ -29,11 +39,13 @@ def mark_circle_completion(request):
page = Page.objects.get(translation_key=page_key, locale__language_code='de-CH')
page_type = get_wagtail_type(page.specific)
circle = Circle.objects.ancestor_of(page).first()
learning_path = LearningPath.objects.ancestor_of(page).first()
cc, created = CircleCompletion.objects.get_or_create(
user=request.user,
page_key=page_key,
circle_key=circle.translation_key,
learning_path_key=learning_path.translation_key,
)
cc.page_type = page_type
cc.completed = completed

View File

@ -98,16 +98,12 @@ class Circle(Page):
FieldPanel('experts'),
]
@property
def learning_sequences(self):
return self.get_children().filter(content_type__model='learningsequence').values('id', 'title')
@classmethod
def get_serializer_class(cls):
return get_it_serializer_class(
cls,
field_names=[
'id', 'title', 'slug', 'type', 'translation_key', 'learning_sequences', 'children',
'id', 'title', 'slug', 'type', 'translation_key', 'children',
'description', 'job_situations', 'goals', 'experts',
]
)

View File

@ -17,4 +17,4 @@ class LearningPathSerializer(get_it_serializer_class(LearningPath, [])):
class Meta:
model = Circle
fields = ['id', 'title', 'slug', 'children', 'type']
fields = ['id', 'title', 'slug', 'type', 'translation_key', 'children']