Social: Hide social groups menu item based on config setting - refs BT#21572

pull/5745/head
christianbeeznst 1 year ago
parent d0264aedca
commit 824308e919
  1. 59
      assets/vue/composables/useSocialMenuItems.js

@ -1,9 +1,9 @@
import { computed, ref } from 'vue'; import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n'
import { useMessageRelUserStore } from "../store/messageRelUserStore" import { useMessageRelUserStore } from "../store/messageRelUserStore"
import { useSecurityStore } from "../store/securityStore" import { useSecurityStore } from "../store/securityStore"
import { usePlatformConfig } from "../store/platformConfig" import { usePlatformConfig } from "../store/platformConfig"
import axios from 'axios'; import axios from 'axios'
import { useSocialInfo } from "./useSocialInfo" import { useSocialInfo } from "./useSocialInfo"
import { storeToRefs } from "pinia" import { storeToRefs } from "pinia"
@ -15,60 +15,65 @@ export function useSocialMenuItems() {
const invitationsCount = ref(0); const invitationsCount = ref(0);
const groupLink = ref({ name: "UserGroupShow" }); const groupLink = ref({ name: "UserGroupShow" });
const { isCurrentUser} = useSocialInfo() const { isCurrentUser } = useSocialInfo()
const { user } = storeToRefs(securityStore) const { user } = storeToRefs(securityStore)
const unreadMessagesCount = computed(() => messageRelUserStore.countUnread); const unreadMessagesCount = computed(() => messageRelUserStore.countUnread)
const globalForumsCourse = computed(() => platformConfigStore.getSetting("forum.global_forums_course_id")); const globalForumsCourse = computed(() => platformConfigStore.getSetting("forum.global_forums_course_id"))
const hideSocialGroupBlock = computed(() => platformConfigStore.getSetting("social.hide_social_groups_block") === "true")
const isValidGlobalForumsCourse = computed(() => { const isValidGlobalForumsCourse = computed(() => {
const courseId = globalForumsCourse.value; const courseId = globalForumsCourse.value
return courseId !== null && courseId !== undefined && courseId > 0; return courseId !== null && courseId !== undefined && courseId > 0
}); });
const fetchInvitationsCount = async (userId) => { const fetchInvitationsCount = async (userId) => {
if (!userId) return; if (!userId) return
try { try {
const { data } = await axios.get(`/social-network/invitations/count/${userId}`); const { data } = await axios.get(`/social-network/invitations/count/${userId}`)
invitationsCount.value = data.totalInvitationsCount; invitationsCount.value = data.totalInvitationsCount
} catch (error) { } catch (error) {
console.error("Error fetching invitations count:", error); console.error("Error fetching invitations count:", error)
} }
}; };
const getGroupLink = async () => { const getGroupLink = async () => {
try { try {
const response = await axios.get("/social-network/get-forum-link"); const response = await axios.get("/social-network/get-forum-link")
if (isValidGlobalForumsCourse.value) { if (isValidGlobalForumsCourse.value) {
groupLink.value = response.data.go_to; groupLink.value = response.data.go_to
} else { } else {
groupLink.value = { name: "UserGroupList" }; groupLink.value = { name: "UserGroupList" }
} }
} catch (error) { } catch (error) {
console.error("Error fetching forum link:", error); console.error("Error fetching forum link:", error)
groupLink.value = { name: "UserGroupList" }; groupLink.value = { name: "UserGroupList" }
} }
}; };
console.log('user.value ::: ', user.value.id)
if (user.value && user.value.id) { if (user.value && user.value.id) {
fetchInvitationsCount(user.value.id); fetchInvitationsCount(user.value.id)
getGroupLink(); getGroupLink()
} }
const items = computed(() => { const items = computed(() => {
return isCurrentUser.value ? [ const menuItems = [
{ icon: 'mdi mdi-home', label: t("Home"), route: '/social' }, { icon: 'mdi mdi-home', label: t("Home"), route: '/social' },
{ icon: 'mdi mdi-email', label: t("Messages"), route: '/resources/messages', badgeCount: unreadMessagesCount.value }, { icon: 'mdi mdi-email', label: t("Messages"), route: '/resources/messages', badgeCount: unreadMessagesCount.value },
{ icon: 'mdi mdi-handshake', label: t("My friends"), route: { name: 'UserRelUserList' } }, { icon: 'mdi mdi-handshake', label: t("My friends"), route: { name: 'UserRelUserList' } },
{ icon: 'mdi mdi-group', label: t("Social groups"), route: groupLink.value, isLink: isValidGlobalForumsCourse.value },
{ icon: 'mdi mdi-briefcase', label: t("My files"), route: { name: 'PersonalFileList', params: { node: securityStore.user.resourceNode.id } } }, { icon: 'mdi mdi-briefcase', label: t("My files"), route: { name: 'PersonalFileList', params: { node: securityStore.user.resourceNode.id } } },
{ icon: 'mdi mdi-account', label: t("Personal data"), route: '/resources/users/personal_data' }, { icon: 'mdi mdi-account', label: t("Personal data"), route: '/resources/users/personal_data' },
] : [ ]
if (!hideSocialGroupBlock.value) {
menuItems.splice(3, 0, { icon: 'mdi mdi-group', label: t("Social groups"), route: groupLink.value, isLink: isValidGlobalForumsCourse.value })
}
return isCurrentUser.value ? menuItems : [
{ icon: 'mdi mdi-home', label: t("Home"), route: '/social' }, { icon: 'mdi mdi-home', label: t("Home"), route: '/social' },
{ icon: 'mdi mdi-email', label: t("Send message"), link: `/main/inc/ajax/user_manager.ajax.php?a=get_user_popup&user_id=${user.value.id}`, isExternal: true } { icon: 'mdi mdi-email', label: t("Send message"), link: `/main/inc/ajax/user_manager.ajax.php?a=get_user_popup&user_id=${user.value.id}`, isExternal: true }
]; ]
}); })
return { items }; return { items }
} }

Loading…
Cancel
Save