From c51f90b70e465575751ea6937a0d8d453b089963 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 20 Feb 2018 17:45:46 +0100 Subject: [PATCH] navigation de menu basique + gestion de l'item login/logout en fonction de la connexion actuelle --- webpack/data/common.js | 53 ++++++++++++++++++++++++------------------ webpack/vue/menu.vue | 6 ++--- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/webpack/data/common.js b/webpack/data/common.js index 670cae1..1e41d3c 100644 --- a/webpack/data/common.js +++ b/webpack/data/common.js @@ -3,39 +3,46 @@ import {GlobalStore} from '../lib/gstore' window.gstore = new GlobalStore(); -/* (1) Main components +/* (1) Global data +---------------------------------------------------------*/ +/* (1) Get Full URI */ +gstore.add('URI', document.URL.replace(/^(?:\/\/|[^\/]+)*/, '').split('/').filter(function(i){ return i.length; })); + +/* (2) Get if local version or prod */ +gstore.add('is_local', document.URL.replace(/^https?:\/\/([^\/:]+).*$/, '$1') == 'ptut.com'); + + +/* (2) Main components ---------------------------------------------------------*/ /* (1) Header */ gstore.add('header_title', 'ndli1718'); /* (2) Menu */ gstore.add('menu_item', { - dashboard: { + home: { label: 'Accueil', - theme: 'dashboard' - }, emergency: { - label: 'Urgences', - theme: 'emergency' - }, event: { - label: 'Signalements', - theme: 'event' - }, inbox: { - label: 'Messagerie', - theme: 'inbox' + url: 'home', + icon: 'home' + }, manage: { + label: 'Administration', + url: 'manage', + icon: 'manage' + }, fiche: { + label: 'Fiches', + url: 'fiche', + icon: 'fiche' } }); -gstore.add('URI', document.URL.replace(/^(?:\/\/|[^\/]+)*/, '')); -gstore.add('is_local', document.URL.replace(/^https?:\/\/([^\/:]+).*$/, '$1') == 'ptut.com'); -gstore.add('min_menu', false); +/* (3) Gestion du login/logout */ +if( _SERVER.connected ) gstore.get.menu_item.login = { label: 'Connexion', url: 'login', icon: 'login' }; +else gstore.get.menu_item.logout = { label: 'Déconnexion', url: 'logout', icon: 'logout' }; -// // Proccess current page from url -// if( /^\/(\w+)(?:\/?.*)$/.test(gstore.data.URI) ){ -// var mi_keys = Object.keys( gstore.data.menu_item ); -// // if current page exists -// if( !!~mi_keys.indexOf(RegExp.$1) ) gstore.add('menu_item_active', RegExp.$1); -// else gstore.add('menu_item_active', 'dashboard'); -// }else -// gstore.add('menu_item_active', 'dashboard'); + +/* (4) Set current page active in menu */ +if( gstore.get.URI.length > 0 && gstore.get.menu_item.hasOwnProperty(gstore.get.URI[0]) ) + gstore.add('menu_item_active', gstore.get.menu_item[gstore.get.URI[0]].url); +else + gstore.add('menu_item_active', 'home'); diff --git a/webpack/vue/menu.vue b/webpack/vue/menu.vue index c4c7e82..9b34c64 100644 --- a/webpack/vue/menu.vue +++ b/webpack/vue/menu.vue @@ -2,9 +2,9 @@