added data_strct to dbs : it reference all links in both ways : to and from
This commit is contained in:
@@ -15,6 +15,7 @@ module.exports = {
|
||||
data:[],
|
||||
loaded_dbs:0,
|
||||
data_byid:[],
|
||||
data_strct:{},
|
||||
load: function(callback) {
|
||||
// load all dbs, when all loaded call main app callback function
|
||||
for (var i = 0; i < this.langs.length; i++) {
|
||||
@@ -73,6 +74,39 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
// console.log('this.data_byid', this.data_byid);
|
||||
this.parseStrct(callback);
|
||||
},
|
||||
parseStrct: function(callback){
|
||||
|
||||
var id, item, obj, links_match, link, tid;
|
||||
for (id in this.data_byid[this.langs[0].lc]) {
|
||||
item = this.data_byid[this.langs[0].lc][id];
|
||||
// console.log(item);
|
||||
obj = {
|
||||
'to':[],
|
||||
'from':[],
|
||||
};
|
||||
// get links
|
||||
links_match = item.text.match(/\[[^\]]+\]\([^\)]+\)/g);
|
||||
// console.log(links_match);
|
||||
if(links_match){
|
||||
for(link of links_match){
|
||||
// console.log(link);
|
||||
tid = link.match(/\((.+)\)/)[1];
|
||||
obj.to.push(tid);
|
||||
// add id to "from" links in target
|
||||
if(typeof this.data_strct[tid] !== 'undefined'){
|
||||
this.data_strct[tid].from.push(id);
|
||||
}else{
|
||||
console.log('!! warning : '+tid+' target id does not exists');
|
||||
}
|
||||
}
|
||||
}
|
||||
// console.log(this.links);
|
||||
this.data_strct[id] = obj;
|
||||
}
|
||||
// console.log('data_strct',this.data_strct);
|
||||
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user