gues type from id, classe added to dots on connecction mode (remians nested dots and text mode)

This commit is contained in:
Bachir Soussi Chiadmi
2018-02-22 23:18:03 +01:00
parent c7beaf1e10
commit 2ce27b3245
12 changed files with 258 additions and 79 deletions
+96 -8
View File
@@ -17,7 +17,9 @@ var _Ui = require('./ui.js');
// /_____/\____/\__/
var _Dot = {
id:null,
dottype:null,
type:'',
title:'',
text:'',
summary:'',
active:true,
@@ -25,6 +27,76 @@ var _Dot = {
links:null,
parents:[],
lang:_dbs.lang,
setupDotType(vn){
// var rx_id = /^(\d)(app|agd|\d\d|pr|ad|ap|c|p|d|a)(cd|sc|\d\d|d|c|a|l|p|\d)?(e|\d|sc)?(d|c|a|sc)?$/;
// var m = this.id.match(rx_id);
// if(m){
// switch(true){
// case /^\d{2}$/.test(m[2]):
// switch(true){
// case /^cd$/.test(m[3]) : this.dottype = 'corollaire-demo'; break;
// case /^sc$/.test(m[3]) : this.dottype = 'scolie'; break;
// case /^d$/.test(m[3]) : this.dottype = 'demonstration'; break;
// case /^c$/.test(m[3]) :
// switch(true){
// case /^sc$/.test(m[4]): this.dottype = 'scolie'; break;
// case /^d$/.test(m[4]) : this.dottype = 'demonstration'; break;
// case /^d$/.test(m[5]) : this.dottype = 'demonstration'; break;
// case /^sc$/.test(m[5]): this.dottype = 'scolie'; break;
// case /^\d$/.test(m[4]): this.dottype = 'corollaire'; break;
// case !m[4] : this.dottype = 'corollaire'; break;
// }
// break;
// case /^a$/.test(m[3]) : this.dottype = 'axiom'; break;
// case /^l$/.test(m[3]) :
// switch(true){
// case /^d$/.test(m[5]) : this.dottype = 'demonstration'; break;
// case /^sc$/.test(m[5]): this.dottype = 'scolie'; break;
// case !m[5] : this.dottype = 'lemme'; break;
// }
// break;
// case /^p$/.test(m[3]) : this.dottype = 'postulat'; break;
// case /^\d$/.test(m[3]) : this.dottype = '??'; break;
// case /^\d{2}$/.test(m[3]) : this.dottype = '??'; break;
// case !m[3] : this.dottype = 'proposition'; break;
// }
// break;
// case /^app|ap$/.test(m[2]) : this.dottype = 'appendice'; break;
// case /^agd$/.test(m[2]) : this.dottype = 'def-gen-affect'; break;
// case /^pr$/.test(m[2]) : this.dottype = 'preface'; break;
// case /^ad$/.test(m[2]) :
// switch(true){
// case /^e$/.test(m[4]) :this.dottype = 'explication'; break;
// case !m[4] :this.dottype = 'def-affect'; break;
// }
// break;
// case /^c$/.test(m[2]) : this.dottype = 'chapitre'; break;
// case /^p$/.test(m[2]) : this.dottype = 'postulat'; break;
// case /^d$/.test(m[2]) :
// switch(true){
// case /^e$/.test(m[4]) : this.dottype = 'explication'; break;
// case !m[4] : this.dottype = 'definition'; break;
// }
// break;
// case /^a$/.test(m[2]) : this.dottype = 'axiom'; break;
// }
// // }
// }
// console.log(`${this.id} -> ${this.dottype}`,m);
//
// // TODO: fix false ids
// // we have app and ap for appendice (1app | 4ap)
// // 213def ??
// // 209cd demo ou corollaire-demo ??
// // 210csc scolie ou corollaire-scolie ??
// // 213l1d demo ??
},
setupTitle(vn){
this.title = vn.attrs.title;
if(!this.title){
this.title = this.type;
}
},
setuptext(vn){
// console.log('setuptext', vn);
@@ -43,9 +115,15 @@ var _Dot = {
oninit(vn){
this.id = vn.attrs.id;
this.type = vn.attrs.type;
this.title = vn.attrs.title || "title";
// this.title = vn.attrs.title || "title";
// this.setupDotType(vn);
this.dottype = vn.attrs.dottype;
this.setupTitle(vn);
this.setuptext(vn);
console.log(`${this.id} -> ${this.dottype}`);
if(typeof vn.attrs.active !== 'undefined')
this.active = vn.attrs.active;
@@ -80,6 +158,7 @@ var _Dot = {
// console.log('_Dot view '+this.id+' parents :',this.parents);
var dot_content = [
// links to
// TODO: add dottype class to nested dots
this.links.to.length
? m('nav', {'class':'links to'}, this.links.to.map(id => {
// console.log(id);
@@ -98,9 +177,11 @@ var _Dot = {
)
: null,
// id
m('span', {'class':'id'}, this.id), // this.type+' '+
// m('span', {'class':'id'}, this.id), // this.type+' '+
// bullet
m('span', {'class':'bullet'}, m.trust('⚫')),
// m('span', {'class':'bullet'}, m.trust('⚫')),
// Title
m('span', {'class':'title'}, m.trust(this.title)),
// full text
m('section', {
'class':'text',
@@ -134,6 +215,7 @@ var _Dot = {
this.links.from.length
? m('nav', {'class':'links from'}, this.links.from.map(id => {
// retrun a dot
// TODO: add dottype class to nested dots
return m(_Dot, {
"id":id,
'text':_dbs.data_byid[_dbs.lang][id].text,
@@ -150,8 +232,9 @@ var _Dot = {
}else{
// preview dot
var dot_content = [
m('span', {'class':'id'}, this.id), // this.type+' '+
m('span', {'class':'bullet'}, m.trust('•')),
// m('span', {'class':'id'}, this.id), // this.type+' '+
// m('span', {'class':'bullet'}, m.trust('•')),
m('span', {'class':'title'}, m.trust(this.title)),
m('p', {
'class':'summary',
onclick(e){
@@ -164,7 +247,7 @@ var _Dot = {
return m('div',{
'uid':this.id,
'class':'dot'
'class':`dot ${this.dottype}`
},
dot_content
);
@@ -211,6 +294,7 @@ var _Child = {
id:null,
part:null,
type:null,
dottype:null,
// nested:false,
text:'',
oninit(vn){
@@ -220,6 +304,7 @@ var _Child = {
// vn.state.part = vn.state.slug.match(/^(\d)(.+)/)[1];
this.text = vn.attrs.text;
// this.nested = vn.attrs.nested || false;
this.dottype = vn.attrs.dottype;
},
onbeforeupdate(vn, old){
// this.nested = vn.attrs.nested || false;
@@ -227,7 +312,7 @@ var _Child = {
this.text = vn.attrs.text;
},
view(vn){
return m(_Dot, {"id":this.id, 'text':this.text, 'type':this.type});
return m(_Dot, {"id":this.id, 'text':this.text, 'type':this.type, 'dottype':this.dottype});
}
};
@@ -241,6 +326,7 @@ var _Enonce = {
id:null,
title:null,
text:null,
dottype:null,
// nested:false,
childs:[],
oninit(vn){
@@ -251,6 +337,7 @@ var _Enonce = {
this.text = vn.attrs.text;
this.childs = vn.attrs.childs || [];
// this.nested = vn.attrs.nested || false;
this.dottype = vn.attrs.dottype;
},
onbeforeupdate(vn, old) {
// console.log(vn.attrs.childs);
@@ -259,12 +346,13 @@ var _Enonce = {
this.childs = vn.attrs.childs || [];
// this.nested = vn.attrs.nested || false;
// if(vn.attrs.id == '1d1') console.log('_Enonce UPDATE, text :', vn.attrs.text);
this.dottype = vn.attrs.dottype;
},
view(vn){
// if(vn.attrs.id == '1d1') console.log('_Enonce VIEW, text :', vn.attrs.text);
return [
// create dot
m(_Dot, {"id":this.id, 'text':this.text,'type':this.title}),
m(_Dot, {"id":this.id, 'text':this.text,'type':this.title, 'dottype':this.dottype}),
// addd children
this.childs.map(c => { return m(_Child, c); })
]
+1 -1
View File
@@ -278,7 +278,7 @@ var _Part = {
m("h1", {'class':'part-title', 'part':this.id}, m.trust(markdown.renderInline(this.title))),
// create text node
this.enonces.map(e => {
console.log(e.title +" - "+ e.type);
// console.log(e.title +" - "+ e.type);
// var title = e.title || '';
switch (e.type) {
case "title":
+103
View File
@@ -52,6 +52,7 @@ module.exports = {
case 3:
// console.log('loading');
break;
break;
case 4:
if (xobj.status === 200) {
this.onJSONLoaded(lc, xobj.responseText, callback);
@@ -77,17 +78,32 @@ module.exports = {
},
parseByID(callback){
// loop through laguages
for(l in this.data){
// console.log('l', l);
this.data_byid[l] = {};
// loop through parts
for (p in this.data[l]) {
if(this.data[l][p].type !== "intro"){
// console.log(this.data[l][p]);
// loop through enonces
for (e in this.data[l][p].enonces) {
// console.log('e',e);
if(this.data[l][p].enonces[e].id){
// guess the type from the id
// console.log(this.data[l][p].enonces[e].id);
this.data[l][p].enonces[e].dottype = this.setupType(this.data[l][p].enonces[e].id);
}
// records childs in flat array by ids
this.data_byid[l][this.data[l][p].enonces[e].id] = this.data[l][p].enonces[e];
// loop through childs
for (c in this.data[l][p].enonces[e].childs){
// console.log(_db[p][e][c]);
if(this.data[l][p].enonces[e].childs[c].id){
// guess the type from the id
this.data[l][p].enonces[e].childs[c].dottype = this.setupType(this.data[l][p].enonces[e].childs[c].id);
}
// records childs in flat array by ids
this.data_byid[l][this.data[l][p].enonces[e].childs[c].id] = this.data[l][p].enonces[e].childs[c];
}
}
@@ -97,6 +113,93 @@ module.exports = {
// console.log('this.data_byid', this.data_byid);
this.parseStrct(callback);
},
setupType(id){
// console.log('setupType',id);
var rx_id = /^(\d)(app|agd|\d\d|pr|ad|ap|c|p|d|a)(cd|sc|\d\d|d|c|a|l|p|\d)?(e|\d|sc)?(d|c|a|sc)?$/;
var m = id.match(rx_id);
if(m){
switch(true){
case /^\d{2}$/.test(m[2]):
switch(true){
case /^cd$/.test(m[3]) : return 'corollaire-demo';
case /^cd$/.test(m[3]) : return 'corollaire-demo';
case /^sc$/.test(m[3]) : return 'scolie';
case /^sc$/.test(m[3]) : return 'scolie';
case /^d$/.test(m[3]) : return 'demonstration';
case /^d$/.test(m[3]) : return 'demonstration';
case /^c$/.test(m[3]) :
switch(true){
case /^sc$/.test(m[4]): return 'scolie';
case /^sc$/.test(m[4]): return 'scolie';
case /^d$/.test(m[4]) : return 'demonstration';
case /^d$/.test(m[4]) : return 'demonstration';
case /^d$/.test(m[5]) : return 'demonstration';
case /^d$/.test(m[5]) : return 'demonstration';
case /^sc$/.test(m[5]): return 'scolie';
case /^sc$/.test(m[5]): return 'scolie';
case /^\d$/.test(m[4]): return 'corollaire';
case /^\d$/.test(m[4]): return 'corollaire';
case !m[4] : return 'corollaire';
case !m[4] : return 'corollaire';
}
case /^a$/.test(m[3]) : return 'axiom';
case /^a$/.test(m[3]) : return 'axiom';
case /^l$/.test(m[3]) :
switch(true){
case /^d$/.test(m[5]) : return 'demonstration';
case /^d$/.test(m[5]) : return 'demonstration';
case /^sc$/.test(m[5]): return 'scolie';
case /^sc$/.test(m[5]): return 'scolie';
case !m[5] : return 'lemme';
case !m[5] : return 'lemme';
}
case /^p$/.test(m[3]) : return 'postulat';
case /^p$/.test(m[3]) : return 'postulat';
case /^\d$/.test(m[3]) : return '??';
case /^\d$/.test(m[3]) : return '??';
case /^\d{2}$/.test(m[3]) : return '??';
case /^\d{2}$/.test(m[3]) : return '??';
case !m[3] : return 'proposition';
case !m[3] : return 'proposition';
}
case /^app|ap$/.test(m[2]) : return 'appendice';
case /^app|ap$/.test(m[2]) : return 'appendice';
case /^agd$/.test(m[2]) : return 'def-gen-affect';
case /^agd$/.test(m[2]) : return 'def-gen-affect';
case /^pr$/.test(m[2]) : return 'preface';
case /^pr$/.test(m[2]) : return 'preface';
case /^ad$/.test(m[2]) :
switch(true){
case /^e$/.test(m[4]) :return 'explication';
case /^e$/.test(m[4]) :return 'explication';
case !m[4] :return 'def-affect';
case !m[4] :return 'def-affect';
}
case /^c$/.test(m[2]) : return 'chapitre';
case /^c$/.test(m[2]) : return 'chapitre';
case /^p$/.test(m[2]) : return 'postulat';
case /^p$/.test(m[2]) : return 'postulat';
case /^d$/.test(m[2]) :
switch(true){
case /^e$/.test(m[4]) : return 'explication';
case /^e$/.test(m[4]) : return 'explication';
case !m[4] : return 'definition';
case !m[4] : return 'definition';
}
case /^a$/.test(m[2]) : return 'axiom';
case /^a$/.test(m[2]) : return 'axiom';
}
// }
}
// console.log(`${this.id} -> ${this.dottype}`,m);
// TODO: fix false ids
// we have app and ap for appendice (1app | 4ap)
// 213def ??
// 209cd demo ou corollaire-demo ??
// 210csc scolie ou corollaire-scolie ??
// 213l1d demo ??
},
parseStrct(callback){
var id, item, obj, links_match, link, tid;
+2 -2
View File
@@ -77,10 +77,10 @@ var _RouteMenu = {
onupdate : m.route.link
}, _i18n.t("Text"))),
m('li', m('a', {
'href':`/${lang}/conexions${path[3]}`,
'href':`/${lang}/connections${path[3]}`,
oncreate : m.route.link,
onupdate : m.route.link
}, _i18n.t("Conexions"))),
}, _i18n.t("Connections"))),
])
]);
}
+2 -2
View File
@@ -45,8 +45,8 @@ module.exports = {
'bra':'Texto',
'lat':'Illud'
},
'Conexions':{
'en':'Conexions',
'Connections':{
'en':'Connections',
'fr':'Connections',
'bra':'Conexões',
'lat':'Hospites'
+1 -1
View File
@@ -64,7 +64,7 @@ module.exports = {
console.log('new sticky', stkd_part.innerHTML);
// clone only once
clone = stkd_part.cloneNode(true);
// stkd_wrapper.innerHTML = '';
stkd_wrapper.innerHTML = '';
// fill stkd_wrapper
stkd_wrapper.appendChild(clone);
last_stkd_part = stkd_part;