From 40c06864004eaac50bda1845829c2e5660fe30a8 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 3 Apr 2018 22:12:01 +0200 Subject: [PATCH] [lib.content-controller] added channel DELETE/CREATE/UPDATE [MUST TEST] --- webpack/lib/channel-controller.js | 6 ++--- webpack/lib/content-controller.js | 41 +++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/webpack/lib/channel-controller.js b/webpack/lib/channel-controller.js index b783b31..6a676b2 100644 --- a/webpack/lib/channel-controller.js +++ b/webpack/lib/channel-controller.js @@ -91,7 +91,7 @@ export default class ChannelController{ for(let c of channels){ // add 'users' field (will be filled by GET channel/cid) - c.users = []; + !( c.users instanceof Array ) && ( c.users = [] ); this.list.push(c); @@ -235,7 +235,7 @@ export default class ChannelController{ return false; /* (3) Reload channel list */ - this.fetch(); + // this.fetch(); }.bind(this), auth.token); @@ -258,7 +258,7 @@ export default class ChannelController{ gs.get.popup.hide(); /* (2) Reload channel list */ - this.fetch(); + // this.fetch(); }.bind(this), auth.token); diff --git a/webpack/lib/content-controller.js b/webpack/lib/content-controller.js index 372d9ac..e1d01b5 100644 --- a/webpack/lib/content-controller.js +++ b/webpack/lib/content-controller.js @@ -254,13 +254,16 @@ export default class ContentController{ ---------------------------------------------------------*/ for( let c of _dat.channels.rem ){ - console.log(c); + for( let ci in gs.get.channel.list ){ - // gs.get.channel.dump({ - // id: parseInt(c.id), - // label: c.name, - // link: c.link - // }, true); + // 1. Local copy channel data + let channel = gs.get.channel.list[ci]; + + // 2. If id matches -> REMOVE + if( channel.id === c.id ) + gs.get.channel.list.splice(ci, 1); + + } } @@ -273,11 +276,35 @@ export default class ContentController{ gs.get.channel.dump({ id: parseInt(c.id), label: c.name, - link: c.link + link: c.link, + users: c.users || [] }, true); } + + /* (5) Manage channels UPDATE + ---------------------------------------------------------*/ + for( let c of _dat.channels.upd ){ + + for( let ci in gs.get.channel.list ){ + + // 1. Local copy channel data + let channel = gs.get.channel.list[ci]; + + // 2. If id matches -> UPDATE + if( channel.id === c.id ){ + + gs.get.channel.list[ci].label = c.name; + gs.get.channel.list[ci].link = c.link; + gs.get.channel.list[ci].users = c.users; + + } + + } + + } + }