diff --git a/client/src/components/circle/LearningSequence.vue b/client/src/components/circle/LearningSequence.vue index c5993e26..fc62dca5 100644 --- a/client/src/components/circle/LearningSequence.vue +++ b/client/src/components/circle/LearningSequence.vue @@ -6,8 +6,10 @@ import ItCheckbox from '@/components/ui/ItCheckbox.vue'; const props = defineProps(['learningSequence', 'completionData']) const contentCompleted = (learningContent) => { - if (props.completionData?.json_data?.completed_learning_contents) { - return learningContent.translation_key in props.completionData.json_data.completed_learning_contents; + if (props.completionData?.completed_learning_contents) { + return props.completionData.completed_learning_contents.findIndex((e) => { + return e.learning_content_key === learningContent.translation_key && e.completed; + }) > 0; } return false; @@ -41,7 +43,7 @@ const contentCompleted = (learningContent) => { > {{ learningContent.contents[0].type }}: {{ learningContent.title }} diff --git a/client/src/views/CircleView.vue b/client/src/views/CircleView.vue index babf7a2a..12d25dde 100644 --- a/client/src/views/CircleView.vue +++ b/client/src/views/CircleView.vue @@ -17,12 +17,13 @@ export default { } }, methods: { - toggleLearningContentCheckbox(learningContent) { - log.debug('toggleLearningContentCheckbox', learningContent); + toggleLearningContentCheckbox(learningContent, completed=true) { + log.debug('toggleLearningContentCheckbox', learningContent, completed); console.log(learningContent); itPost('/api/completion/complete_learning_content/', { learning_content_key: learningContent.translation_key, + completed: completed, }).then((data) => { this.completionData = data; }); diff --git a/server/vbv_lernwelt/completion/serializers.py b/server/vbv_lernwelt/completion/serializers.py index eaa5a4af..9fd3d044 100644 --- a/server/vbv_lernwelt/completion/serializers.py +++ b/server/vbv_lernwelt/completion/serializers.py @@ -12,4 +12,7 @@ class UserCircleCompletionSerializer(serializers.ModelSerializer): class LearningContentCompletionSerializer(serializers.ModelSerializer): class Meta: model = LearningContentCompletion - fields = ['id', 'created_at', 'updated_at', 'user', 'learning_content_key', 'circle_key', 'json_data'] + fields = [ + 'id', 'created_at', 'updated_at', 'user', 'learning_content_key', 'circle_key', + 'completed', 'json_data', + ] diff --git a/server/vbv_lernwelt/completion/tests/test_api.py b/server/vbv_lernwelt/completion/tests/test_api.py index e257c11b..058956be 100644 --- a/server/vbv_lernwelt/completion/tests/test_api.py +++ b/server/vbv_lernwelt/completion/tests/test_api.py @@ -35,7 +35,7 @@ class CompletionApiTestCase(APITestCase): self.assertEqual(response.status_code, 200) self.assertEqual(response_json['circle_key'], circle_key) self.assertEqual( - response_json['json_data']['completed_learning_contents'][learning_content_key]['learning_content_key'], + response_json['completed_learning_contents'][learning_content_key]['learning_content_key'], learning_content_key ) @@ -47,7 +47,7 @@ class CompletionApiTestCase(APITestCase): self.assertEqual(response.status_code, 200) self.assertEqual(response_json['circle_key'], circle_key) self.assertEqual( - response_json['json_data']['completed_learning_contents'][learning_content_key]['learning_content_key'], + response_json['completed_learning_contents'][learning_content_key]['learning_content_key'], learning_content_key ) diff --git a/server/vbv_lernwelt/completion/views.py b/server/vbv_lernwelt/completion/views.py index 98f7b708..77e70cac 100644 --- a/server/vbv_lernwelt/completion/views.py +++ b/server/vbv_lernwelt/completion/views.py @@ -1,11 +1,9 @@ -from datetime import datetime - import structlog from rest_framework.decorators import api_view from rest_framework.response import Response from vbv_lernwelt.completion.models import LearningContentCompletion, UserCircleCompletion -from vbv_lernwelt.completion.serializers import UserCircleCompletionSerializer +from vbv_lernwelt.completion.serializers import UserCircleCompletionSerializer, LearningContentCompletionSerializer from vbv_lernwelt.learnpath.models import LearningContent logger = structlog.get_logger(__name__) @@ -18,30 +16,44 @@ def request_user_circle_completion(request, circle_key): circle_key=circle_key, ) + response_data = {} if ucc.count() > 0: - return Response(status=200, data=UserCircleCompletionSerializer(ucc.first()).data) - else: - return Response(status=200, data={}) + response_data = UserCircleCompletionSerializer(ucc.first()).data + + response_data['completed_learning_contents'] = LearningContentCompletionSerializer( + LearningContentCompletion.objects.filter(circle_key=circle_key, user=request.user), + many=True + ).data + + return Response(status=200, data=response_data) @api_view(['POST']) def complete_learning_content(request): learning_content_key = request.data.get('learning_content_key') + completed = request.data.get('completed', True) learning_content = LearningContent.objects.get(translation_key=learning_content_key) circle_key = learning_content.get_parent().translation_key - LearningContentCompletion.objects.get_or_create( + lcc, created = LearningContentCompletion.objects.get_or_create( user=request.user, learning_content_key=learning_content_key, circle_key=circle_key, ) + lcc.completed = completed + lcc.save() ucc, created = UserCircleCompletion.objects.get_or_create( user=request.user, circle_key=circle_key, ) - ucc.save() + + response_data = UserCircleCompletionSerializer(ucc).data + response_data['completed_learning_contents'] = LearningContentCompletionSerializer( + LearningContentCompletion.objects.filter(circle_key=circle_key, user=request.user), + many=True + ).data logger.debug( 'learning content completed', @@ -51,4 +63,4 @@ def complete_learning_content(request): user_id=request.user.id, ) - return Response(status=200, data=UserCircleCompletionSerializer(ucc).data) + return Response(status=200, data=response_data) diff --git a/tailwind/input.css b/tailwind/input.css index 4f68bab9..784c99aa 100644 --- a/tailwind/input.css +++ b/tailwind/input.css @@ -66,6 +66,5 @@ svg { hover:bg-sky-400 hover:border-sky-400 disabled:opacity-50 disabled:cursor-not-allowed } - }