diff --git a/client/src/pages/dashboard/DashboardPersonsPage.vue b/client/src/pages/dashboard/DashboardPersonsPage.vue index 59557836..77256adb 100644 --- a/client/src/pages/dashboard/DashboardPersonsPage.vue +++ b/client/src/pages/dashboard/DashboardPersonsPage.vue @@ -6,9 +6,14 @@ import ItDropdownSelect from "@/components/ui/ItDropdownSelect.vue"; import { computed, ref, watch } from "vue"; import { useTranslation } from "i18next-vue"; import _ from "lodash"; -import type { DashboardPersonCourseSessionType } from "@/services/dashboard"; +import { + type DashboardPersonCourseSessionType, + exportPersons, +} from "@/services/dashboard"; import { useRouteQuery } from "@vueuse/router"; -import type { DashboardPersonsPageMode } from "@/types"; +import type { DashboardPersonsPageMode, StatisticsFilterItem } from "@/types"; +import { useUserStore } from "@/stores/user"; +import { exportDataAsXls } from "@/utils/export"; log.debug("DashboardPersonsPage created"); @@ -28,6 +33,7 @@ type MenuItem = { }; const { t } = useTranslation(); +const userStore = useUserStore(); const { loading, dashboardPersons } = useDashboardPersonsDueDates(props.mode); @@ -227,6 +233,32 @@ function personRoleDisplayValue(personCourseSession: DashboardPersonCourseSessio return ""; } +function exportData() { + const courseSessionIdsSet = new Set(); + // get all course session ids from users + if (selectedSession.value.id === UNFILTERED) { + for (const person of filteredPersons.value) { + for (const courseSession of person.course_sessions) { + courseSessionIdsSet.add(courseSession.id); + } + } + } else { + courseSessionIdsSet.add(selectedSession.value.id); + } + + // construct StatisticsFilterItems for export call + const items: StatisticsFilterItem[] = []; + for (const csId of courseSessionIdsSet) { + items.push({ + _id: "", + course_session_id: csId, + generation: "", + circle_id: "", + }); + } + exportDataAsXls(items, exportPersons, userStore.language); +} + watch(selectedCourse, () => { selectedRegion.value = regions.value[0]; }); @@ -253,7 +285,18 @@ watch(selectedRegion, () => { {{ $t("general.back") }} -

{{ $t("a.Personen") }}

+
+

{{ $t("a.Personen") }}

+ +
{ + return await itPost("/api/dashboard/export/persons/", data, { + headers: { "Accept-Language": language }, + }); +} + export function courseIdForCourseSlug( dashboardConfigs: DashboardCourseConfigType[], courseSlug: string diff --git a/server/config/urls.py b/server/config/urls.py index eeaaa517..79f0bcd7 100644 --- a/server/config/urls.py +++ b/server/config/urls.py @@ -44,6 +44,7 @@ from vbv_lernwelt.dashboard.views import ( export_attendance_as_xsl, export_competence_elements_as_xsl, export_feedback_as_xsl, + export_persons_as_xsl, get_dashboard_config, get_dashboard_due_dates, get_dashboard_persons, @@ -143,6 +144,7 @@ urlpatterns = [ path(r"api/dashboard/export/competence_elements/", export_competence_elements_as_xsl, name="export_certificate_as_xsl"), path(r"api/dashboard/export/feedback/", export_feedback_as_xsl, name="export_feedback_as_xsl"), + path(r"api/dashboard/export/persons/", export_persons_as_xsl, name="export_persons_as_xsl"), # course path(r"api/course/sessions/", get_course_sessions, name="get_course_sessions"), diff --git a/server/vbv_lernwelt/dashboard/person_export.py b/server/vbv_lernwelt/dashboard/person_export.py index 0c7e5eae..e9a0495a 100644 --- a/server/vbv_lernwelt/dashboard/person_export.py +++ b/server/vbv_lernwelt/dashboard/person_export.py @@ -78,6 +78,8 @@ def _add_rows( users, course_session_id, ): + idx_offset = 0 + for row_idx, user in enumerate(users, start=2): def get_user_cs_by_id(user_cs, cs_id): @@ -91,17 +93,19 @@ def _add_rows( user_id=user["user_id"], course_session_id=course_session_id, ) + idx_offset += 1 continue user_role = (user_cs.get("user_role"),) + idx = row_idx - idx_offset - sheet.cell(row=row_idx, column=1, value=user["first_name"]) - sheet.cell(row=row_idx, column=2, value=user["last_name"]) - sheet.cell(row=row_idx, column=3, value=user["email"]) - sheet.cell(row=row_idx, column=4, value=user.get("Lehrvertragsnummer", "")) + sheet.cell(row=idx, column=1, value=user["first_name"]) + sheet.cell(row=idx, column=2, value=user["last_name"]) + sheet.cell(row=idx, column=3, value=user["email"]) + sheet.cell(row=idx, column=4, value=user.get("Lehrvertragsnummer", "")) sheet.cell( - row=row_idx, + row=idx, column=5, value=user.get("phone", ""), ) - sheet.cell(row=row_idx, column=6, value=user_role[0]) + sheet.cell(row=idx, column=6, value=user_role[0]) diff --git a/server/vbv_lernwelt/dashboard/views.py b/server/vbv_lernwelt/dashboard/views.py index 290397fd..11f58563 100644 --- a/server/vbv_lernwelt/dashboard/views.py +++ b/server/vbv_lernwelt/dashboard/views.py @@ -424,6 +424,7 @@ def export_persons_as_xsl(request): ) # noqa data = export_persons( + request.user, [cswr.id for cswr in course_sessions_with_roles], ) return _make_excel_response(data, PERSONS_EXPORT_FILENAME)