- add MobileLayout changes
This commit is contained in:
Alexandrina-Kuzeleva
2025-11-11 17:27:09 +03:00
parent 655df62d6c
commit 962dcc1ce9

View File

@@ -76,15 +76,12 @@ const isModerator = ref(false)
const isInstructor = ref(false)
onMounted(() => {
sidebarSettings.reload(
{},
{
onSuccess(data) {
filterLinksToShow(data)
addOtherLinks()
},
}
)
// Вызываем addSideBar только если userResource уже загружен
if (userResource.data) {
addSideBar()
}
addOtherLinks()
filterLinksToShow(data)
})
const handleOutsideClick = (e) => {
@@ -113,24 +110,186 @@ const filterLinksToShow = (data) => {
})
}
const addSideBar = () => {
sidebarLinks.value = [] // Очищаем, чтобы избежать дублирования
// Проверяем роли пользователя
const roles = userResource.data?.roles || []
sidebarLinks.value.push({
label: __('Courses'),
icon: 'BookOpen',
to: 'Courses',
activeFor: [
'Courses',
'CourseDetail',
'Lesson',
'CourseForm',
'LessonForm',
],
})
sidebarLinks.value.push({
label: __('Leader Board'),
icon: 'Trophy',
to: 'leaderboardsample',
external: true,
activeFor: [],
})
if (roles.includes('LMS Student') || roles.includes('LMS Schoolchild')) {
otherLinks.value.push({
label: __('My points'),
icon: 'Award',
to: 'my_points',
external: true,
activeFor: [],
})
}
if (roles.includes('Parent')) {
otherLinks.value.push({
label: __('My Child'),
icon: 'User',
to: 'my-child',
external: true,
activeFor: [],
})
}
let chatGPTURL = ''
let chatGPTLabel = ''
if (roles.includes('LMS Schoolchild')) {
chatGPTURL = 'chatgpt-schoolchild'
chatGPTLabel = __('ChatGPT for Schoolers')
} else if (roles.includes('LMS Student')) {
chatGPTURL = 'chatgpt-schoolchild'
chatGPTLabel = __('ChatGPT for Students')
} else if (roles.includes('Course Creator')) {
chatGPTURL = 'ai-teachers'
chatGPTLabel = __('ChatGPT for Teachers')
}
if (chatGPTURL) {
sidebarLinks.value.push({
label: chatGPTLabel,
icon: 'Cpu',
to: chatGPTURL,
external: true,
activeFor: [],
})
}
}
const addOtherLinks = () => {
otherLinks.value = []
if (user) {
const roles = userResource.data?.roles || []
if (!userResource.data?.is_instructor && !userResource.data?.is_moderator) {
otherLinks.value.push({
label: __('Programs'),
icon: 'Route',
to: 'Programs',
activeFor: ['Programs', 'ProgramForm', 'CourseDetail', 'Lesson'],
})
} else if (userResource.data?.is_instructor || userResource.data?.is_moderator) {
otherLinks.value.push({
label: __('Programs'),
icon: 'Route',
to: 'Programs',
activeFor: ['Programs', 'ProgramForm'],
})
}
if (userResource.data?.is_moderator || userResource.data?.is_instructor) {
otherLinks.value.push({
label: __('Quizzes'),
icon: 'CircleHelp',
to: 'Quizzes',
activeFor: [
'Quizzes',
'QuizForm',
'QuizSubmissionList',
'QuizSubmission',
],
})
otherLinks.value.push({
label: __('Assignments'),
icon: 'Pencil',
to: 'Assignments',
activeFor: [
'Assignments',
'AssignmentForm',
'AssignmentSubmissionList',
'AssignmentSubmission',
],
}),
otherLinks.value.push({
label: 'Programming Exercises',
icon: 'Code',
to: 'ProgrammingExercises',
})
}
if (roles.includes('LMS Student') || roles.includes('LMS Schoolchild')) {
otherLinks.value.push({
label: __('My points'),
icon: 'Award',
to: 'my_points',
external: true,
activeFor: [],
})
}
let chatGPTURL = ''
let chatGPTLabel = ''
if (roles.includes('LMS Schoolchild')) {
chatGPTURL = 'chatgpt-schoolchild'
chatGPTLabel = __('ChatGPT for Schoolers')
} else if (roles.includes('LMS Student')) {
chatGPTURL = 'chatgpt-schoolchild'
chatGPTLabel = __('ChatGPT for Students')
} else if (roles.includes('Course Creator')) {
chatGPTURL = 'ai-teachers'
chatGPTLabel = __('ChatGPT for Teachers')
}
if (chatGPTURL) {
otherLinks.value.push({
label: chatGPTLabel,
icon: 'Cpu',
to: chatGPTURL,
external: true,
activeFor: [],
})
}
otherLinks.value.push({
label: 'Notifications',
icon: 'Bell',
to: 'Notifications',
label: __('Leader Board'),
icon: 'Trophy',
to: 'leaderboardsample',
external: true,
activeFor: [],
})
otherLinks.value.push({
label: 'Profile',
label: __('Profile'),
icon: 'UserRound',
to: 'Profile',
params: { username: userResource.data?.username },
})
otherLinks.value.push({
label: 'Log out',
label: __('Log out'),
icon: 'LogOut',
})
} else {
otherLinks.value.push({
label: 'Log in',
label: __('Log in'),
icon: 'LogIn',
})
}
@@ -138,63 +297,11 @@ const addOtherLinks = () => {
watch(userResource, () => {
if (userResource.data) {
isModerator.value = userResource.data.is_moderator
isInstructor.value = userResource.data.is_instructor
addPrograms()
if (isModerator.value || isInstructor.value) {
addProgrammingExercises()
addQuizzes()
addAssignments()
}
addSideBar() // Обновляем sidebarLinks при изменении userResource
addOtherLinks() // Обновляем otherLinks
}
})
const addQuizzes = () => {
otherLinks.value.push({
label: 'Quizzes',
icon: 'CircleHelp',
to: 'Quizzes',
})
}
const addAssignments = () => {
otherLinks.value.push({
label: 'Assignments',
icon: 'Pencil',
to: 'Assignments',
})
}
const addProgrammingExercises = () => {
otherLinks.value.push({
label: 'Programming Exercises',
icon: 'Code',
to: 'ProgrammingExercises',
})
}
const addPrograms = async () => {
let canAddProgram = await checkIfCanAddProgram()
if (!canAddProgram) return
let activeFor = ['Programs', 'ProgramDetail']
let index = 1
sidebarLinks.value.splice(index, 0, {
label: 'Programs',
icon: 'Route',
to: 'Programs',
activeFor: activeFor,
})
}
const checkIfCanAddProgram = async () => {
if (isModerator.value || isInstructor.value) {
return true
}
const programs = await call('lms.lms.utils.get_programs')
return programs.enrolled.length > 0 || programs.published.length > 0
}
let isActive = (tab) => {
return tab.activeFor?.includes(router.currentRoute.value.name)
}