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); })
]