浏览代码

menu Site internet

Vincent GUFFON 4 年之前
父节点
当前提交
a6ff5f0990

+ 4 - 4
components/Layout/MenuComponent.vue

@@ -10,8 +10,8 @@
       <div v-for="(item, i) in menu" :key="i">
         <v-list-item
           v-if="!item.children"
-          :href="item.old ? item.to : undefined"
-          :to="!item.old ? item.to : undefined"
+          :href="item.isExternalLink ? item.to : undefined"
+          :to="!item.isExternalLink ? item.to : undefined"
           router
           exact
         >
@@ -40,8 +40,8 @@
           <v-list-item
             v-for="child in item.children"
             :key="child.title"
-            :href="child.old ? child.to : undefined"
-            :to="!child.old ? child.to : undefined"
+            :href="child.isExternalLink ? child.to : undefined"
+            :to="!child.isExternalLink ? child.to : undefined"
             router
             exact
           >

+ 1 - 0
config/nuxtConfig/env.js

@@ -12,6 +12,7 @@ export default {
     },
     baseURL_Legacy: process.env.NODE_ENV !== 'production' ? 'https://local.api.opentalent.fr' : 'https://local.api.opentalent.fr',
     baseURL_adminLegacy: process.env.NODE_ENV !== 'production' ? 'https://local.admin.opentalent.fr/#' : 'https://admin.opentalent.fr/#',
+    baseURL_typo3: process.env.NODE_ENV !== 'production' ? `https://local.sub.opentalent.fr/###subDomain###` : `https://###subDomain###.opentalent.fr/#`,
   },
   privateRuntimeConfig: {
     http: {

+ 5 - 1
config/nuxtConfig/i18n.js

@@ -8,6 +8,10 @@ export default {
     ],
     lazy: true,
     langDir: 'lang/',
-    defaultLocale: 'fr'
+    defaultLocale: 'fr',
+    vueI18n: {
+      silentTranslationWarn: true,
+      silentFallbackWarn: true
+    }
   }
 }

+ 2 - 0
lang/layout/fr-FR.js

@@ -69,5 +69,7 @@ export default (context, locale) => {
     cmf_cotisation: 'Cotisation CMF',
     right_menu: 'Droits version 5.9',
     tree_menu: 'Gestion de l\'arbre',
+    website: 'Site internet',
+    advanced_modification: 'Modifications avancées',
   })
 }

+ 1 - 1
services/profile/organizationProfile.ts

