fix: *.js|*.vue (removed 'window.' when accessing window.* variables because 'window.' is implicit)

This commit is contained in:
xdrm-brackets 2017-12-05 18:41:39 +01:00
parent 69a6be7c2d
commit 3fd5fdfa97
9 changed files with 42 additions and 42 deletions

View File

@ -25,7 +25,7 @@ window.wsc = new WSClientBuilder("wss://websocket.xdrm.io");
/* (3) global store init */ /* (3) global store init */
require('./vue-config'); require('./vue-config');
window.gstore.add('server', window._SERVER); window.gstore.add('server', window._SERVER);
window.infobox = new InfoBox(window.gstore.data.info); window.infobox = new InfoBox(gstore.data.info);
/* (4) Init vue router */ /* (4) Init vue router */
Vue.use(VueRouter); Vue.use(VueRouter);
@ -46,51 +46,51 @@ new Vue({
/* (3) Set WebSocket channels /* (3) Set WebSocket channels
---------------------------------------------------------*/ ---------------------------------------------------------*/
/* (1) Connection channel */ /* (1) Connection channel */
window.wsc_connect = window.wsc.channel('connect').listen(function(msg, err){ window.wsc_connect = wsc.channel('connect').listen(function(msg, err){
// {1} Manage error // // {1} Manage error //
if( msg == null && err != null ) if( msg == null && err != null )
return window.infobox.show('Erreur de connexion WebSocket@connect ('+err+')', 'error', 3000); return infobox.show('Erreur de connexion WebSocket@connect ('+err+')', 'error', 3000);
// {2} Manage wsclient error // // {2} Manage wsclient error //
if( typeof msg.error != 'boolean' || msg.error !== false ) if( typeof msg.error != 'boolean' || msg.error !== false )
return window.infobox.show('Erreur de connexion WebSocket@connect', 'warning', 3000); return infobox.show('Erreur de connexion WebSocket@connect', 'warning', 3000);
// {3} Manage notification // // {3} Manage notification //
if( msg.connected != null ){ if( msg.connected != null ){
console.log('Detected '+msg.connected.length+' new user(s)'); console.log('Detected '+msg.connected.length+' new user(s)');
window.gstore.data.notif[0].data = window.gstore.data.notif[0].data.concat( msg.connected ); gstore.data.notif[0].data = gstore.data.notif[0].data.concat( msg.connected );
window.gstore.data.notif[0].count += msg.connected.length; gstore.data.notif[0].count += msg.connected.length;
} }
}).send({name: window._SERVER.session.name}); }).send({name: _SERVER.session.name});
/* (2) Message channel */ /* (2) Message channel */
window.wsc_chat = window.wsc.channel('chat').listen(function(msg, err){ window.wsc_chat = wsc.channel('chat').listen(function(msg, err){
// {1} Manage error // // {1} Manage error //
if( msg == null && err != null ) if( msg == null && err != null )
return window.infobox.show('Erreur de connexion WebSocket@chat ('+err+')', 'error', 3000); return infobox.show('Erreur de connexion WebSocket@chat ('+err+')', 'error', 3000);
// {2} Manage wsclient error // // {2} Manage wsclient error //
if( typeof msg.error != 'boolean' || msg.error !== false ) if( typeof msg.error != 'boolean' || msg.error !== false )
return window.infobox.show('Erreur de connexion WebSocket@chat', 'warning', 3000); return infobox.show('Erreur de connexion WebSocket@chat', 'warning', 3000);
// {3} Manage notification // // {3} Manage notification //
if( msg.msg != null ){ if( msg.msg != null ){
console.log('Received '+msg.msg.length+' new message(s)'); console.log('Received '+msg.msg.length+' new message(s)');
window.gstore.data.notif[1].data = window.gstore.data.notif[1].data.concat( msg.msg ); gstore.data.notif[1].data = gstore.data.notif[1].data.concat( msg.msg );
window.gstore.data.notif[1].count += msg.msg.length gstore.data.notif[1].count += msg.msg.length
} }
}).send({name: window._SERVER.session.name}); }).send({name: _SERVER.session.name});
/* (4) Clean sockets before page quit /* (4) Clean sockets before page quit
---------------------------------------------------------*/ ---------------------------------------------------------*/
window.onbeforeunload = function() { window.onbeforeunload = function() {
window.wsc_chat.send('{"close": true}'); wsc_chat.send('{"close": true}');
window.wsc_connect.send('{"close": true}'); wsc_connect.send('{"close": true}');
}; };

View File

@ -3,13 +3,13 @@ import {GlobalStore} from './lib/gstore-es6'
window.gstore = new GlobalStore(); window.gstore = new GlobalStore();
// Header // Header
window.gstore.add('header_title', 'ndli1718'); gstore.add('header_title', 'ndli1718');
window.gstore.add('info', { gstore.add('info', {
active: false, active: false,
type: 'warning', type: 'warning',
message: 'Warning! blabla' message: 'Warning! blabla'
}); });
window.gstore.add('notif', [ gstore.add('notif', [
{ class: 'bell', link: 'notifications', data: [], count: 0 }, { class: 'bell', link: 'notifications', data: [], count: 0 },
{ class: 'message', link: 'inbox', data: [], count: 0 }, { class: 'message', link: 'inbox', data: [], count: 0 },
{ class: 'search', link: 'search', data: [], count: 0 }, { class: 'search', link: 'search', data: [], count: 0 },
@ -17,7 +17,7 @@ window.gstore.add('notif', [
]) ])
// Menu // Menu
window.gstore.add('menu_item', { gstore.add('menu_item', {
dashboard: { dashboard: {
label: 'Dashboard', label: 'Dashboard',
icon: 'dashboard' icon: 'dashboard'
@ -33,46 +33,46 @@ window.gstore.add('menu_item', {
} }
}); });
window.gstore.add('URI', document.URL.replace(/^(?:\/\/|[^\/]+)*/, '')); gstore.add('URI', document.URL.replace(/^(?:\/\/|[^\/]+)*/, ''));
window.gstore.add('min_menu', false); gstore.add('min_menu', false);
// Proccess current page from url // Proccess current page from url
if( /^\/(\w+)(?:\/?.*)$/.test(window.gstore.data.URI) ){ if( /^\/(\w+)(?:\/?.*)$/.test(gstore.data.URI) ){
var mi_keys = Object.keys( window.gstore.data.menu_item ); var mi_keys = Object.keys( gstore.data.menu_item );
// if current page exists // if current page exists
if( !!~mi_keys.indexOf(RegExp.$1) ) window.gstore.add('menu_item_active', RegExp.$1); if( !!~mi_keys.indexOf(RegExp.$1) ) gstore.add('menu_item_active', RegExp.$1);
else window.gstore.add('menu_item_active', 'dashboard'); else gstore.add('menu_item_active', 'dashboard');
}else }else
window.gstore.add('menu_item_active', 'dashboard'); gstore.add('menu_item_active', 'dashboard');
// Functions // Functions
window.gstore.add('func', { gstore.add('func', {
nav: function(router, uri){ nav: function(router, uri){
// {1} Update view (vue-router) // // {1} Update view (vue-router) //
router.push('/'+uri); router.push('/'+uri);
// {2} Activate current menu_item // // {2} Activate current menu_item //
window.gstore.data.menu_item_active = uri; gstore.data.menu_item_active = uri;
// {3} Manage notifications // // {3} Manage notifications //
for( var notif of window.gstore.data.notif ) for( var notif of gstore.data.notif )
if( notif.link == uri ) // if notif links to current page if( notif.link == uri ) // if notif links to current page
notif.count = 0; notif.count = 0;
}, },
toggleMenuSize: function(){ window.gstore.data.min_menu=!window.gstore.data.min_menu; }, toggleMenuSize: function(){ gstore.data.min_menu=!gstore.data.min_menu; },
sendMessage: function(msg){ sendMessage: function(msg){
/* (1) Send message to WebSocket */ /* (1) Send message to WebSocket */
window.wsc_chat.send(JSON.stringify({message: msg})); wsc_chat.send(JSON.stringify({message: msg}));
/* (2) Add locally */ /* (2) Add locally */
window.gstore.data.notif[1].data.push([ window.gstore.data.server.session.name, msg ]); gstore.data.notif[1].data.push([ gstore.data.server.session.name, msg ]);
} }
}); });
// new-message container // new-message container
window.gstore.add('new_msg', ''); gstore.add('new_msg', '');

View File

@ -12,6 +12,6 @@
<script> <script>
export default { export default {
name: 'CONTAINER_DASHBOARD', name: 'CONTAINER_DASHBOARD',
data(){ return { gstore: window.gstore.data }; } data(){ return { gstore: gstore.data }; }
} }
</script> </script>

View File

@ -20,7 +20,7 @@
<script> <script>
export default { export default {
name: 'CONTAINER_INBOX', name: 'CONTAINER_INBOX',
data(){ return { gstore: window.gstore.data }; }, data(){ return { gstore: gstore.data }; },
methods: { methods: {
new_message(msg){ new_message(msg){

View File

@ -12,6 +12,6 @@
<script> <script>
export default { export default {
name: 'CONTAINER_NOTIFICATIONS', name: 'CONTAINER_NOTIFICATIONS',
data(){ return { gstore: window.gstore.data }; } data(){ return { gstore: gstore.data }; }
} }
</script> </script>

View File

@ -12,6 +12,6 @@
<script> <script>
export default { export default {
name: 'CONTAINER_PROFILE', name: 'CONTAINER_PROFILE',
data(){ return { gstore: window.gstore.data }; } data(){ return { gstore: gstore.data }; }
} }
</script> </script>

View File

@ -23,10 +23,10 @@
<script> <script>
export default { export default {
name: 'HEADER', name: 'HEADER',
data(){ return { gstore: window.gstore.data }; }, data(){ return { gstore: gstore.data }; },
methods: { methods: {
show_notif(uri){ show_notif(uri){
window.gstore.data.func.nav(this.$router, uri); this.gstore.func.nav(this.$router, uri);
} }
} }
} }

View File

@ -18,10 +18,10 @@
<script> <script>
export default { export default {
name: 'MENU', name: 'MENU',
data(){ return { gstore: window.gstore.data }; }, data(){ return { gstore: gstore.data }; },
methods: { methods: {
navigate(uri){ navigate(uri){
window.gstore.data.func.nav(this.$router, uri); this.gstore.func.nav(this.$router, uri);
} }
} }
} }

View File

@ -21,7 +21,7 @@
export default { export default {
name: 'wrapper', name: 'wrapper',
data(){ return { gstore: window.gstore.data }; }, data(){ return { gstore: gstore.data }; },
components: { components: {
'HeaderComp': header_vue, 'HeaderComp': header_vue,
'MenuComp': menu_vue 'MenuComp': menu_vue