memex/docs/logic/main.js

139 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-07-13 15:56:09 +00:00
function Main()
{
this.util = null;
this.database = null;
this.grid = null;
this.nav = null;
this.add = null;
this.write = null;
2018-10-30 14:05:23 +00:00
2018-07-23 13:20:03 +00:00
this.queryCur = '';
2018-09-14 02:57:15 +00:00
this.queryPrev = '';
this.queryPrevAdd = '';
2018-10-30 14:05:23 +00:00
2018-11-05 23:39:57 +00:00
this.timeBegin = Date.now();
2018-11-05 23:29:55 +00:00
this.timeStore = Date.now();
this.curTime = null;
var parent = this;
2018-07-13 15:56:09 +00:00
2018-07-15 14:23:07 +00:00
this.install = function()
{
this.util = new Util();
this.database = new Wrap();
2018-11-06 09:28:12 +00:00
this.database.install(DATABASE);
this.grid = new Grid();
this.grid.install(
document.querySelector('main'),
document.querySelector('.page-overlay'),
'main',
'article');
this.nav = new Nav();
this.nav.install(document.querySelector('nav'));
2018-07-24 11:50:04 +00:00
2018-10-30 03:01:22 +00:00
if (window.showAdd !== undefined && window.showAdd)
2018-07-24 11:50:04 +00:00
{
this.add = new Add();
this.add.install();
2018-09-14 02:57:15 +00:00
// var escape = document.getElementById("escape");
// escape.onclick = function()
// {
// main.add.close();
// }
2018-07-24 11:50:04 +00:00
}
2018-07-15 14:23:07 +00:00
}
2018-11-05 23:29:55 +00:00
this.timediff = function(label)
2018-11-05 23:39:57 +00:00
{
this.curTime = Date.now();
console.log((this.curTime - this.timeStore) + ' ms to ' + label);
this.timeStore = this.curTime;
}
2018-11-05 23:29:55 +00:00
2018-11-06 09:28:12 +00:00
this.resetPage = function()
{
lightbox.close();
document.activeElement.blur();
}
this.updateQuery = function()
{
let target = window.document.location.hash;
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;
}
}
2018-07-15 14:23:07 +00:00
this.start = function()
{
2018-11-05 23:39:57 +00:00
this.timediff('load all js files');
2018-11-06 09:28:12 +00:00
this.database.start()
2018-11-05 23:29:55 +00:00
.then((db) => {
this.timediff('process db');
2018-11-06 09:28:12 +00:00
this.resetPage();
this.updateQuery();
this.timediff('prep query \'' + this.queryCur + '\'');
return this.database.filter(db, this.queryCur);
})
.then((filtered) => {
this.timediff('filter db');
return this.grid.buildAllArticles(filtered);
2018-11-05 23:29:55 +00:00
})
.then((html) => {
this.timediff('build html');
document.querySelector('main').innerHTML = html;
this.timediff('render html');
2018-11-05 23:39:57 +00:00
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());
2018-07-15 14:23:07 +00:00
}
// this.load = function(target)
// {
// lightbox.close();
// document.activeElement.blur();
// if (this.queryCur !== 'add')
// {
// this.queryPrev = this.queryCur;
// }
2018-10-30 03:01:22 +00:00
// target = target.substr(0,1) === "#" ? target.substr(1,target.length-1) : target;
// this.queryCur = target.trim();
2018-07-23 13:20:03 +00:00
// if (window.location.hash != this.queryCur)
// {
// window.location.hash = this.queryCur;
// }
2018-07-23 13:20:03 +00:00
// 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));
// }
// }
2018-07-13 15:56:09 +00:00
}
// window.addEventListener("hashchange", function() { main.load(window.document.location.hash); });