mirror of
https://github.com/TangentFoxy/memex.git
synced 2024-11-22 04:54:23 +00:00
Add db query filtering again with promise setup and benchmarking.
This commit is contained in:
parent
2f8809cafb
commit
36e2dca38c
@ -56,25 +56,9 @@ function Main()
|
||||
this.database.start(new Indental(DATABASE).parse())
|
||||
.then((db) => {
|
||||
this.timediff('process db');
|
||||
return this.grid.buildAllArticles(db);
|
||||
})
|
||||
.then((html) => {
|
||||
this.timediff('build html');
|
||||
document.querySelector('main').innerHTML = html;
|
||||
this.timediff('render html');
|
||||
console.log('TOTAL: ' + (Date.now() - this.timeBegin) + ' ms');
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('ERROR:', error);
|
||||
})
|
||||
// this.load(window.document.location.hash);
|
||||
// this.nav.display(this.db.stats());
|
||||
}
|
||||
let target = window.document.location.hash;
|
||||
|
||||
this.load = function(target)
|
||||
{
|
||||
lightbox.close();
|
||||
|
||||
document.activeElement.blur();
|
||||
if (this.queryCur !== 'add')
|
||||
{
|
||||
@ -89,22 +73,59 @@ function Main()
|
||||
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));
|
||||
}
|
||||
}
|
||||
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');
|
||||
document.querySelector('main').innerHTML = html;
|
||||
this.timediff('render html');
|
||||
console.log('TOTAL: ' + (Date.now() - this.timeBegin) + ' ms');
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('ERROR:', error);
|
||||
})
|
||||
// this.load(window.document.location.hash);
|
||||
// this.nav.display(this.db.stats());
|
||||
}
|
||||
|
||||
window.addEventListener("hashchange", function() { main.load(window.document.location.hash); });
|
||||
// this.load = function(target)
|
||||
// {
|
||||
// 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;
|
||||
// }
|
||||
|
||||
// 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); });
|
@ -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)
|
||||
|
@ -61,21 +61,24 @@ function Wrap()
|
||||
});
|
||||
}
|
||||
|
||||
this.filter = function(target)
|
||||
this.filter = function(db, target)
|
||||
{
|
||||
var tempDatabase = {};
|
||||
let tempDatabase = {};
|
||||
if (target == '')
|
||||
{
|
||||
tempDatabase = this.database;
|
||||
tempDatabase = db;
|
||||
}
|
||||
else if (target == 'term')
|
||||
else
|
||||
{
|
||||
for (let i = 0; i < this.keys.length; i++)
|
||||
let keys = Object.keys(db);
|
||||
if (target == 'term')
|
||||
{
|
||||
let value = this.database[this.keys[i]];
|
||||
for (let i = 0; i < keys.length; i++)
|
||||
{
|
||||
let value = db[keys[i]];
|
||||
if (typeof value.TERM !== 'undefined')
|
||||
{
|
||||
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
|
||||
tempDatabase[keys[i]] = db[keys[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -86,16 +89,16 @@ function Wrap()
|
||||
{
|
||||
// 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]];
|
||||
let value = db[keys[i]];
|
||||
if (typeof value.TAGS !== '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]];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -105,16 +108,16 @@ function Wrap()
|
||||
{
|
||||
// PROJECT
|
||||
let projectRequest = 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]];
|
||||
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[this.keys[i]] = this.database[this.keys[i]];
|
||||
tempDatabase[keys[i]] = db[keys[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,9 +127,9 @@ function Wrap()
|
||||
{
|
||||
// TYPE
|
||||
let typeRequest = 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]];
|
||||
let value = db[keys[i]];
|
||||
if (typeof value.TYPE !== 'undefined')
|
||||
{
|
||||
if (typeof value.TYPE == 'object')
|
||||
@ -136,7 +139,7 @@ function Wrap()
|
||||
{
|
||||
if (value.TYPE[t] == typeRequest)
|
||||
{
|
||||
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
|
||||
tempDatabase[keys[i]] = db[keys[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -145,7 +148,7 @@ function Wrap()
|
||||
// This entry has a single type
|
||||
if (value.TYPE == typeRequest)
|
||||
{
|
||||
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
|
||||
tempDatabase[keys[i]] = db[keys[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -155,9 +158,9 @@ function Wrap()
|
||||
{
|
||||
// DONE
|
||||
let doneValue = 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]];
|
||||
let value = db[keys[i]];
|
||||
if (doneValue == 'true')
|
||||
{
|
||||
// true
|
||||
@ -165,7 +168,7 @@ function Wrap()
|
||||
{
|
||||
if (value.DONE == 'true')
|
||||
{
|
||||
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
|
||||
tempDatabase[keys[i]] = db[keys[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,16 +177,18 @@ function Wrap()
|
||||
// false
|
||||
if (typeof value.DONE === 'undefined')
|
||||
{
|
||||
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
|
||||
tempDatabase[keys[i]] = db[keys[i]];
|
||||
}
|
||||
else if (value.DONE == false)
|
||||
{
|
||||
tempDatabase[this.keys[i]] = this.database[this.keys[i]];
|
||||
tempDatabase[keys[i]] = db[keys[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tempDatabase;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user