parent
81109a634c
commit
f3e521f813
@ -1,150 +1,178 @@ |
|||||||
import { useI18n } from "vue-i18n" |
import { useI18n } from "vue-i18n" |
||||||
|
import { ref, onMounted, watch } from "vue" |
||||||
import { useSecurityStore } from "../store/securityStore" |
import { useSecurityStore } from "../store/securityStore" |
||||||
import { usePlatformConfig } from "../store/platformConfig" |
import { usePlatformConfig } from "../store/platformConfig" |
||||||
|
import { useEnrolledStore } from "../store/enrolledStore" |
||||||
|
|
||||||
export function useSidebarMenu() { |
export function useSidebarMenu() { |
||||||
const { t } = useI18n() |
const { t } = useI18n() |
||||||
const securityStore = useSecurityStore() |
const securityStore = useSecurityStore() |
||||||
const platformConfigStore = usePlatformConfig() |
const platformConfigStore = usePlatformConfig() |
||||||
|
const enrolledStore = useEnrolledStore() |
||||||
const showTabsSetting = platformConfigStore.getSetting("platform.show_tabs") |
const showTabsSetting = platformConfigStore.getSetting("platform.show_tabs") |
||||||
|
|
||||||
const items = [] |
const items = ref([]) |
||||||
|
const coursesItems = ref([]) |
||||||
|
|
||||||
if (showTabsSetting.indexOf("campus_homepage") > -1) { |
const updateItems = () => { |
||||||
items.push({ |
items.value = [] |
||||||
icon: "mdi mdi-home", |
|
||||||
label: t("Home"), |
|
||||||
to: { name: "Home" }, |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
if (securityStore.isAuthenticated) { |
|
||||||
if (showTabsSetting.indexOf("campus_homepage") > -1) { |
if (showTabsSetting.indexOf("campus_homepage") > -1) { |
||||||
items.push({ |
items.value.push({ |
||||||
icon: "mdi mdi-book-open-page-variant", |
icon: "mdi mdi-home", |
||||||
|
label: t("Home"), |
||||||
|
to: { name: "Home" }, |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
if (securityStore.isAuthenticated) { |
||||||
|
if (coursesItems.value.length > 0) { |
||||||
|
const coursesMenu = { |
||||||
|
icon: "mdi mdi-book-open-page-variant", |
||||||
|
label: coursesItems.value.length > 1 ? t("Courses") : coursesItems.value[0].label, |
||||||
|
items: coursesItems.value.length > 1 ? coursesItems.value : undefined, |
||||||
|
to: coursesItems.value.length === 1 ? coursesItems.value[0].to : undefined, |
||||||
|
} |
||||||
|
items.value.push(coursesMenu) |
||||||
|
} |
||||||
|
|
||||||
|
if (showTabsSetting.indexOf("my_agenda") > -1) { |
||||||
|
items.value.push({ |
||||||
|
icon: "mdi mdi-calendar-text", |
||||||
|
label: t("Events"), |
||||||
|
to: { name: "CCalendarEventList" }, |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
if (showTabsSetting.indexOf("reporting") > -1) { |
||||||
|
let subItems = [] |
||||||
|
|
||||||
|
if (securityStore.isTeacher || securityStore.isHRM || securityStore.isSessionAdmin) { |
||||||
|
subItems.push({ |
||||||
|
label: securityStore.isHRM ? t("Course sessions") : t("Reporting"), |
||||||
|
url: "/main/my_space/" + (securityStore.isHRM ? "session.php" : "index.php"), |
||||||
|
}) |
||||||
|
} else if (securityStore.isStudentBoss) { |
||||||
|
subItems.push({ |
||||||
|
label: t("Learners"), |
||||||
|
url: "/main/my_space/student.php", |
||||||
|
}) |
||||||
|
} else { |
||||||
|
subItems.push({ |
||||||
|
label: t("Progress"), |
||||||
|
url: "/main/auth/my_progress.php", |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
items.value.push({ |
||||||
|
icon: "mdi mdi-chart-box", |
||||||
|
label: t("Reporting"), |
||||||
|
items: subItems, |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
if (showTabsSetting.indexOf("social") > -1) { |
||||||
|
items.value.push({ |
||||||
|
icon: "mdi mdi-sitemap-outline", |
||||||
|
label: t("Social network"), |
||||||
|
to: { name: "SocialWall" }, |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
if (platformConfigStore.plugins?.bbb?.show_global_conference_link) { |
||||||
|
items.value.push({ |
||||||
|
icon: "mdi mdi-video", |
||||||
|
label: t("Videoconference"), |
||||||
|
url: platformConfigStore.plugins.bbb.listingURL, |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (securityStore.isStudentBoss || securityStore.isStudent) { |
||||||
|
items.value.push({ |
||||||
|
icon: "mdi mdi-text-box-search", |
||||||
items: [ |
items: [ |
||||||
{ |
{ |
||||||
label: t("My courses"), |
label: t("Diagnosis Management"), |
||||||
to: { name: "MyCourses" }, |
url: "/main/search/load_search.php", |
||||||
|
visible: securityStore.isStudentBoss, |
||||||
}, |
}, |
||||||
{ |
{ |
||||||
label: t("My sessions"), |
label: t("Diagnostic Form"), |
||||||
to: { name: "MySessions" }, |
url: "/main/search/search.php", |
||||||
}, |
}, |
||||||
], |
], |
||||||
label: t("Courses"), |
label: t("Diagnosis"), |
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
if (showTabsSetting.indexOf("my_agenda") > -1) { |
|
||||||
items.push({ |
|
||||||
icon: "mdi mdi-calendar-text", |
|
||||||
label: t("Events"), |
|
||||||
to: { name: "CCalendarEventList" }, |
|
||||||
}) |
}) |
||||||
} |
} |
||||||
|
|
||||||
if (showTabsSetting.indexOf("reporting") > -1) { |
if (securityStore.isAdmin || securityStore.isSessionAdmin) { |
||||||
let subItems = [] |
const adminItems = [ |
||||||
|
{ |
||||||
|
label: t("Administration"), |
||||||
|
to: { name: "AdminIndex" }, |
||||||
|
}, |
||||||
|
] |
||||||
|
|
||||||
if (securityStore.isTeacher || securityStore.isHRM || securityStore.isSessionAdmin) { |
if (securityStore.isSessionAdmin && 'true' === platformConfigStore.getSetting('session.limit_session_admin_list_users')) { |
||||||
subItems.push({ |
adminItems.push({ |
||||||
label: securityStore.isHRM ? t("Course sessions") : t("Reporting"), |
label: t("Add user"), |
||||||
url: "/main/my_space/" + (securityStore.isHRM ? "session.php" : "index.php"), |
url: "/main/admin/user_add.php", |
||||||
}) |
|
||||||
} else if (securityStore.isStudentBoss) { |
|
||||||
subItems.push({ |
|
||||||
label: t("Learners"), |
|
||||||
url: "/main/my_space/student.php", |
|
||||||
}) |
}) |
||||||
} else { |
} else { |
||||||
subItems.push({ |
adminItems.push({ |
||||||
label: t("Progress"), |
label: t("Users"), |
||||||
url: "/main/auth/my_progress.php", |
url: "/main/admin/user_list.php", |
||||||
}) |
}) |
||||||
} |
} |
||||||
|
|
||||||
items.push({ |
if (securityStore.isAdmin) { |
||||||
icon: "mdi mdi-chart-box", |
adminItems.push({ |
||||||
label: t("Reporting"), |
label: t("Courses"), |
||||||
items: subItems, |
url: "/main/admin/course_list.php", |
||||||
}) |
}) |
||||||
} |
} |
||||||
|
|
||||||
if (showTabsSetting.indexOf("social") > -1) { |
adminItems.push({ |
||||||
items.push({ |
label: t("Sessions"), |
||||||
icon: "mdi mdi-sitemap-outline", |
url: "/main/session/session_list.php", |
||||||
label: t("Social network"), |
|
||||||
to: { name: "SocialWall" }, |
|
||||||
}) |
}) |
||||||
} |
|
||||||
|
|
||||||
if (platformConfigStore.plugins?.bbb?.show_global_conference_link) { |
items.value.push({ |
||||||
items.push({ |
icon: "mdi mdi-cog", |
||||||
icon: "mdi mdi-video", |
items: adminItems, |
||||||
label: t("Videoconference"), |
label: t("Administration"), |
||||||
url: platformConfigStore.plugins.bbb.listingURL, |
|
||||||
}) |
}) |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
if (securityStore.isStudentBoss || securityStore.isStudent) { |
const updateCoursesItems = () => { |
||||||
items.push({ |
coursesItems.value = []; |
||||||
icon: "mdi mdi-text-box-search", |
|
||||||
items: [ |
|
||||||
{ |
|
||||||
label: t("Diagnosis Management"), |
|
||||||
url: "/main/search/load_search.php", |
|
||||||
visible: securityStore.isStudentBoss, |
|
||||||
}, |
|
||||||
{ |
|
||||||
label: t("Diagnostic Form"), |
|
||||||
url: "/main/search/search.php", |
|
||||||
}, |
|
||||||
], |
|
||||||
label: t("Diagnosis"), |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
if (securityStore.isAdmin || securityStore.isSessionAdmin) { |
|
||||||
const adminItems = [ |
|
||||||
{ |
|
||||||
label: t("Administration"), |
|
||||||
to: { name: "AdminIndex" }, |
|
||||||
}, |
|
||||||
] |
|
||||||
|
|
||||||
if (securityStore.isSessionAdmin && 'true' === platformConfigStore.getSetting('session.limit_session_admin_list_users')) { |
if (enrolledStore.isEnrolledInCourses) { |
||||||
adminItems.push({ |
coursesItems.value.push({ |
||||||
label: t("Add user"), |
label: t("My courses"), |
||||||
url: "/main/admin/user_add.php", |
to: { name: "MyCourses" }, |
||||||
}) |
|
||||||
} else { |
|
||||||
adminItems.push({ |
|
||||||
label: t("Users"), |
|
||||||
url: "/main/admin/user_list.php", |
|
||||||
}) |
}) |
||||||
} |
} |
||||||
|
|
||||||
if (securityStore.isAdmin) { |
if (enrolledStore.isEnrolledInSessions) { |
||||||
adminItems.push({ |
coursesItems.value.push({ |
||||||
label: t("Courses"), |
label: t("My sessions"), |
||||||
url: "/main/admin/course_list.php", |
to: { name: "MySessions" }, |
||||||
}) |
}) |
||||||
} |
} |
||||||
|
|
||||||
adminItems.push({ |
updateItems(); |
||||||
label: t("Sessions"), |
|
||||||
url: "/main/session/session_list.php", |
|
||||||
}) |
|
||||||
|
|
||||||
items.push({ |
|
||||||
icon: "mdi mdi-cog", |
|
||||||
items: adminItems, |
|
||||||
label: t("Administration"), |
|
||||||
}) |
|
||||||
} |
} |
||||||
|
|
||||||
|
onMounted(async () => { |
||||||
|
await enrolledStore.initialize(); |
||||||
|
updateCoursesItems(); |
||||||
|
}) |
||||||
|
|
||||||
|
watch(() => enrolledStore.isEnrolledInCourses, updateCoursesItems) |
||||||
|
watch(() => enrolledStore.isEnrolledInSessions, updateCoursesItems) |
||||||
|
|
||||||
return items |
return items |
||||||
} |
} |
||||||
|
@ -0,0 +1,33 @@ |
|||||||
|
import { defineStore } from "pinia" |
||||||
|
import axios from "axios" |
||||||
|
import { computed, ref } from "vue" |
||||||
|
|
||||||
|
export const useEnrolledStore = defineStore("enrolledStore", () => { |
||||||
|
// Reactive state to track if the user is enrolled in courses or sessions
|
||||||
|
const isEnrolledInCourses = ref(false) |
||||||
|
const isEnrolledInSessions = ref(false) |
||||||
|
|
||||||
|
// Function to check enrollment status
|
||||||
|
async function checkEnrollments() { |
||||||
|
try { |
||||||
|
const { data } = await axios.get("/course/check-enrollments") |
||||||
|
console.log('Check enrollments data:', data) |
||||||
|
isEnrolledInCourses.value = data.isEnrolledInCourses |
||||||
|
isEnrolledInSessions.value = data.isEnrolledInSessions |
||||||
|
} catch (error) { |
||||||
|
console.error("Error verifying enrollments:", error) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Function to initialize the store
|
||||||
|
async function initialize() { |
||||||
|
await checkEnrollments() |
||||||
|
} |
||||||
|
|
||||||
|
return { |
||||||
|
// Computed properties for reactivity
|
||||||
|
isEnrolledInCourses: computed(() => isEnrolledInCourses.value), |
||||||
|
isEnrolledInSessions: computed(() => isEnrolledInSessions.value), |
||||||
|
initialize |
||||||
|
}; |
||||||
|
}); |
Loading…
Reference in new issue