Hide export button for members
This commit is contained in:
parent
720130439b
commit
7dd38182fc
|
|
@ -7,6 +7,7 @@ import {
|
||||||
type DashboardPersonCourseSessionType,
|
type DashboardPersonCourseSessionType,
|
||||||
exportPersons,
|
exportPersons,
|
||||||
} from "@/services/dashboard";
|
} from "@/services/dashboard";
|
||||||
|
import { useCourseSessionsStore } from "@/stores/courseSessions";
|
||||||
import { useUserStore } from "@/stores/user";
|
import { useUserStore } from "@/stores/user";
|
||||||
import type { DashboardPersonsPageMode } from "@/types";
|
import type { DashboardPersonsPageMode } from "@/types";
|
||||||
import { openDataAsXls } from "@/utils/export";
|
import { openDataAsXls } from "@/utils/export";
|
||||||
|
|
@ -39,6 +40,7 @@ const userStore = useUserStore();
|
||||||
|
|
||||||
const { loading, dashboardPersons } = useDashboardPersonsDueDates(props.mode);
|
const { loading, dashboardPersons } = useDashboardPersonsDueDates(props.mode);
|
||||||
const { CHOSEN_PROFILE_TO_NAME } = useChosenProfileMapping();
|
const { CHOSEN_PROFILE_TO_NAME } = useChosenProfileMapping();
|
||||||
|
const { allCourseSessionActions } = useCourseSessionsStore();
|
||||||
|
|
||||||
const courses = computed(() => {
|
const courses = computed(() => {
|
||||||
return [
|
return [
|
||||||
|
|
@ -300,6 +302,25 @@ const filtersVisible = computed(() => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const canExport = computed(() => {
|
||||||
|
// If user is only member, he can't export
|
||||||
|
// member = has is_member property, but not is_expert or is_supervisor
|
||||||
|
if (!allCourseSessionActions.has("is_member")) {
|
||||||
|
// is berufsbildner or expert or supervisor
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
allCourseSessionActions.has("is_expert") ||
|
||||||
|
allCourseSessionActions.has("is_supervisor")
|
||||||
|
) {
|
||||||
|
// is member
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
function personRoleDisplayValue(personCourseSession: DashboardPersonCourseSessionType) {
|
function personRoleDisplayValue(personCourseSession: DashboardPersonCourseSessionType) {
|
||||||
if (
|
if (
|
||||||
[
|
[
|
||||||
|
|
@ -317,15 +338,9 @@ function personRoleDisplayValue(personCourseSession: DashboardPersonCourseSessio
|
||||||
}
|
}
|
||||||
|
|
||||||
async function exportData() {
|
async function exportData() {
|
||||||
const requestData = filteredPersons.value.reduce(
|
const requestData = {
|
||||||
(acc, person) => {
|
courseSessionUserIds: filteredPersons.value.map((person) => person.csu_id),
|
||||||
acc.courseSessionUserIds.push(person.csu_id);
|
};
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
{
|
|
||||||
courseSessionUserIds: [] as string[],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const data = await exportPersons(requestData, userStore.language);
|
const data = await exportPersons(requestData, userStore.language);
|
||||||
openDataAsXls(data.encoded_data, data.file_name);
|
openDataAsXls(data.encoded_data, data.file_name);
|
||||||
}
|
}
|
||||||
|
|
@ -358,7 +373,12 @@ watch(selectedRegion, () => {
|
||||||
</router-link>
|
</router-link>
|
||||||
<div class="mb-10 flex items-center justify-between">
|
<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 class="flex" data-cy="export-button" @click="exportData">
|
<button
|
||||||
|
v-if="canExport"
|
||||||
|
class="flex"
|
||||||
|
data-cy="export-button"
|
||||||
|
@click="exportData"
|
||||||
|
>
|
||||||
<it-icon-export></it-icon-export>
|
<it-icon-export></it-icon-export>
|
||||||
<span class="ml inline-block">{{ $t("a.Als Excel exportieren") }}</span>
|
<span class="ml inline-block">{{ $t("a.Als Excel exportieren") }}</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,18 @@ export const useCourseSessionsStore = defineStore("courseSessions", () => {
|
||||||
return Boolean(hasPreview && (inLearningPath() || inCompetenceProfile()));
|
return Boolean(hasPreview && (inLearningPath() || inCompetenceProfile()));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const allCourseSessionActions = computed(() => {
|
||||||
|
const actionsSet = new Set();
|
||||||
|
|
||||||
|
allCourseSessions.value.forEach((item) => {
|
||||||
|
item.actions.forEach((action) => {
|
||||||
|
actionsSet.add(action);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return actionsSet;
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
uniqueCourseSessionsByCourse,
|
uniqueCourseSessionsByCourse,
|
||||||
allCurrentCourseSessions,
|
allCurrentCourseSessions,
|
||||||
|
|
@ -146,5 +158,6 @@ export const useCourseSessionsStore = defineStore("courseSessions", () => {
|
||||||
|
|
||||||
// only used for unit testing
|
// only used for unit testing
|
||||||
allCourseSessions,
|
allCourseSessions,
|
||||||
|
allCourseSessionActions,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue