Add db query filtering again with promise setup and benchmarking.

This commit is contained in:
kor 2018-11-06 13:05:29 +13:00
parent 2f8809cafb
commit 36e2dca38c
3 changed files with 151 additions and 135 deletions

View File

@ -56,7 +56,29 @@ function Main()
this.database.start(new Indental(DATABASE).parse())
.then((db) => {
this.timediff('process db');
return this.grid.buildAllArticles(db);
let target = window.document.location.hash;
lightbox.close();
document.activeElement.blur();
if (this.queryCur !== 'add')
{
this.queryPrev = this.queryCur;
}
target = target.substr(0,1) === "#" ? target.substr(1,target.length-1) : target;
this.queryCur = target.trim();
if (window.location.hash != this.queryCur)
{
window.location.hash = this.queryCur;
}
this.timediff('prep query \'' + this.queryCur + '\'');
return this.database.filter(db, this.queryCur);
})
.then((filtered) => {
this.timediff('filter db');
return this.grid.buildAllArticles(filtered);
})
.then((html) => {
this.timediff('build html');
@ -71,40 +93,39 @@ function Main()
// this.nav.display(this.db.stats());
}
this.load = function(target)
{
lightbox.close();
// this.load = function(target)
// {
// lightbox.close();
// document.activeElement.blur();
// if (this.queryCur !== 'add')
// {
// this.queryPrev = this.queryCur;
// }
document.activeElement.blur();
if (this.queryCur !== 'add')
{
this.queryPrev = this.queryCur;
}
// target = target.substr(0,1) === "#" ? target.substr(1,target.length-1) : target;
// this.queryCur = target.trim();
target = target.substr(0,1) === "#" ? target.substr(1,target.length-1) : target;
this.queryCur = target.trim();
// if (window.location.hash != this.queryCur)
// {
// window.location.hash = this.queryCur;
// }
if (window.location.hash != this.queryCur)
{
window.location.hash = this.queryCur;
}
if (this.queryCur === 'add')
{
if (window.showAdd != undefined && window.showAdd)
{
this.add.show();
}
else
{
window.location.hash = this.queryPrev;
}
}
else
{
this.grid.display(this.db.filter(this.queryCur));
}
}
// if (this.queryCur === 'add')
// {
// if (window.showAdd != undefined && window.showAdd)
// {
// this.add.show();
// }
// else
// {
// window.location.hash = this.queryPrev;
// }
// }
// else
// {
// this.grid.display(this.db.filter(this.queryCur));
// }
// }
}
window.addEventListener("hashchange", function() { main.load(window.document.location.hash); });
// window.addEventListener("hashchange", function() { main.load(window.document.location.hash); });

View File

