From 5406b38cbdc4b4a9a4fc9ff725ee4966fdac2f11 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 21 Mar 2018 23:34:45 +0100 Subject: [PATCH] [main] manage redirection from URL if 'gs.get.channel.get()' used in vueJS templates overrides 'gs.get.channel.active' -> now restored after fetching data [+removed blocking same-page navigation] --- webpack/init/channels.js | 33 ++++++++++++++++++++++++++------- webpack/main.js | 27 +++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/webpack/init/channels.js b/webpack/init/channels.js index 1d7353e..b7111db 100644 --- a/webpack/init/channels.js +++ b/webpack/init/channels.js @@ -21,6 +21,9 @@ gs.get.channel.dump = function(){}; /* (6) Initialize accessor for channel data */ gs.get.channel.get = function(){}; +/* (7) Initialize local channel opener */ +gs.get.channel.open = function(){}; + /* (2) Channel navigation @@ -35,9 +38,9 @@ gs.get.channel.nav = function(channel_id=null){ /* (1) Get channel data */ var channel = this.get(channel_id); - /* (3) Abort if same channel */ - if( gs.get.router.history.current.params.link === channel.link ) - return false; + /* (2) Abort if same channel */ + // if( gs.get.router.history.current.params.link === channel.link ) + // return false; /* (3) Navigate vue-router */ gs.get.router.push(`/channel/${channel.link}`); @@ -152,8 +155,24 @@ gs.get.channel.get = function(channel_id=null){ - -/* (N) Manage active channel from URL +/* (5) Open a local channel +* +* @type Local channel type (text, voice, video) +* @id Local channel id +* ---------------------------------------------------------*/ -/* (1) Set current active channel item from URL */ -// gs.get.channel.nav(); \ No newline at end of file +gs.get.channel.open = function(type=null, id=null){ + + let error = function(type){ this.get().local[type].active = null; }.bind(this, type); + + /* (1) Get current channel */ + let channel = this.get(); + + /* (2) Manage invalid @type */ + if( typeof type !== 'string' || !channel.local.hasOwnProperty(type) ) + return false; + + + + console.log(`open(${type}, ${id})`, channel.id); +}; \ No newline at end of file diff --git a/webpack/main.js b/webpack/main.js index ec13772..f93c67e 100644 --- a/webpack/main.js +++ b/webpack/main.js @@ -24,12 +24,31 @@ new Vue({ render(h){ return h(wrapper); } }) - +/* (2) Store route params */ +window.initial_link = gs.get.router.history.current.params.link; +console.log(`[channel.URL] ${initial_link}`); /* (3) Channel data gathering ---------------------------------------------------------*/ /* (1) Fetch channel data */ -gs.get.channel.dump( require('./mockup/channels.json') ); +setTimeout(() => { -/* (2) Initialize channel_id guess */ -gs.get.channel.nav(); \ No newline at end of file + /* (2) Fetch data */ + gs.get.channel.dump( require('./mockup/channels.json') ); + + /* (3) Find if @link matches */ + var redirect_id = null; + for( let c of gs.get.channel.list ){ + + if( c.link === window.initial_link ){ + redirect_id = c.id; + break; + } + + } + + /* (4) Emulate navigatation from URL */ + console.log(`[restore.channel] ${redirect_id}`); + gs.get.channel.nav(redirect_id); + +}, 500); \ No newline at end of file