From df28c1188411f33b902b8e128c1e90904807faa7 Mon Sep 17 00:00:00 2001 From: bsilkyn Date: Tue, 7 May 2024 17:10:35 +0200 Subject: [PATCH] chore: add csv header + fix user type + convert score to score with max_score 10 #400 --- frontend/cypress.config.js | 2 +- frontend/src/components/projects/DownloadCSV.vue | 15 +++++++++------ frontend/src/types/users/Student.ts | 4 ++-- .../views/projects/roles/TeacherProjectView.vue | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/frontend/cypress.config.js b/frontend/cypress.config.js index 6b759d73..5975fc9d 100644 --- a/frontend/cypress.config.js +++ b/frontend/cypress.config.js @@ -2,7 +2,7 @@ import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { - baseUrl: 'http://nginx', + baseUrl: 'https://localhost', specPattern: 'src/test/e2e/**/*.cy.{js,jsx,ts,tsx}', }, }); diff --git a/frontend/src/components/projects/DownloadCSV.vue b/frontend/src/components/projects/DownloadCSV.vue index 508ac7a5..f668d757 100644 --- a/frontend/src/components/projects/DownloadCSV.vue +++ b/frontend/src/components/projects/DownloadCSV.vue @@ -3,11 +3,11 @@ import Button from 'primevue/button'; import { useI18n } from 'vue-i18n'; import { useGroup } from '@/composables/services/group.service.ts'; import { useStudents } from '@/composables/services/student.service.ts'; +import { type Project } from '@/types/Project.ts'; /* Props */ const props = defineProps<{ - projectId: string; - projectName: string; + project: Project; }>(); /* Injections */ @@ -15,6 +15,9 @@ const { t } = useI18n(); const { groups, getGroupsByProject } = useGroup(); const { students, getStudentsByGroup } = useStudents(); +/* Constants */ +const header = 'OrgDefinedId,Last Name,First Name,Email,Grade,End-of-Line Indicator\n'; + /* Functions */ /** * generateCSVAndDownload generates a csv combining all the scores for all students in all groups associated @@ -23,7 +26,7 @@ const { students, getStudentsByGroup } = useStudents(); */ const generateCSVAndDownload = async (): Promise => { // retrieve all the groups associated with a given project - await getGroupsByProject(props.projectId); + await getGroupsByProject(props.project.id); // construct for every group's student a csv line according to ufora grade csv standard // and concatenate them all into one csv const csvPromises = @@ -33,14 +36,14 @@ const generateCSVAndDownload = async (): Promise => { students.value ?.map((student) => { // single csv line - return `#${student.id},${student.last_name},${student.first_name},${student.email},${group.score},#`; + return `#${student.student_id},${student.last_name},${student.first_name},${student.email},${group.score * 10 / props.project.max_score},#`; }) .join('\n') ?? '' ); }) ?? []; const csvList = await Promise.all(csvPromises); - const csvContent = csvList.join('\n'); + const csvContent = header + csvList.join('\n'); // create a blob from the csv content const blob = new Blob([csvContent], { type: 'text/plain' }); @@ -51,7 +54,7 @@ const generateCSVAndDownload = async (): Promise => { // create an anchor element for downloading the file const a = document.createElement('a'); a.href = url; - a.download = props.projectName + '.csv'; + a.download = props.project.name + '.csv'; // click anchor element a.click(); diff --git a/frontend/src/types/users/Student.ts b/frontend/src/types/users/Student.ts index 8ba17f8c..34285a98 100644 --- a/frontend/src/types/users/Student.ts +++ b/frontend/src/types/users/Student.ts @@ -14,7 +14,7 @@ export class Student extends User { public last_enrolled: number, public create_time: Date, public last_login: Date | null, - public studentId: string, + public student_id: string, public roles: Role[] = [], public courses: Course[] = [], public groups: Group[] = [], @@ -51,7 +51,7 @@ export class Student extends User { student.last_enrolled, new Date(student.create_time), student.last_login !== null ? new Date(student.last_login) : null, - student.studentId, + student.student_id, ); } diff --git a/frontend/src/views/projects/roles/TeacherProjectView.vue b/frontend/src/views/projects/roles/TeacherProjectView.vue index 513c1839..10385344 100644 --- a/frontend/src/views/projects/roles/TeacherProjectView.vue +++ b/frontend/src/views/projects/roles/TeacherProjectView.vue @@ -39,7 +39,7 @@ defineProps<{