Add frontend code
This commit is contained in:
parent
b8c4125b37
commit
f69b607ca8
|
|
@ -6,9 +6,14 @@ import ItDropdownSelect from "@/components/ui/ItDropdownSelect.vue";
|
||||||
import { computed, ref, watch } from "vue";
|
import { computed, ref, watch } from "vue";
|
||||||
import { useTranslation } from "i18next-vue";
|
import { useTranslation } from "i18next-vue";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import type { DashboardPersonCourseSessionType } from "@/services/dashboard";
|
import {
|
||||||
|
type DashboardPersonCourseSessionType,
|
||||||
|
exportPersons,
|
||||||
|
} from "@/services/dashboard";
|
||||||
import { useRouteQuery } from "@vueuse/router";
|
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");
|
log.debug("DashboardPersonsPage created");
|
||||||
|
|
||||||
|
|
@ -28,6 +33,7 @@ type MenuItem = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
const { loading, dashboardPersons } = useDashboardPersonsDueDates(props.mode);
|
const { loading, dashboardPersons } = useDashboardPersonsDueDates(props.mode);
|
||||||
|
|
||||||
|
|
@ -227,6 +233,32 @@ function personRoleDisplayValue(personCourseSession: DashboardPersonCourseSessio
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function exportData() {
|
||||||
|
const courseSessionIdsSet = new Set<string>();
|
||||||
|
// 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, () => {
|
watch(selectedCourse, () => {
|
||||||
selectedRegion.value = regions.value[0];
|
selectedRegion.value = regions.value[0];
|
||||||
});
|
});
|
||||||
|
|
@ -253,7 +285,18 @@ watch(selectedRegion, () => {
|
||||||
<it-icon-arrow-left class="-ml-1 mr-1 h-5 w-5"></it-icon-arrow-left>
|
<it-icon-arrow-left class="-ml-1 mr-1 h-5 w-5"></it-icon-arrow-left>
|
||||||
<span class="inline">{{ $t("general.back") }}</span>
|
<span class="inline">{{ $t("general.back") }}</span>
|
||||||
</router-link>
|
</router-link>
|
||||||
|
<div class="mb-10 flex items-center justify-between">
|
||||||
<h2 class="my-4">{{ $t("a.Personen") }}</h2>
|
<h2 class="my-4">{{ $t("a.Personen") }}</h2>
|
||||||
|
<button
|
||||||
|
v-if="userStore.course_session_experts.length > 0"
|
||||||
|
class="flex"
|
||||||
|
data-cy="export-button"
|
||||||
|
@click="exportData"
|
||||||
|
>
|
||||||
|
<it-icon-export></it-icon-export>
|
||||||
|
<span class="ml inline-block">{{ $t("a.Als Excel exportieren") }}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<div class="bg-white px-4 py-2">
|
<div class="bg-white px-4 py-2">
|
||||||
<section
|
<section
|
||||||
v-if="filtersVisible"
|
v-if="filtersVisible"
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,15 @@ export async function exportCompetenceElements(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function exportPersons(
|
||||||
|
data: XlsExportRequestData,
|
||||||
|
language: string
|
||||||
|
): Promise<XlsExportResponseData> {
|
||||||
|
return await itPost("/api/dashboard/export/persons/", data, {
|
||||||
|
headers: { "Accept-Language": language },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function courseIdForCourseSlug(
|
export function courseIdForCourseSlug(
|
||||||
dashboardConfigs: DashboardCourseConfigType[],
|
dashboardConfigs: DashboardCourseConfigType[],
|
||||||
courseSlug: string
|
courseSlug: string
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ from vbv_lernwelt.dashboard.views import (
|
||||||
export_attendance_as_xsl,
|
export_attendance_as_xsl,
|
||||||
export_competence_elements_as_xsl,
|
export_competence_elements_as_xsl,
|
||||||
export_feedback_as_xsl,
|
export_feedback_as_xsl,
|
||||||
|
export_persons_as_xsl,
|
||||||
get_dashboard_config,
|
get_dashboard_config,
|
||||||
get_dashboard_due_dates,
|
get_dashboard_due_dates,
|
||||||
get_dashboard_persons,
|
get_dashboard_persons,
|
||||||
|
|
@ -143,6 +144,7 @@ urlpatterns = [
|
||||||
path(r"api/dashboard/export/competence_elements/", export_competence_elements_as_xsl,
|
path(r"api/dashboard/export/competence_elements/", export_competence_elements_as_xsl,
|
||||||
name="export_certificate_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/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
|
# course
|
||||||
path(r"api/course/sessions/", get_course_sessions, name="get_course_sessions"),
|
path(r"api/course/sessions/", get_course_sessions, name="get_course_sessions"),
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,8 @@ def _add_rows(
|
||||||
users,
|
users,
|
||||||
course_session_id,
|
course_session_id,
|
||||||
):
|
):
|
||||||
|
idx_offset = 0
|
||||||
|
|
||||||
for row_idx, user in enumerate(users, start=2):
|
for row_idx, user in enumerate(users, start=2):
|
||||||
|
|
||||||
def get_user_cs_by_id(user_cs, cs_id):
|
def get_user_cs_by_id(user_cs, cs_id):
|
||||||
|
|
@ -91,17 +93,19 @@ def _add_rows(
|
||||||
user_id=user["user_id"],
|
user_id=user["user_id"],
|
||||||
course_session_id=course_session_id,
|
course_session_id=course_session_id,
|
||||||
)
|
)
|
||||||
|
idx_offset += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
user_role = (user_cs.get("user_role"),)
|
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=idx, column=1, value=user["first_name"])
|
||||||
sheet.cell(row=row_idx, column=2, value=user["last_name"])
|
sheet.cell(row=idx, column=2, value=user["last_name"])
|
||||||
sheet.cell(row=row_idx, column=3, value=user["email"])
|
sheet.cell(row=idx, column=3, value=user["email"])
|
||||||
sheet.cell(row=row_idx, column=4, value=user.get("Lehrvertragsnummer", ""))
|
sheet.cell(row=idx, column=4, value=user.get("Lehrvertragsnummer", ""))
|
||||||
sheet.cell(
|
sheet.cell(
|
||||||
row=row_idx,
|
row=idx,
|
||||||
column=5,
|
column=5,
|
||||||
value=user.get("phone", ""),
|
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])
|
||||||
|
|
|
||||||
|
|
@ -424,6 +424,7 @@ def export_persons_as_xsl(request):
|
||||||
) # noqa
|
) # noqa
|
||||||
|
|
||||||
data = export_persons(
|
data = export_persons(
|
||||||
|
request.user,
|
||||||
[cswr.id for cswr in course_sessions_with_roles],
|
[cswr.id for cswr in course_sessions_with_roles],
|
||||||
)
|
)
|
||||||
return _make_excel_response(data, PERSONS_EXPORT_FILENAME)
|
return _make_excel_response(data, PERSONS_EXPORT_FILENAME)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue