From 927ede4e565f2b60915b0d265dc147c321446676 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 7 Aug 2023 08:14:47 +0900 Subject: [PATCH] Add assignment UI --- backend/examples/serializers.py | 28 +++++-- frontend/components/example/AudioList.vue | 74 +++++++++++++++---- frontend/components/example/DocumentList.vue | 74 +++++++++++++++---- frontend/components/example/ImageList.vue | 74 +++++++++++++++---- frontend/domain/models/example/example.ts | 9 ++- frontend/pages/projects/_id/dataset/index.vue | 29 ++++++++ frontend/plugins/repositories.ts | 4 +- .../example/apiAssignmentRepository.ts | 18 +++++ .../example/apiDocumentRepository.ts | 3 +- .../application/example/exampleData.ts | 4 +- 10 files changed, 266 insertions(+), 51 deletions(-) create mode 100644 frontend/repositories/example/apiAssignmentRepository.ts diff --git a/backend/examples/serializers.py b/backend/examples/serializers.py index acdbcfef..4ea517fe 100644 --- a/backend/examples/serializers.py +++ b/backend/examples/serializers.py @@ -17,9 +17,17 @@ class CommentSerializer(serializers.ModelSerializer): read_only_fields = ("user", "example") +class AssignmentSerializer(serializers.ModelSerializer): + class Meta: + model = Assignment + fields = ("id", "assignee", "example", "created_at", "updated_at") + read_only_fields = ("id", "created_at", "updated_at") + + class ExampleSerializer(serializers.ModelSerializer): annotation_approver = serializers.SerializerMethodField() is_confirmed = serializers.SerializerMethodField() + assignments = serializers.SerializerMethodField() @classmethod def get_annotation_approver(cls, instance): @@ -34,6 +42,16 @@ class ExampleSerializer(serializers.ModelSerializer): states = instance.states.filter(confirmed_by_id=user.id) return states.count() > 0 + def get_assignments(self, instance): + return [ + { + "id": assignment.id, + "assignee": assignment.assignee.username, + "assignee_id": assignment.assignee.id, + } + for assignment in instance.assignments.all() + ] + class Meta: model = Example fields = [ @@ -46,15 +64,9 @@ class ExampleSerializer(serializers.ModelSerializer): "is_confirmed", "upload_name", "score", + "assignments", ] - read_only_fields = ["filename", "is_confirmed", "upload_name"] - - -class AssignmentSerializer(serializers.ModelSerializer): - class Meta: - model = Assignment - fields = ("id", "assignee", "example", "created_at", "updated_at") - read_only_fields = ("id", "created_at", "updated_at") + read_only_fields = ["filename", "is_confirmed", "upload_name", "assignments"] class ExampleStateSerializer(serializers.ModelSerializer): diff --git a/frontend/components/example/AudioList.vue b/frontend/components/example/AudioList.vue index 887916ab..988a2858 100644 --- a/frontend/components/example/AudioList.vue +++ b/frontend/components/example/AudioList.vue @@ -43,8 +43,23 @@ -