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 */
require('./vue-config');
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 */
Vue.use(VueRouter);
@ -46,51 +46,51 @@ new Vue({
/* (3) Set WebSocket channels
---------------------------------------------------------*/
/* (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 //
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 //
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 //
if( msg.connected != null ){
console.log('Detected '+msg.connected.length+' new user(s)');
window.gstore.data.notif[0].data = window.gstore.data.notif[0].data.concat( msg.connected );
window.gstore.data.notif[0].count += msg.connected.length;
gstore.data.notif[0].data = gstore.data.notif[0].data.concat( msg.connected );
gstore.data.notif[0].count += msg.connected.length;
}
}).send({name: window._SERVER.session.name});
}).send({name: _SERVER.session.name});
/* (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 //
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 //
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 //
if( msg.msg != null ){
console.log('Received '+msg.msg.length+' new message(s)');
window.gstore.data.notif[1].data = window.gstore.data.notif[1].data.concat( msg.msg );
window.gstore.data.notif[1].count += msg.msg.length
gstore.data.notif[1].data = gstore.data.notif[1].data.concat( msg.msg );
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
---------------------------------------------------------*/
window.onbeforeunload = function() {
window.wsc_chat.send('{"close": true}');
window.wsc_connect.send('{"close": true}');
wsc_chat.send('{"close": true}');
wsc_connect.send('{"close": true}');
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -23,10 +23,10 @@
<script>
export default {
name: 'HEADER',
data(){ return { gstore: window.gstore.data }; },
data(){ return { gstore: gstore.data }; },
methods: {
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>
export default {
name: 'MENU',
data(){ return { gstore: window.gstore.data }; },
data(){ return { gstore: gstore.data }; },
methods: {
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 {
name: 'wrapper',
data(){ return { gstore: window.gstore.data }; },
data(){ return { gstore: gstore.data }; },
components: {
'HeaderComp': header_vue,
'MenuComp': menu_vue