mirror of
https://github.com/TangentFoxy/memex.git
synced 2024-11-22 04:54:23 +00:00
Refactor to messy testing with promise setup.
This commit is contained in:
parent
6ccb4d19dc
commit
0806fcc658
@ -1,7 +1,7 @@
|
||||
function Main()
|
||||
{
|
||||
this.util = null;
|
||||
this.db = null;
|
||||
this.database = null;
|
||||
this.grid = null;
|
||||
this.nav = null;
|
||||
this.add = null;
|
||||
@ -16,8 +16,8 @@ function Main()
|
||||
this.install = function()
|
||||
{
|
||||
this.util = new Util();
|
||||
this.db = new Wrap();
|
||||
this.db.install(DATABASE);
|
||||
this.database = new Wrap();
|
||||
// this.database.install(DATABASE);
|
||||
this.grid = new Grid();
|
||||
this.grid.install(
|
||||
document.querySelector('main'),
|
||||
@ -41,8 +41,33 @@ function Main()
|
||||
|
||||
this.start = function()
|
||||
{
|
||||
this.load(window.document.location.hash);
|
||||
this.nav.display(this.db.stats());
|
||||
console.log(Date.now() + ' - start');
|
||||
let dbPromise = this.database.start(new Indental(DATABASE).parse());
|
||||
dbPromise.then((db) => {
|
||||
console.log(Date.now() + ' - db ready');
|
||||
// console.log(db);
|
||||
|
||||
let dbKeys = Object.keys(db);
|
||||
let i = 0;
|
||||
let contentHtml = '';
|
||||
while (i < dbKeys.length)
|
||||
{
|
||||
contentHtml += this.grid.buildArticle(db[dbKeys[i]], dbKeys[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
return contentHtml;
|
||||
})
|
||||
.then((html) => {
|
||||
console.log(Date.now() + ' - html ready');
|
||||
document.querySelector('main').innerHTML = html;
|
||||
console.log(Date.now() + ' - rendered!');
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('ERROR:', error);
|
||||
})
|
||||
// this.load(window.document.location.hash);
|
||||
// this.nav.display(this.db.stats());
|
||||
}
|
||||
|
||||
this.load = function(target)
|
||||
|
@ -24,6 +24,16 @@ 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)
|
||||
@ -37,7 +47,7 @@ function Grid()
|
||||
let contentHtml = '';
|
||||
while (i < dbKeys.length)
|
||||
{
|
||||
contentHtml += this.buildArticle(db, dbKeys[i]);
|
||||
contentHtml += this.buildArticle(db[dbKeys[i]], dbKeys[i]);
|
||||
i++;
|
||||
}
|
||||
this.container.innerHTML = contentHtml;
|
||||
@ -65,9 +75,9 @@ function Grid()
|
||||
}
|
||||
}
|
||||
|
||||
this.buildArticle = function(db, key)
|
||||
this.buildArticle = function(value, key)
|
||||
{
|
||||
let value = db[key];
|
||||
// let value = db[key];
|
||||
let itemClass = "article";
|
||||
if (SETTINGS.WIDEARTICLE)
|
||||
{
|
||||
|
@ -7,46 +7,58 @@ function Wrap()
|
||||
{
|
||||
this.database = new Indental(data).parse();
|
||||
this.keys = Object.keys(this.database);
|
||||
this.process();
|
||||
}
|
||||
|
||||
this.process = function()
|
||||
this.start = function(data)
|
||||
{
|
||||
for (let i = 0; i < this.keys.length; i++)
|
||||
return new Promise(function(resolve, reject)
|
||||
{
|
||||
let entry = this.database[this.keys[i]];
|
||||
|
||||
entry.AUTH = this.commaSplit(entry.AUTH);
|
||||
entry.TAGS = this.commaSplit(entry.TAGS);
|
||||
entry.TYPE = this.commaSplit(entry.TYPE);
|
||||
entry.PROJ = this.commaSplit(entry.PROJ);
|
||||
|
||||
// LINK
|
||||
if (typeof entry.LINK == 'object')
|
||||
let commaSplit = function(data)
|
||||
{
|
||||
for (let l = 0; l < entry.LINK.length; l++)
|
||||
if (data !== undefined)
|
||||
{
|
||||
if (entry.LINK[l].substr(0,2) == '> ')
|
||||
var result = data.split(",");
|
||||
for (var c = 0; c < result.length; c++)
|
||||
{
|
||||
entry.LINK[l] = entry.LINK[l].substr(2,entry.LINK[l].length-1);
|
||||
result[c] = result[c].trim().toLowerCase();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
// FILE
|
||||
if (typeof entry.FILE == 'object')
|
||||
let objectSplit = function(data)
|
||||
{
|
||||
for (let f = 0; f < entry.FILE.length; f++)
|
||||
if (typeof data == 'object')
|
||||
{
|
||||
if (entry.FILE[f].substr(0,2) == '> ')
|
||||
for (let o = 0; o < data.length; o++)
|
||||
{
|
||||
entry.FILE[f] = entry.FILE[f].substr(2,entry.FILE[f].length-1);
|
||||
if (data[o].substr(0,2) == '> ')
|
||||
{
|
||||
data[o] = data[o].substr(2,data[o].length-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
this.database[this.keys[i]].DIID = i;
|
||||
let keys = Object.keys(data);
|
||||
for (let i = 0; i < keys.length; i++)
|
||||
{
|
||||
let entry = data[keys[i]];
|
||||
|
||||
entry.AUTH = commaSplit(entry.AUTH);
|
||||
entry.TAGS = commaSplit(entry.TAGS);
|
||||
entry.TYPE = commaSplit(entry.TYPE);
|
||||
entry.PROJ = commaSplit(entry.PROJ);
|
||||
|
||||
entry.LINK = objectSplit(entry.LINK);
|
||||
entry.FILE = objectSplit(entry.FILE);
|
||||
|
||||
data[keys[i]].DIID = i;
|
||||
}
|
||||
resolve(data);
|
||||
});
|
||||
}
|
||||
|
||||
this.filter = function(target)
|
||||
|
Loading…
Reference in New Issue
Block a user