@@ -24,7 +24,7 @@ class OrganizationProfile{
   hasModule(modules:Array<string>) {
     let hasModule = false;
     modules.map((module) => {
-      if (this.organizationProfile.modules.indexOf(module) > -1)
+      if (this.organizationProfile.modules && this.organizationProfile.modules.indexOf(module) > -1)
         hasModule = true;
     });
     return hasModule;

+ 14 - 0
store/profile/access.ts

@@ -3,6 +3,8 @@ import {AbilitiesType, accessState} from "~/types/types";
 
 export const state = () => ({
   bearer: null,
+  name: null,
+  givenName: null,
   accessId: null,
   roles: [],
   abilities: [],
@@ -24,12 +26,21 @@ export const mutations = {
   setAccessId(state:accessState, accessId:number){
     state.accessId = accessId
   },
+  setName(state:accessState, name:string){
+    state.name = name
+  },
+  setGivenName(state:accessState, givenName:string){
+    state.givenName = givenName
+  },
   setRoles(state:accessState, roles:Array<string>){
     state.roles = roles
   },
   setAbilities(state:accessState, abilities:Array<AbilitiesType>){
     state.abilities = abilities
   },
+  setIsAdminAccess(state:accessState, isAdminAccess:boolean){
+    state.isAdminAccess = isAdminAccess
+  },
   setIsAdmin(state:accessState, isRole:boolean){
     state.isAdmin = isRole
   },
@@ -63,6 +74,9 @@ export const actions = {
   setProfile(context:any, profile:any){
     let roles_to_array:Array<string> = Object.values(profile.roles)
 
+    context.commit('setName', profile.name)
+    context.commit('setGivenName', profile.givenName)
+    context.commit('setIsAdminAccess', profile.isAdminAccess)
     context.commit('setIsAdmin', $roleUtils.isA('ADMIN', roles_to_array))
     context.commit('setIsAdministratifManager', $roleUtils.isA('ADMINISTRATIF_MANAGER', roles_to_array))
     context.commit('setIsPedagogicManager', $roleUtils.isA('PEDAGOGICS_MANAGER', roles_to_array))

+ 29 - 1
store/profile/organization.ts

@@ -1,10 +1,14 @@
 import {organizationState} from "~/types/types";
+import * as _ from "lodash";
 
 export const state = () => ({
   name: '',
   product: '',
   modules: [],
-  hasChildren: false
+  hasChildren: false,
+  website: '',
+  subDomain: '',
+  parents: []
 })
 
 export const mutations = {
@@ -19,6 +23,18 @@ export const mutations = {
   },
   setHasChildren(state:organizationState, hasChildren:boolean) {
     state.hasChildren = hasChildren
+  },
+  setParents(state:organizationState, parents:Array<organizationState>) {
+    state.parents = parents
+  },
+  setWebsite(state:organizationState, website:string) {
+    state.website = website
+  },
+  setSubDomain(state:organizationState, subDomain:string) {
+    state.subDomain = subDomain
+  },
+  addParent(state:organizationState, parent:organizationState) {
+    state.parents.push(parent)
   }
 }
 
@@ -26,7 +42,19 @@ export const actions = {
   setProfile(context:any, profile:any){
     context.commit('setName', profile.name)
     context.commit('setProduct', profile.product)
+    context.commit('setWebsite', profile.website)
+    context.commit('setSubDomain', profile.subDomain)
     context.commit('setModules', profile.modules)
     context.commit('setHasChildren', profile.hasChildren)
+
+    _.each(profile.parents, parent => {
+      const p:organizationState = {
+        name: parent.name,
+        website: parent.website,
+        subDomain: parent.subDomain,
+        parents: []
+      }
+      context.commit('addParent', p)
+    });
   }
 }

+ 3 - 3
test/use/template/menu.spec.js

@@ -6,7 +6,7 @@ test('test constructMenu', () => {
     "icon": "icon",
     "title": "children",
     "to": "/url",
-    "old": false
+    "isExternalLink": false
   });
 
   const menuWithChildren = new BaseMenu({'baseURL_adminLegacy': 'base_url'}).constructMenu('icon', 'parent', undefined, undefined, [menuWithoutChildren])
@@ -14,9 +14,9 @@ test('test constructMenu', () => {
     "children": [
       {
         "icon": "icon",
-        "old": false,
         "title": "children",
-        "to": "/url"
+        "to": "/url",
+        "isExternalLink": false
       }
     ],
     "icon": "icon",

+ 11 - 5
types/types.d.ts

@@ -16,8 +16,8 @@ interface ItemMenu {
   icon: string,
   title: string,
   to?: string,
-  old?: boolean,
-  children?: ItemsMenu
+  children?: ItemsMenu,
+  isExternalLink?: boolean,
 }
 
 interface AbilitiesType {
@@ -36,8 +36,11 @@ interface AbilitiesType {
 interface accessState {
   bearer: string,
   accessId: number,
+  name: string,
+  givenName: string,
   roles: Array<string>,
   abilities: Array<AbilitiesType>,
+  isAdminAccess: boolean,
   isAdmin: boolean,
   isAdministratifManager: boolean,
   isPedagogicManager: boolean,
@@ -52,9 +55,12 @@ interface AccessStore extends Store<{profile:{access:accessState}}> {}
 
 interface organizationState {
   name: string,
-  product: string,
-  modules: Array<string>,
-  hasChildren: boolean,
+  product?: string,
+  modules?: Array<string>,
+  hasChildren?: boolean,
+  website?: string,
+  subDomain?: string,
+  parents: Array<organizationState>,
 }
 interface OrganizationStore extends Store<{profile:{organization:organizationState}}> {}
 

+ 6 - 5
use/template/Menus/baseMenu.ts

@@ -1,7 +1,7 @@
 import {ItemMenu} from "~/types/types";
 
 class BaseMenu{
-  private $config:any;
+  protected $config:any;
 
   constructor($config:any) {
     this.$config = $config;
@@ -12,11 +12,12 @@ class BaseMenu{
    * @param {string} icon
    * @param {string} title titre qui sera traduit
    * @param {string} link lien
-   * @param {boolean} isOldLink est-ce un lien renvoyant vers l'ancien admin ?
+   * @param {boolean} isOldLink est-ce un lien renvoyant vers l'ancien admin?
    * @param {Array<ItemMenu>} children Tableau d'ItemMenu représentant les sous menu du menu principal
+   * @param {boolean} isExternalLink est-ce un lien renvoyant vers l'extérieur?
    * @return {ItemMenu}
    */
-  constructMenu(icon: string, title: string, link?: string, isOldLink?: boolean, children?: Array<ItemMenu>): ItemMenu{
+  constructMenu(icon: string, title: string, link?: string, isOldLink?: boolean, children?: Array<ItemMenu>, isExternalLink?: boolean): ItemMenu{
     return children ? {
       icon: icon,
       title: title,
@@ -24,8 +25,8 @@ class BaseMenu{
     } : {
       icon: icon,
       title: title,
-      to: `${isOldLink ? this.$config.baseURL_adminLegacy : ''}${link}`,
-      old: isOldLink,
+      to: `${isExternalLink || !isOldLink ? '' : this.$config.baseURL_adminLegacy}${link}`,
+      isExternalLink: isExternalLink || isOldLink,
     }
   }
 }

+ 39 - 0
use/template/Menus/websiteMenu.ts

@@ -0,0 +1,39 @@
+import {ItemMenu, ItemsMenu, organizationState} from "~/types/types";
+import BaseMenu from "~/use/template/Menus/baseMenu";
+import *  as _ from "lodash"
+
+class WebsiteMenu extends BaseMenu{
+  private $ability:any;
+  private $store:any;
+
+  constructor($config:any, $ability:any, $store:any) {
+    super($config)
+    this.$ability = $ability
+    this.$store = $store
+  }
+
+  /**
+   * Construit le menu Site internet ou null si aucune page accessible
+   * @return {ItemMenu | null}
+   */
+  getMenu():ItemMenu | null {
+    const children:ItemsMenu = [];
+
+    children.push(this.constructMenu('fa-globe-europe', this.$store.state.profile.organization.name, this.getWebsite(this.$store.state.profile.organization), false, undefined, true))
+
+    if(!this.$store.state.profile.organization.website && this.$store.state.profile.access.isAdminAccess)
+      children.push(this.constructMenu('fa-globe-europe', 'advanced_modification', this.getWebsite(this.$store.state.profile.organization) + '/typo3', false, undefined, true))
+
+    _.each(this.$store.state.profile.organization.parents, parent => {
+      children.push(this.constructMenu('fa-globe-europe', parent.name, this.getWebsite(parent), false, undefined, true))
+    })
+
+    return children.length > 0 ? this.constructMenu('fa-globe-europe', 'website', undefined, undefined, children) : null;
+  }
+
+  getWebsite(organization:organizationState):string{
+    return organization.website ? organization.website : this.$config.baseURL_typo3.replace('###subDomain###', organization.subDomain)
+  }
+}
+
+export const getWebsiteMenu = ($config:any, $ability:any, $store:any) => new WebsiteMenu($config, $ability, $store).getMenu()

+ 4 - 1
use/template/menu.ts

@@ -1,6 +1,5 @@
 import {ref, useContext} from "@nuxtjs/composition-api";
 import {ItemsMenu} from "~/types/types";
-import BaseMenu from "~/use/template/Menus/baseMenu";
 import {getAccessMenu} from "~/use/template/Menus/accessMenu";
 import {getAgendaMenu} from "~/use/template/Menus/agendaMenu";
 import {getEquipmentMenu} from "~/use/template/Menus/equipmentMenu";
@@ -12,6 +11,7 @@ import {getMedalsMenu} from "~/use/template/Menus/medalsMenu";
 import {getStatsMenu} from "~/use/template/Menus/statsMenu";
 import {getCotisationsMenu} from "~/use/template/Menus/cotisationsMenu";
 import {getAdmin2iosMenu} from "~/use/template/Menus/admin2iosMenu";
+import {getWebsiteMenu} from "~/use/template/Menus/websiteMenu";
 
 /**
  * @category Use/template
@@ -68,6 +68,9 @@ class Menu{
     const medalsMenu = getMedalsMenu(this.$config,this.$ability)
     if(medalsMenu) menu.push(medalsMenu)
 
+    const websiteMenu = getWebsiteMenu(this.$config,this.$ability,this.$store)
+    if(websiteMenu) menu.push(websiteMenu)
+
     const cotisationsMenu = getCotisationsMenu(this.$config,this.$ability)
     if(cotisationsMenu) menu.push(cotisationsMenu)