Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 32 additions & 27 deletions assets/vue/composables/useSocialMenuItems.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useMessageRelUserStore } from "../store/messageRelUserStore"
import { useSecurityStore } from "../store/securityStore"
import { usePlatformConfig } from "../store/platformConfig"
import axios from 'axios';
import axios from 'axios'
import { useSocialInfo } from "./useSocialInfo"
import { storeToRefs } from "pinia"

Expand All @@ -15,60 +15,65 @@ export function useSocialMenuItems() {
const invitationsCount = ref(0);
const groupLink = ref({ name: "UserGroupShow" });

const { isCurrentUser} = useSocialInfo()
const { isCurrentUser } = useSocialInfo()
const { user } = storeToRefs(securityStore)

const unreadMessagesCount = computed(() => messageRelUserStore.countUnread);
const globalForumsCourse = computed(() => platformConfigStore.getSetting("forum.global_forums_course_id"));
const unreadMessagesCount = computed(() => messageRelUserStore.countUnread)
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 courseId = globalForumsCourse.value;
return courseId !== null && courseId !== undefined && courseId > 0;
const courseId = globalForumsCourse.value
return courseId !== null && courseId !== undefined && courseId > 0
});

const fetchInvitationsCount = async (userId) => {
if (!userId) return;
if (!userId) return
try {
const { data } = await axios.get(`/social-network/invitations/count/${userId}`);
invitationsCount.value = data.totalInvitationsCount;
const { data } = await axios.get(`/social-network/invitations/count/${userId}`)
invitationsCount.value = data.totalInvitationsCount
} catch (error) {
console.error("Error fetching invitations count:", error);
console.error("Error fetching invitations count:", error)
}
};

const getGroupLink = async () => {
try {
const response = await axios.get("/social-network/get-forum-link");
const response = await axios.get("/social-network/get-forum-link")
if (isValidGlobalForumsCourse.value) {
groupLink.value = response.data.go_to;
groupLink.value = response.data.go_to
} else {
groupLink.value = { name: "UserGroupList" };
groupLink.value = { name: "UserGroupList" }
}
} catch (error) {
console.error("Error fetching forum link:", error);
groupLink.value = { name: "UserGroupList" };
console.error("Error fetching forum link:", error)
groupLink.value = { name: "UserGroupList" }
}
};

console.log('user.value ::: ', user.value.id)

if (user.value && user.value.id) {
fetchInvitationsCount(user.value.id);
getGroupLink();
fetchInvitationsCount(user.value.id)
getGroupLink()
}

const items = computed(() => {
return isCurrentUser.value ? [
const menuItems = [
{ 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-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-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-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