[lib.content-controller] added channel DELETE/CREATE/UPDATE [MUST TEST]

This commit is contained in:
xdrm-brackets 2018-04-03 22:12:01 +02:00
parent b76d2f8499
commit 40c0686400
2 changed files with 37 additions and 10 deletions

View File

@ -91,7 +91,7 @@ export default class ChannelController{
for(let c of channels){ for(let c of channels){
// add 'users' field (will be filled by GET channel/cid) // add 'users' field (will be filled by GET channel/cid)
c.users = []; !( c.users instanceof Array ) && ( c.users = [] );
this.list.push(c); this.list.push(c);
@ -235,7 +235,7 @@ export default class ChannelController{
return false; return false;
/* (3) Reload channel list */ /* (3) Reload channel list */
this.fetch(); // this.fetch();
}.bind(this), auth.token); }.bind(this), auth.token);
@ -258,7 +258,7 @@ export default class ChannelController{
gs.get.popup.hide(); gs.get.popup.hide();
/* (2) Reload channel list */ /* (2) Reload channel list */
this.fetch(); // this.fetch();
}.bind(this), auth.token); }.bind(this), auth.token);

View File

@ -254,13 +254,16 @@ export default class ContentController{
---------------------------------------------------------*/ ---------------------------------------------------------*/
for( let c of _dat.channels.rem ){ for( let c of _dat.channels.rem ){
console.log(c); for( let ci in gs.get.channel.list ){
// gs.get.channel.dump({ // 1. Local copy channel data
// id: parseInt(c.id), let channel = gs.get.channel.list[ci];
// label: c.name,
// link: c.link // 2. If id matches -> REMOVE
// }, true); if( channel.id === c.id )
gs.get.channel.list.splice(ci, 1);
}
} }
@ -273,11 +276,35 @@ export default class ContentController{
gs.get.channel.dump({ gs.get.channel.dump({
id: parseInt(c.id), id: parseInt(c.id),
label: c.name, label: c.name,
link: c.link link: c.link,
users: c.users || []
}, true); }, 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;
}
}
}
} }