@ -24,16 +24,6 @@ function Grid()
}
}
this.formatArticle = function(entry)
{
return '<div>test</div>';
}
this.addHtmlToPage = function()
{
this.container.innerHTML += contentHtml;
}
this.display = function(db)
{
if (window.showAdd !== undefined && window.showAdd)

View File

@ -61,129 +61,134 @@ function Wrap()
});
}
this.filter = function(target)
this.filter = function(db, target)
{
var tempDatabase = {};
let tempDatabase = {};
if (target == '')
{
tempDatabase = this.database;
}
else if (target == 'term')
{
for (let i = 0; i < this.keys.length; i++)
{
let value = this.database[this.keys[i]];
if (typeof value.TERM !== 'undefined')
{
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
}
}
tempDatabase = db;
}
else
{
var splitTarget = target.split("-");
if (splitTarget[0] == 'tag')
let keys = Object.keys(db);
if (target == 'term')
{
// TAG
let tagRequest = decodeURI(splitTarget[1]);
for (let i = 0; i < this.keys.length; i++)
for (let i = 0; i < keys.length; i++)
{
let value = this.database[this.keys[i]];
if (typeof value.TAGS !== 'undefined')
let value = db[keys[i]];
if (typeof value.TERM !== 'undefined')
{
for (let t = 0; t < value.TAGS.length; t++)
{
if (value.TAGS[t] == tagRequest)
{
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
}
}
tempDatabase[keys[i]] = db[keys[i]];
}
}
}
if (splitTarget[0] == 'proj')
else
{
// PROJECT
let projectRequest = decodeURI(splitTarget[1]);
for (let i = 0; i < this.keys.length; i++)
{
let value = this.database[this.keys[i]];
if (typeof value.PROJ !== 'undefined')
var splitTarget = target.split("-");
if (splitTarget[0] == 'tag')
{
// TAG
let tagRequest = decodeURI(splitTarget[1]);
for (let i = 0; i < keys.length; i++)
{
for (let p = 0; p < value.PROJ.length; p++)
let value = db[keys[i]];
if (typeof value.TAGS !== 'undefined')
{
if (value.PROJ[p] == projectRequest)
for (let t = 0; t < value.TAGS.length; t++)
{
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
}
}
}
}
}
else if (splitTarget[0] == 'type')
{
// TYPE
let typeRequest = decodeURI(splitTarget[1]);
for (let i = 0; i < this.keys.length; i++)
{
let value = this.database[this.keys[i]];
if (typeof value.TYPE !== 'undefined')
{
if (typeof value.TYPE == 'object')
{
// This entry has multiple types
for (let t = 0; t < value.TYPE.length; t++)
{
if (value.TYPE[t] == typeRequest)
if (value.TAGS[t] == tagRequest)
{
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
tempDatabase[keys[i]] = db[keys[i]];
}
}
}
}
}
if (splitTarget[0] == 'proj')
{
// PROJECT
let projectRequest = decodeURI(splitTarget[1]);
for (let i = 0; i < keys.length; i++)
{
let value = db[keys[i]];
if (typeof value.PROJ !== 'undefined')
{
for (let p = 0; p < value.PROJ.length; p++)
{
if (value.PROJ[p] == projectRequest)
{
tempDatabase[keys[i]] = db[keys[i]];
}
}
}
}
}
else if (splitTarget[0] == 'type')
{
// TYPE
let typeRequest = decodeURI(splitTarget[1]);
for (let i = 0; i < keys.length; i++)
{
let value = db[keys[i]];
if (typeof value.TYPE !== 'undefined')
{
if (typeof value.TYPE == 'object')
{
// This entry has multiple types
for (let t = 0; t < value.TYPE.length; t++)
{
if (value.TYPE[t] == typeRequest)
{
tempDatabase[keys[i]] = db[keys[i]];
}
}
}
else
{
// This entry has a single type
if (value.TYPE == typeRequest)
{
tempDatabase[keys[i]] = db[keys[i]];
}
}
}
}
}
else if (splitTarget[0] == 'done')
{
// DONE
let doneValue = decodeURI(splitTarget[1]);
for (let i = 0; i < keys.length; i++)
{
let value = db[keys[i]];
if (doneValue == 'true')
{
// true
if (typeof value.DONE !== 'undefined')
{
if (value.DONE == 'true')
{
tempDatabase[keys[i]] = db[keys[i]];
}
}
}
else
{
// This entry has a single type
if (value.TYPE == typeRequest)
// false
if (typeof value.DONE === 'undefined')
{
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
tempDatabase[keys[i]] = db[keys[i]];
}
}
}
}
}
else if (splitTarget[0] == 'done')
{
// DONE
let doneValue = decodeURI(splitTarget[1]);
for (let i = 0; i < this.keys.length; i++)
{
let value = this.database[this.keys[i]];
if (doneValue == 'true')
{
// true
if (typeof value.DONE !== 'undefined')
{
if (value.DONE == 'true')
else if (value.DONE == false)
{
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
tempDatabase[keys[i]] = db[keys[i]];
}
}
}
else
{
// false
if (typeof value.DONE === 'undefined')
{
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
}
else if (value.DONE == false)
{
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
}
}
}
}
}
return tempDatabase;
}