Refactor to messy testing with promise setup.

This commit is contained in:
kor 2018-11-06 04:00:16 +13:00
parent 6ccb4d19dc
commit 0806fcc658
3 changed files with 77 additions and 30 deletions

View File

@ -1,7 +1,7 @@
function Main() function Main()
{ {
this.util = null; this.util = null;
this.db = null; this.database = null;
this.grid = null; this.grid = null;
this.nav = null; this.nav = null;
this.add = null; this.add = null;
@ -16,8 +16,8 @@ function Main()
this.install = function() this.install = function()
{ {
this.util = new Util(); this.util = new Util();
this.db = new Wrap(); this.database = new Wrap();
this.db.install(DATABASE); // this.database.install(DATABASE);
this.grid = new Grid(); this.grid = new Grid();
this.grid.install( this.grid.install(
document.querySelector('main'), document.querySelector('main'),
@ -41,8 +41,33 @@ function Main()
this.start = function() this.start = function()
{ {
this.load(window.document.location.hash); console.log(Date.now() + ' - start');
this.nav.display(this.db.stats()); 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) this.load = function(target)

View File

@ -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) this.display = function(db)
{ {
if (window.showAdd !== undefined && window.showAdd) if (window.showAdd !== undefined && window.showAdd)
@ -37,7 +47,7 @@ function Grid()
let contentHtml = ''; let contentHtml = '';
while (i < dbKeys.length) while (i < dbKeys.length)
{ {
contentHtml += this.buildArticle(db, dbKeys[i]); contentHtml += this.buildArticle(db[dbKeys[i]], dbKeys[i]);
i++; i++;
} }
this.container.innerHTML = contentHtml; 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"; let itemClass = "article";
if (SETTINGS.WIDEARTICLE) if (SETTINGS.WIDEARTICLE)
{ {

View File

@ -7,46 +7,58 @@ function Wrap()
{ {
this.database = new Indental(data).parse(); this.database = new Indental(data).parse();
this.keys = Object.keys(this.database); 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]]; let commaSplit = function(data)
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')
{ {
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 let objectSplit = function(data)
if (typeof entry.FILE == 'object')
{ {
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) this.filter = function(target)