Skip to content

Commit

Permalink
fix: feedback serializer and frontend model (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutV authored May 24, 2024
1 parent 61c07ed commit 7165746
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 59 deletions.
7 changes: 2 additions & 5 deletions backend/api/views/submission_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ def _add_feedback(self, request, **_) -> Response:
serializer = FeedbackSerializer(data=request.data, context=context)

if serializer.is_valid():
serializer.save(submission=submission)
return Response({
"message": "Success",
"feedback": serializer.data
})
serializer.save(submission=submission, author=request.user)
return Response(serializer.data)

return Response(serializer.errors, status=400)

Expand Down
18 changes: 9 additions & 9 deletions frontend/src/components/projects/ProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ const incomingProjects = computed<Project[]>(() => {

<template>
<div>
<!-- Show past projects switch -->
<div class="p-4 surface-100 inline-block mb-5">
<div class="flex gap-3 align-items-center">
<Checkbox input-id="show-past" v-model="showPast" binary />
<label for="show-past">
{{ t('components.list.showPastProjects') }}
</label>
</div>
</div>
<!-- Project list -->
<template v-if="sortedProjects.length > 0">
<!-- Show past projects switch -->
<div class="p-4 surface-100 inline-block mb-5">
<div class="flex gap-3 align-items-center">
<Checkbox input-id="show-past" v-model="showPast" binary />
<label for="show-past">
{{ t('components.list.showPastProjects') }}
</label>
</div>
</div>
<div class="grid nested-grid">
<div class="col-12 md:col-5">
<h2 class="mt-0">
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/submissions/AllSubmission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ const navigateToSubmission = (submissionId: string): void => {
}
.status {
&.passed {
background-color: var(--bg-primary);
color: var(--primary-color-text);
}
&.failed-structure {
background-color: indianred;
color: white;
Expand All @@ -137,6 +132,11 @@ const navigateToSubmission = (submissionId: string): void => {
&.failed-extra:not(.failed-structure) {
background-color: var(--secondary-color);
}
&.passed {
background-color: var(--primary-color);
color: var(--primary-color-text);
}
}
}
</style>
5 changes: 3 additions & 2 deletions frontend/src/types/Feedback.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { User } from '@/types/users/User.ts';
import { Submission } from '@/types/submission/Submission.ts';
import { type HyperlinkedRelation } from '@/types/ApiResponse.ts';
import { Teacher, type TeacherJSON } from '@/types/users/Teacher.ts';

export interface FeedbackJSON {
id: string;
message: string;
creation_date: string;
author: HyperlinkedRelation;
author: TeacherJSON;
submission: HyperlinkedRelation;
}

Expand All @@ -20,6 +21,6 @@ export class Feedback {
) {}

static fromJSON(data: FeedbackJSON): Feedback {
return new Feedback(data.id, data.message, new Date(data.creation_date));
return new Feedback(data.id, data.message, new Date(data.creation_date), Teacher.fromJSON(data.author));
}
}
56 changes: 18 additions & 38 deletions frontend/src/views/submissions/SubmissionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,22 @@ function editFeedback(feedback: Feedback): void {
}
/**
* Submit feedback depending if the feedback is being edited or created
* Submit feedback depending on if the feedback is being edited or created
*/
function submitFeedback(): void {
if (editedFeedback.value === null) {
createFeedback(feedbackTextValue.value, route.params.submissionId as string);
feedbackTextValue.value = '';
} else {
updateFeedback(feedbackTextValue.value, editedFeedback.value.id);
feedbackTextValue.value = '';
editedFeedback.value = null;
async function submitFeedback(): Promise<void> {
try {
if (editedFeedback.value === null) {
await createFeedback(feedbackTextValue.value, route.params.submissionId as string);
feedbackTextValue.value = '';
} else {
await updateFeedback(feedbackTextValue.value, editedFeedback.value.id);
feedbackTextValue.value = '';
editedFeedback.value = null;
}
await getFeedbackBySubmission(route.params.submissionId as string);
} catch (e) {
console.error(e);
}
getFeedbackBySubmission(route.params.submissionId as string);
}
/* Computed Properties */
Expand Down Expand Up @@ -154,7 +158,7 @@ watch(
</div>
</div>
<!-- Feedback section -->
<div class="col-8 md:col-7">
<div class="col-12 md:col-7">
<!-- Written Feedback overview -->
<div class="feedback-section mb-3">
<Title class="flex mb-3">Feedback</Title>
Expand Down Expand Up @@ -184,15 +188,15 @@ watch(
<p class="feedback-message">{{ feedback.message }}</p>
</div>
</div>
<p v-else class="pt-2 pl-2">{{ t('views.submissions.feedback.noFeedback') }}</p>
<p v-else class="pt-2">{{ t('views.submissions.feedback.noFeedback') }}</p>
</div>
<!-- Write feedback -->
<div v-if="user?.isTeacher()">
<form @submit.prevent="submitFeedback">
<Textarea
id="feedback"
v-model="feedbackTextValue"
class="w-full"
class="w-full h-10rem"
:placeholder="t('views.submissions.feedback.writeFeedback')"
/>
<Button
Expand All @@ -208,28 +212,4 @@ watch(
</BaseLayout>
</template>
<style scoped lang="scss">
.p-inputtextarea {
width: 100%;
height: 8rem;
}
.feedback-section {
border-bottom: 4px solid var(--primary-color);
}
.feedback-header {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
margin-bottom: 0.25rem;
}
.feedback-header-wrap {
border-bottom: 1px solid lightgray;
display: flex;
justify-content: space-between;
align-items: center;
}
.feedback-message {
word-wrap: break-word;
overflow-wrap: break-word;
width: 100%;
}
</style>
<style scoped lang="scss"></style>

0 comments on commit 7165746

Please sign in to comment.