move classification out of load

This commit is contained in:
TreetopFlyer 2021-05-14 13:53:28 -04:00
parent 27990678c2
commit 5a64ee41c3

View File

@ -259,31 +259,6 @@ let Node = {
{ {
Node.IterateUp(inNode.Parent, inIterator); Node.IterateUp(inNode.Parent, inIterator);
} }
},
Path:(inNode, inList) =>
{
let node = inNode;
while(node)
{
inList.push(node);
node = node.Parent;
}
},
Leaves:(inNode, inList) =>
{
var i;
var child;
if(inNode.Children)
{
for(i=0; i<inNode.Children.length; i++)
{
Node.Decedents(inNode.Children[i], inList);
}
}
else
{
inList.push(inNode);
}
} }
}; };
@ -417,41 +392,96 @@ var App = {
]) ])
} }
}, },
OldClassifier:()=>
{
let leafStructure = inTree=>
{
let output = [];
Node.IterateDown(inTree.Root, n=>
{
if(!n.Children)
{
output[n.ID] = n;
}
});
return output;
};
let structTopics = leafStructure(App.State.Topics)
let structBible = leafStructure(App.State.Bible);
let structDate = leafStructure(App.State.Date);
////
var matched, match;
// match topics
matched = false;
topics.forEach(t=>
{
match = structTopics[t];
if(match)
{
match.Leaves.push(output);
matched = true;
}
});
if(!matched)
{
structTopics[""].Leaves.push(output);
}
// match bible
matched = false;
bible.forEach(t=>
{
match = structBible[ Util.ParsePassage(t)[0] ];
if(match)
{
match.Leaves.push(output);
matched = true;
}
});
if(!matched)
{
structBible[""].Leaves.push(output);
}
// match date
matched = false;
match = structDate[date[2]];
if(match)
{
match.Leaves.push(output);
matched = true;
}
if(!matched)
{
structDate[""].Leaves.push(output);
}
////
let itrUp = inLeaf=>
{
Node.IterateUp(inLeaf, inBranch=>
{
inBranch.Leaves = _.union(inBranch.Leaves, inLeaf.Leaves)
});
};
Object.values(structTopics).forEach(itrUp);
Object.values(structBible).forEach(itrUp);
Object.values(structDate).forEach(itrUp);
},
Update: Update:
{ {
Load:(file)=> Load:(file)=>
{ {
let leafStructure = inTree=>
{
let output = [];
Node.IterateDown(inTree.Root, n=>
{
if(!n.Children)
{
output[n.ID] = n;
}
});
return output;
};
let structTopics = leafStructure(App.State.Topics)
let structBible = leafStructure(App.State.Bible);
let structDate = leafStructure(App.State.Date);
fetch(file) fetch(file)
.then(inAccept=>inAccept.text()) .then(inAccept=>inAccept.text())
.then(inAccept=> .then(inAccept=>
{ {
let itrUp = inLeaf=>
{
Node.IterateUp(inLeaf, inBranch=>
{
inBranch.Leaves = _.union(inBranch.Leaves, inLeaf.Leaves)
});
};
let columns = inAccept.split("|"); let columns = inAccept.split("|");
for(let i=0; i<columns.length; i+=5) for(let i=0; i<columns.length; i+=5)
{ {
let title = columns[i+0]; let title = columns[i+0];
@ -462,60 +492,8 @@ var App = {
let output = { title, id, date, topics, bible }; let output = { title, id, date, topics, bible };
var matched, match;
// match topics
matched = false;
topics.forEach(t=>
{
match = structTopics[t];
if(match)
{
match.Leaves.push(output);
matched = true;
}
});
if(!matched)
{
structTopics[""].Leaves.push(output);
}
// match bible
matched = false;
bible.forEach(t=>
{
match = structBible[ Util.ParsePassage(t)[0] ];
if(match)
{
match.Leaves.push(output);
matched = true;
}
});
if(!matched)
{
structBible[""].Leaves.push(output);
}
// match date
matched = false;
match = structDate[date[2]];
if(match)
{
match.Leaves.push(output);
matched = true;
}
if(!matched)
{
structDate[""].Leaves.push(output);
}
App.State.Items.All.push(output); App.State.Items.All.push(output);
} }
Object.values(structTopics).forEach(itrUp);
Object.values(structBible).forEach(itrUp);
Object.values(structDate).forEach(itrUp);
}) })
.then(inAccept=> .then(inAccept=>
{ {