navigation de menu basique + gestion de l'item login/logout en fonction de la connexion actuelle

This commit is contained in:
xdrm-brackets 2018-02-20 17:45:46 +01:00
parent 90640825d4
commit c51f90b70e
2 changed files with 33 additions and 26 deletions

View File

@ -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');

View File

@ -2,9 +2,9 @@
<div id='MENU'>
<div v-for='(item, index) in gstore.menu_item' class='menu-item-wrapper'>
<div v-for='(item, index) in gstore.menu_item' class='side-menu'>
<div :class="(index == gstore.menu_item_active) ? 'menu-item active' : 'menu-item'" @click='navigate(index)' :data-theme='item.theme'>
<div :class="(index == gstore.menu_item_active) ? 'side-menu-item active' : 'side-menu-item'" @click='navigate(index)' :data-icon='item.icon'>
<span>{{ item.label }}</span>
</div>
@ -21,7 +21,7 @@ export default {
data(){ return { gstore: gstore.get }; },
methods: {
navigate(uri){
console.log("Navigate to "+uri);
document.location = '/'+uri+'/';
}
}
}