diff --git a/docs/index.html b/docs/index.html index 11e77a9..ed53b3c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -20,7 +20,7 @@
diff --git a/docs/logic/main.js b/docs/logic/main.js index 9215114..ea07dee 100644 --- a/docs/logic/main.js +++ b/docs/logic/main.js @@ -1,7 +1,8 @@ function Main() { this.util = null; - this.database = null; + this.wrap = null; + this.articles = null; this.grid = null; this.nav = null; this.add = null; @@ -17,8 +18,7 @@ function Main() seer.note('load all js files'); this.util = new Util(); - this.database = new Wrap(); - this.database.install(DATABASE); + this.wrap = new Wrap(); this.grid = new Grid(); this.grid.install( document.querySelector('main'), @@ -42,6 +42,49 @@ function Main() seer.note('install main'); } + this.start = function() + { + this.wrap.start(DATABASE) + .then((db) => + { + this.articles = db; + seer.note('process db'); + + let stats = this.wrap.stats(this.articles); + seer.note('calc stats'); + this.nav.display(stats); + seer.note('render stats'); + + return this.load(); + }) + .catch((error) => + { + console.log('ERROR: ' + error, error); + }); + } + + this.load = function() + { + this.resetPage(); + this.updateQuery(); + + let filtered = this.wrap.filter(this.queryCur, this.articles); + seer.note('filter db'); + + this.grid.buildAllArticles(filtered) + .then((html) => + { + seer.note('build html'); + + this.grid.newDisplay(html); + document.querySelector('.loading-wave').style.display = 'none'; + return seer.report(); + }).catch((error) => + { + console.log('ERROR: ' + error, error); + }); + } + this.resetPage = function() { lightbox.close(); @@ -62,39 +105,6 @@ function Main() window.location.hash = this.queryCur; } } - - this.start = function() - { - this.database.start(); - seer.note('process db'); - this.load(); - } - - this.load = function() - { - this.resetPage(); - this.updateQuery(); - seer.note('prep query'); - - let filtered = this.database.filter(this.queryCur); - seer.note('filter db'); - - this.grid.buildAllArticles(filtered) - .then((html) => - { - seer.note('build html'); - - let stats = this.database.stats(); - seer.note('calc stats'); - - this.nav.display(stats); - seer.note('render stats'); - - this.grid.newDisplay(html); - seer.report(); - }); - document.querySelector('.loading-wave').style.display = 'none'; - } } window.addEventListener("hashchange", function() { main.load(); }); \ No newline at end of file diff --git a/docs/logic/wrap.js b/docs/logic/wrap.js index ef434ec..9f3ad99 100644 --- a/docs/logic/wrap.js +++ b/docs/logic/wrap.js @@ -1,36 +1,61 @@ function Wrap() { - this.database = null; - this.keys = null; - - this.install = function(data) + this.start = function(data) { - this.database = new Indental(data).parse(); - this.keys = Object.keys(this.database); - } - - this.start = function() - { - let keys = Object.keys(this.database); - for (let i = 0; i < keys.length; i++) + return new Promise(function(resolve, reject) { - let entry = this.database[keys[i]]; + this.commaSplit = function(data) + { + if (data !== undefined) + { + var result = data.split(","); + for (var c = 0; c < result.length; c++) + { + result[c] = result[c].trim().toLowerCase(); + } + return result; + } + return data; + } - entry.AUTH = commaSplit(entry.AUTH); - entry.TAGS = commaSplit(entry.TAGS); - entry.TYPE = commaSplit(entry.TYPE); - entry.PROJ = commaSplit(entry.PROJ); + this.objectSplit = function(data) + { + if (typeof data == 'object') + { + for (let o = 0; o < data.length; o++) + { + if (data[o].substr(0,2) == '> ') + { + data[o] = data[o].substr(2,data[o].length-1); + } + } + } + return data; + } - entry.LINK = objectSplit(entry.LINK); - entry.FILE = objectSplit(entry.FILE); + let database = new Indental(data).parse(); + let keys = Object.keys(database); + for (let i = 0; i < keys.length; i++) + { + let entry = database[keys[i]]; - this.database[keys[i]].DIID = 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); + + entry.LINK = this.objectSplit(entry.LINK); + entry.FILE = this.objectSplit(entry.FILE); + + database[keys[i]].DIID = i; + } + + resolve(database); + }); } - this.filter = function(target, data) + this.filter = function(target, db) { - let db = this.database;//data == undefined ? this.database : data; let tempDatabase = {}; if (target == '') { @@ -159,42 +184,13 @@ function Wrap() return tempDatabase; } - let commaSplit = function(data) - { - if (data !== undefined) - { - var result = data.split(","); - for (var c = 0; c < result.length; c++) - { - result[c] = result[c].trim().toLowerCase(); - } - return result; - } - return data; - } - - let objectSplit = function(data) - { - if (typeof data == 'object') - { - for (let o = 0; o < data.length; o++) - { - if (data[o].substr(0,2) == '> ') - { - data[o] = data[o].substr(2,data[o].length-1); - } - } - } - return data; - } - - this.stats = function(db = this.database) + this.stats = function(db) { // CALCULATE let dbKeys = Object.keys(db); var stats = { - total: this.keys.length, + total: dbKeys.length, types: {}, tags: {}, terms: 0,