Browse Source

added data_strct to dbs : it reference all links in both ways : to and from

Bachir Soussi Chiadmi 6 years ago
parent
commit
6fce164c58
1 changed files with 34 additions and 0 deletions
  1. 34 0
      assets/modules/dbs.js

+ 34 - 0
assets/modules/dbs.js

@@ -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();
   }
 }