Show finished learningSequences in LearningPathDiagram
This commit is contained in:
parent
cbbf4e42a2
commit
2557d478c9
|
|
@ -174,9 +174,10 @@ export default {
|
||||||
let pieWeights = new Array(Math.max(circle.learningSequences.length, 1)).fill(1)
|
let pieWeights = new Array(Math.max(circle.learningSequences.length, 1)).fill(1)
|
||||||
let pieGenerator = d3.pie()
|
let pieGenerator = d3.pie()
|
||||||
let pieData = pieGenerator(pieWeights)
|
let pieData = pieGenerator(pieWeights)
|
||||||
// _.forEach(pieData, function(pie) {
|
pieData.forEach((pie) => {
|
||||||
// pie.done = circle.learning_sequences.length === 0 ? false : circle.learning_sequences[parseInt(pie.index)].done
|
const lp = circle.learningSequences[parseInt(pie.index)];
|
||||||
// })
|
pie.done = circle.someFinishedInLearningSequence(lp.translation_key);
|
||||||
|
});
|
||||||
circle.pieData = pieData
|
circle.pieData = pieData
|
||||||
});
|
});
|
||||||
return internalCircles
|
return internalCircles
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,10 @@ export const useLearningPathStore = defineStore({
|
||||||
actions: {
|
actions: {
|
||||||
async loadLearningPath(slug: string) {
|
async loadLearningPath(slug: string) {
|
||||||
try {
|
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 = [];
|
this.learningPath.topics = [];
|
||||||
const emptyTopic: Topic = {
|
const emptyTopic: Topic = {
|
||||||
id: 0,
|
id: 0,
|
||||||
|
|
@ -43,6 +46,7 @@ export const useLearningPathStore = defineStore({
|
||||||
}
|
}
|
||||||
if (page.type === 'learnpath.Circle') {
|
if (page.type === 'learnpath.Circle') {
|
||||||
const circle = Circle.fromJson(page);
|
const circle = Circle.fromJson(page);
|
||||||
|
circle.parseCompletionData(completionData);
|
||||||
topic.circles.push(circle);
|
topic.circles.push(circle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
@ -23,6 +23,7 @@ class Migration(migrations.Migration):
|
||||||
('page_key', models.UUIDField()),
|
('page_key', models.UUIDField()),
|
||||||
('page_type', models.CharField(blank=True, default='', max_length=255)),
|
('page_type', models.CharField(blank=True, default='', max_length=255)),
|
||||||
('circle_key', models.UUIDField()),
|
('circle_key', models.UUIDField()),
|
||||||
|
('learning_path_key', models.UUIDField()),
|
||||||
('completed', models.BooleanField(default=False)),
|
('completed', models.BooleanField(default=False)),
|
||||||
('json_data', models.JSONField(blank=True, default=dict)),
|
('json_data', models.JSONField(blank=True, default=dict)),
|
||||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ class CircleCompletion(models.Model):
|
||||||
page_key = models.UUIDField()
|
page_key = models.UUIDField()
|
||||||
page_type = models.CharField(max_length=255, default='', blank=True)
|
page_type = models.CharField(max_length=255, default='', blank=True)
|
||||||
circle_key = models.UUIDField()
|
circle_key = models.UUIDField()
|
||||||
|
learning_path_key = models.UUIDField()
|
||||||
|
|
||||||
completed = models.BooleanField(default=False)
|
completed = models.BooleanField(default=False)
|
||||||
json_data = models.JSONField(default=dict, blank=True)
|
json_data = models.JSONField(default=dict, blank=True)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,6 @@ class CircleCompletionSerializer(serializers.ModelSerializer):
|
||||||
model = CircleCompletion
|
model = CircleCompletion
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'created_at', 'updated_at', 'user', 'page_key', 'page_type', 'circle_key',
|
'id', 'created_at', 'updated_at', 'user', 'page_key', 'page_type', 'circle_key',
|
||||||
'completed', 'json_data',
|
'learning_path_key', 'completed', 'json_data',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
from django.urls import path
|
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 = [
|
urlpatterns = [
|
||||||
path(r"circle/<uuid:circle_key>/", request_circle_completion, name="request_circle_completion"),
|
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"),
|
path(r"circle/mark/", mark_circle_completion, name="mark_circle_completion"),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ from wagtail.models import Page
|
||||||
|
|
||||||
from vbv_lernwelt.completion.models import CircleCompletion
|
from vbv_lernwelt.completion.models import CircleCompletion
|
||||||
from vbv_lernwelt.completion.serializers import CircleCompletionSerializer
|
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
|
from vbv_lernwelt.learnpath.utils import get_wagtail_type
|
||||||
|
|
||||||
logger = structlog.get_logger(__name__)
|
logger = structlog.get_logger(__name__)
|
||||||
|
|
@ -21,6 +21,16 @@ def request_circle_completion(request, circle_key):
|
||||||
return Response(status=200, data=response_data)
|
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'])
|
@api_view(['POST'])
|
||||||
def mark_circle_completion(request):
|
def mark_circle_completion(request):
|
||||||
page_key = request.data.get('page_key')
|
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 = Page.objects.get(translation_key=page_key, locale__language_code='de-CH')
|
||||||
page_type = get_wagtail_type(page.specific)
|
page_type = get_wagtail_type(page.specific)
|
||||||
circle = Circle.objects.ancestor_of(page).first()
|
circle = Circle.objects.ancestor_of(page).first()
|
||||||
|
learning_path = LearningPath.objects.ancestor_of(page).first()
|
||||||
|
|
||||||
cc, created = CircleCompletion.objects.get_or_create(
|
cc, created = CircleCompletion.objects.get_or_create(
|
||||||
user=request.user,
|
user=request.user,
|
||||||
page_key=page_key,
|
page_key=page_key,
|
||||||
circle_key=circle.translation_key,
|
circle_key=circle.translation_key,
|
||||||
|
learning_path_key=learning_path.translation_key,
|
||||||
)
|
)
|
||||||
cc.page_type = page_type
|
cc.page_type = page_type
|
||||||
cc.completed = completed
|
cc.completed = completed
|
||||||
|
|
|
||||||
|
|
@ -98,16 +98,12 @@ class Circle(Page):
|
||||||
FieldPanel('experts'),
|
FieldPanel('experts'),
|
||||||
]
|
]
|
||||||
|
|
||||||
@property
|
|
||||||
def learning_sequences(self):
|
|
||||||
return self.get_children().filter(content_type__model='learningsequence').values('id', 'title')
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_serializer_class(cls):
|
def get_serializer_class(cls):
|
||||||
return get_it_serializer_class(
|
return get_it_serializer_class(
|
||||||
cls,
|
cls,
|
||||||
field_names=[
|
field_names=[
|
||||||
'id', 'title', 'slug', 'type', 'translation_key', 'learning_sequences', 'children',
|
'id', 'title', 'slug', 'type', 'translation_key', 'children',
|
||||||
'description', 'job_situations', 'goals', 'experts',
|
'description', 'job_situations', 'goals', 'experts',
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -17,4 +17,4 @@ class LearningPathSerializer(get_it_serializer_class(LearningPath, [])):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Circle
|
model = Circle
|
||||||
fields = ['id', 'title', 'slug', 'children', 'type']
|
fields = ['id', 'title', 'slug', 'type', 'translation_key', 'children']
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue