diff --git a/index.html b/index.html index 7bb500c..14bfc86 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,7 @@ diff --git a/public/menu.json b/public/menu.json new file mode 100644 index 0000000..c62dcc8 --- /dev/null +++ b/public/menu.json @@ -0,0 +1,30 @@ +{ + "config": { + + }, + "menu": [ + { + "label": "Catalogue", + "i18n": "catalogue", + "url": "/datahub/", + "active-app" : "datahub" + }, + { + "label": "My other service", + "url": "/geoserver/web", + "active-app" : "geoserver" + }, + { + "type": "dropdown", + "label": "A dropdown", + "items": [ + { + "label": "Console", + "i18n": "users", + "url": "/console/manager/home", + "active-app": "console" + } + ] + } + ] +} diff --git a/src/auth.ts b/src/auth.ts index 98d1e0f..249810b 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -43,7 +43,6 @@ export async function getUserDetails(): Promise { "roles": [ "ROLE_MAPSTORE_ADMIN", "ROLE_DSP_ILEVIA", - "ROLE_GN_EDITOR", "ROLE_USER", "ROLE_ADMINISTRATOR", "ROLE_SUPERUSER" diff --git a/src/header.ce.vue b/src/header.ce.vue index c208780..4c7a0ba 100644 --- a/src/header.ce.vue +++ b/src/header.ce.vue @@ -4,13 +4,9 @@ import { getUserDetails, getPlatformInfos } from './auth' import type { User, PlatformInfos } from './auth' import UserIcon from './ui/UserIcon.vue' import GeorchestraLogo from './ui/GeorchestraLogo.vue' -import CatalogIcon from '@/ui/CatalogIcon.vue' -import MapIcon from '@/ui/MapIcon.vue' -import ChartPieIcon from '@/ui/ChartPieIcon.vue' -import UsersIcon from '@/ui/UsersIcon.vue' import ChevronDownIcon from '@/ui/ChevronDownIcon.vue' import { LANG_2_TO_3_MAPPER, t } from '@/i18n' -import menu from '@/menu.json' +import { defaultMenu } from '@/menu.json' const props = defineProps<{ hideLogin?: string @@ -22,6 +18,7 @@ const props = defineProps<{ legacyUrl?: string style?: string stylesheet?: string + menuFile?: string }>() const state = reactive({ @@ -29,14 +26,12 @@ const state = reactive({ mobileMenuOpen: false, lang3: props.lang, platformInfos: null as null | PlatformInfos, + menu: defaultMenu, }) const isAnonymous = computed(() => !state.user || state.user.anonymous) -const isAdmin = computed(() => state.user?.adminRoles?.admin) const isWarned = computed(() => state.user?.warned) const remainingDays = computed(() => state.user?.remainingDays) -const adminRoles = computed(() => state.user?.adminRoles) -const cond = computed(condition => state.user?.roles?.[condition]) const loginUrl = computed(() => { const current = new URL(window.location.href) @@ -49,13 +44,28 @@ function toggleMenu(): void { state.mobileMenuOpen = !state.mobileMenuOpen } -function checkCondition(condition: string): boolean { +function checkCondition(item: object): boolean { + const hasRole = item.hasRole if (!state.user) return false - if (!condition) return true - return condition.split(',').some(c => state.user?.roles?.indexOf(c) !== -1) + if (!hasRole) return true + const isBlocked = item.blockedRole + ?.split(',') + .some(c => state.user?.roles?.indexOf(c) !== -1) + if (isBlocked) return false + return hasRole.split(',').some(c => state.user?.roles?.indexOf(c) !== -1) +} + +function computeUrl(url: string): string { + return url.replace(/:lang3/, state.lang3) } onMounted(() => { + if (props.menuFile) + fetch(props.menuFile) + .then(res => res.json()) + .then(file => { + state.menu = file.menu + }) state.lang3 = LANG_2_TO_3_MAPPER[props.lang || navigator.language.substring(0, 2)] || 'eng' @@ -89,10 +99,7 @@ onMounted(() => {