added lat and en languages, handeled new data structure : titles and filet

This commit is contained in:
Bachir Soussi Chiadmi
2017-10-12 14:24:27 +02:00
parent df788ba0b7
commit 72602b3e12
12 changed files with 11108 additions and 10363 deletions
+1
View File
@@ -1 +1,2 @@
node_modules node_modules
*.back
+166 -14
View File
@@ -1585,7 +1585,133 @@ else window.m = m
/* 2 */ /* 2 */
/***/ (function(module, exports) { /***/ (function(module, exports) {
throw new Error("Module parse failed: /mnt/Data/bach/Sites/ethica-spinoza.net/static.ethica-spinoza.net/assets/modules/dbs.js Unexpected token (15:4)\nYou may need an appropriate loader to handle this file type.\n| {'lc':'fr', 'label':'fr', 'db':'2-Appuhn-FR-ethicadb.json'},\n| {'lc':'bra', 'label':'bra', 'db':'ethica-bresilen.json'}\n| {'lc':'en', 'label':'en', 'db':'2-Appuhn-FR-ethicadb.json'},\n| ],\n| data:[],");
// _
// (_)________ ____
// / / ___/ __ \/ __ \
// / (__ ) /_/ / / / /
// __/ /____/\____/_/ /_/
// /___/
module.exports = {
lang:'fr',
langs:[
{'lc':'lat', 'label':'lat', 'db':'0-LAT-ethicadb.json'},
{'lc':'fr', 'label':'fr', 'db':'2-Appuhn-FR-ethicadb.json'},
{'lc':'bra', 'label':'bra', 'db':'ethica-bresilen.json'},
{'lc':'en', 'label':'en', 'db':'3-Elwes-EN-ethicadb.json'}
],
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++) {
this.loadJSON(this.langs[i].lc, 'assets/jsondb/'+this.langs[i].db, callback)
}
},
loadJSON: function(lc, file, callback){
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
// TODO: load and unzip gziped json
// xobj.setRequestHeader('Accept-Encoding', 'gzip');
xobj.onreadystatechange = function () {
// console.log('onreadystatechange', xobj.readyState);
switch(xobj.readyState){
case 3:
console.log('loading');
break;
case 4:
if (xobj.status === 200) {
this.onJSONLoaded(lc, xobj.responseText, callback);
} else {
console.log("Status de la réponse: %d (%s)", xobj.status, xobj.statusText);
}
break;
}
}.bind(this);
xobj.open('GET', file, true);
xobj.send(null);
},
onJSONLoaded: function(lc, json, callback){
console.log('onDBLoaded '+lc);
this.data[lc] = JSON.parse(json);
this.loaded_dbs ++;
//
if (this.loaded_dbs == this.langs.length) {
this.parseByID(callback);
}
},
parseByID: function(callback){
for(l in this.data){
// console.log('l', l);
this.data_byid[l] = {};
for (p in this.data[l]) {
// console.log(this.data[l][p]);
for (e in this.data[l][p].enonces) {
// console.log('e',e);
this.data_byid[l][this.data[l][p].enonces[e].id] = this.data[l][p].enonces[e];
for (c in this.data[l][p].enonces[e].childs){
// console.log(_db[p][e][c]);
this.data_byid[l][this.data[l][p].enonces[e].childs[c].id] = this.data[l][p].enonces[e].childs[c];
}
}
}
}
// 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);
// skeep titles as they don't have structure data
if(item.type == "title") continue;
obj = {
'to':[],
'from':[],
};
// get links
links_match = item.text.match(/\[[^\]]+\]\([^\)]+\)/g);
// console.log(links_match);
// if links exist on text
if(links_match){
for(link of links_match){
// console.log(link);
// get the target id
tid = link.match(/\((.+)\)/)[1];
// avoid duplicates
if (obj.to.indexOf(tid) == -1)
obj.to.push(tid);
// add id to "from" links in target
// if target exists
if(typeof this.data_strct[tid] !== 'undefined'){
// avoid duplicates
if (this.data_strct[tid].from.indexOf(tid) == -1)
this.data_strct[tid].from.push(id);
}else{
// if targets does not exists, the db has an issue, warn about that
console.log('!! warning : '+tid+' target id does not exists');
}
}
}
// add the item links to the main links listings
this.data_strct[id] = obj;
}
// console.log('data_strct',this.data_strct);
callback();
}
}
/***/ }), /***/ }),
/* 3 */ /* 3 */
@@ -3389,7 +3515,20 @@ var _Part = {
// create text node // create text node
this.enonces.map(function(e){ this.enonces.map(function(e){
// console.log(e.text); // console.log(e.text);
return m(_Enonce, Object.assign({"partid":this.id},e)) // return m(_Enonce, Object.assign({"partid":this.id},e))
switch (e.type) {
case "title":
// handle titles
return m("h2", {'class':'title'}, m.trust(markdown.renderInline(e.title)));
break;
case "filet":
// handle filets
return m("h4", {'class':'filet'}, m.trust(markdown.renderInline(e.title)));
break;
default:
// or build structure
return m(_Enonce, Object.assign({"partid":this.id},e));
}
}) })
] ]
) )
@@ -3397,11 +3536,11 @@ var _Part = {
} }
// ____ __ // ______
// / __ \____ / /______ // /_ __/_______ ___
// / / / / __ \/ __/ ___/ // / / / ___/ _ \/ _ \
// / /_/ / /_/ / /_(__ ) // / / / / / __/ __/
// /_____/\____/\__/____/ // /_/ /_/ \___/\___/
module.exports = { module.exports = {
view: function(){ view: function(){
// console.log('_Tree view', _dbs.lang); // console.log('_Tree view', _dbs.lang);
@@ -13420,19 +13559,32 @@ var _Part = {
m("h1", {'class':'part'}, m.trust(markdown.renderInline(this.title))), m("h1", {'class':'part'}, m.trust(markdown.renderInline(this.title))),
// create text node // create text node
this.enonces.map(function(e){ this.enonces.map(function(e){
// console.log(e.text); console.log(e.type);
return m(_Enonce, Object.assign({"partid":this.id},e))
switch (e.type) {
case "title":
// handle titles
return m("h2", {'class':'title'}, m.trust(markdown.renderInline(e.title)));
break;
case "filet":
// handle filets
return m("h4", {'class':'filet'}, m.trust(markdown.renderInline(e.title)));
break;
default:
// or build structure
return m(_Enonce, Object.assign({"partid":this.id},e));
}
}) })
] ]
) )
} }
} }
// ______ // ____ __ _
// /_ __/_______ ___ // / _/___ / / (_)___ ___
// / / / ___/ _ \/ _ \ // / // __ \/ / / / __ \/ _ \
// / / / / / __/ __/ // _/ // / / / /___/ / / / / __/
// /_/ /_/ \___/\___/ // /___/_/ /_/_____/_/_/ /_/\___/
module.exports = { module.exports = {
view: function(){ view: function(){
console.log('_Inline view', _dbs.lang); console.log('_Inline view', _dbs.lang);
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+7 -2
View File
@@ -9,8 +9,10 @@
module.exports = { module.exports = {
lang:'fr', lang:'fr',
langs:[ langs:[
{'lc':'lat', 'label':'lat', 'db':'0-LAT-ethicadb.json'},
{'lc':'fr', 'label':'fr', 'db':'2-Appuhn-FR-ethicadb.json'}, {'lc':'fr', 'label':'fr', 'db':'2-Appuhn-FR-ethicadb.json'},
{'lc':'bra', 'label':'bra', 'db':'ethica-bresilen.json'} {'lc':'bra', 'label':'bra', 'db':'ethica-bresilen.json'},
{'lc':'en', 'label':'en', 'db':'3-Elwes-EN-ethicadb.json'}
], ],
data:[], data:[],
loaded_dbs:0, loaded_dbs:0,
@@ -48,7 +50,7 @@ module.exports = {
xobj.send(null); xobj.send(null);
}, },
onJSONLoaded: function(lc, json, callback){ onJSONLoaded: function(lc, json, callback){
console.log('onDBLoaded'); console.log('onDBLoaded '+lc);
this.data[lc] = JSON.parse(json); this.data[lc] = JSON.parse(json);
this.loaded_dbs ++; this.loaded_dbs ++;
// //
@@ -82,6 +84,9 @@ module.exports = {
for (id in this.data_byid[this.langs[0].lc]) { for (id in this.data_byid[this.langs[0].lc]) {
item = this.data_byid[this.langs[0].lc][id]; item = this.data_byid[this.langs[0].lc][id];
// console.log(item); // console.log(item);
// skeep titles as they don't have structure data
if(item.type == "title") continue;
obj = { obj = {
'to':[], 'to':[],
'from':[], 'from':[],
+20 -7
View File
@@ -269,19 +269,32 @@ var _Part = {
m("h1", {'class':'part'}, m.trust(markdown.renderInline(this.title))), m("h1", {'class':'part'}, m.trust(markdown.renderInline(this.title))),
// create text node // create text node
this.enonces.map(function(e){ this.enonces.map(function(e){
// console.log(e.text); console.log(e.type);
return m(_Enonce, Object.assign({"partid":this.id},e))
switch (e.type) {
case "title":
// handle titles
return m("h2", {'class':'title'}, m.trust(markdown.renderInline(e.title)));
break;
case "filet":
// handle filets
return m("h4", {'class':'filet'}, m.trust(markdown.renderInline(e.title)));
break;
default:
// or build structure
return m(_Enonce, Object.assign({"partid":this.id},e));
}
}) })
] ]
) )
} }
} }
// ______ // ____ __ _
// /_ __/_______ ___ // / _/___ / / (_)___ ___
// / / / ___/ _ \/ _ \ // / // __ \/ / / / __ \/ _ \
// / / / / / __/ __/ // _/ // / / / /___/ / / / / __/
// /_/ /_/ \___/\___/ // /___/_/ /_/_____/_/_/ /_/\___/
module.exports = { module.exports = {
view: function(){ view: function(){
console.log('_Inline view', _dbs.lang); console.log('_Inline view', _dbs.lang);
+19 -6
View File
@@ -302,7 +302,20 @@ var _Part = {
// create text node // create text node
this.enonces.map(function(e){ this.enonces.map(function(e){
// console.log(e.text); // console.log(e.text);
return m(_Enonce, Object.assign({"partid":this.id},e)) // return m(_Enonce, Object.assign({"partid":this.id},e))
switch (e.type) {
case "title":
// handle titles
return m("h2", {'class':'title'}, m.trust(markdown.renderInline(e.title)));
break;
case "filet":
// handle filets
return m("h4", {'class':'filet'}, m.trust(markdown.renderInline(e.title)));
break;
default:
// or build structure
return m(_Enonce, Object.assign({"partid":this.id},e));
}
}) })
] ]
) )
@@ -310,11 +323,11 @@ var _Part = {
} }
// ____ __ // ______
// / __ \____ / /______ // /_ __/_______ ___
// / / / / __ \/ __/ ___/ // / / / ___/ _ \/ _ \
// / /_/ / /_/ / /_(__ ) // / / / / / __/ __/
// /_____/\____/\__/____/ // /_/ /_/ \___/\___/
module.exports = { module.exports = {
view: function(){ view: function(){
// console.log('_Tree view', _dbs.lang); // console.log('_Tree view', _dbs.lang);