2018-07-21 14:35:55 +00:00
|
|
|
function Wrap()
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
|
|
|
this.database = null;
|
|
|
|
this.keys = null;
|
|
|
|
|
2018-08-08 15:49:00 +00:00
|
|
|
this.install = function(data)
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
2018-08-08 15:49:00 +00:00
|
|
|
this.database = new Indental(data).parse();
|
2018-07-17 13:08:20 +00:00
|
|
|
this.keys = Object.keys(this.database);
|
|
|
|
}
|
|
|
|
|
2018-11-06 09:28:12 +00:00
|
|
|
this.start = function()
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
2018-11-06 11:45:52 +00:00
|
|
|
let keys = Object.keys(this.database);
|
|
|
|
for (let i = 0; i < keys.length; i++)
|
2018-10-30 03:01:22 +00:00
|
|
|
{
|
2018-11-06 11:45:52 +00:00
|
|
|
let entry = this.database[keys[i]];
|
2018-11-05 15:00:16 +00:00
|
|
|
|
2018-11-06 11:45:52 +00:00
|
|
|
entry.AUTH = commaSplit(entry.AUTH);
|
|
|
|
entry.TAGS = commaSplit(entry.TAGS);
|
|
|
|
entry.TYPE = commaSplit(entry.TYPE);
|
|
|
|
entry.PROJ = commaSplit(entry.PROJ);
|
2018-11-05 15:00:16 +00:00
|
|
|
|
2018-11-06 11:45:52 +00:00
|
|
|
entry.LINK = objectSplit(entry.LINK);
|
|
|
|
entry.FILE = objectSplit(entry.FILE);
|
2018-11-05 15:00:16 +00:00
|
|
|
|
2018-11-06 11:45:52 +00:00
|
|
|
this.database[keys[i]].DIID = i;
|
|
|
|
}
|
2018-07-17 13:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 11:45:52 +00:00
|
|
|
this.filter = function(target, data)
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
2018-11-06 11:45:52 +00:00
|
|
|
let db = this.database;//data == undefined ? this.database : data;
|
2018-11-06 00:05:29 +00:00
|
|
|
let tempDatabase = {};
|
2018-07-22 19:45:04 +00:00
|
|
|
if (target == '')
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
tempDatabase = db;
|
2018-07-17 13:08:20 +00:00
|
|
|
}
|
2018-11-06 00:05:29 +00:00
|
|
|
else
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
let keys = Object.keys(db);
|
|
|
|
if (target == 'term')
|
2018-10-30 03:01:22 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
for (let i = 0; i < keys.length; i++)
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
let value = db[keys[i]];
|
|
|
|
if (typeof value.TERM !== 'undefined')
|
|
|
|
{
|
|
|
|
tempDatabase[keys[i]] = db[keys[i]];
|
|
|
|
}
|
2018-07-17 13:08:20 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-06 00:05:29 +00:00
|
|
|
else
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
var splitTarget = target.split("-");
|
|
|
|
if (splitTarget[0] == 'tag')
|
2018-10-30 03:01:22 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
// TAG
|
|
|
|
let tagRequest = decodeURI(splitTarget[1]);
|
|
|
|
for (let i = 0; i < keys.length; i++)
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
let value = db[keys[i]];
|
|
|
|
if (typeof value.TAGS !== 'undefined')
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
for (let t = 0; t < value.TAGS.length; t++)
|
2018-10-29 13:45:34 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
if (value.TAGS[t] == tagRequest)
|
|
|
|
{
|
|
|
|
tempDatabase[keys[i]] = db[keys[i]];
|
|
|
|
}
|
2018-10-29 13:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-06 00:05:29 +00:00
|
|
|
if (splitTarget[0] == 'proj')
|
|
|
|
{
|
|
|
|
// PROJECT
|
|
|
|
let projectRequest = decodeURI(splitTarget[1]);
|
|
|
|
for (let i = 0; i < keys.length; i++)
|
|
|
|
{
|
|
|
|
let value = db[keys[i]];
|
|
|
|
if (typeof value.PROJ !== 'undefined')
|
2018-10-29 13:45:34 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
for (let p = 0; p < value.PROJ.length; p++)
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
if (value.PROJ[p] == projectRequest)
|
|
|
|
{
|
|
|
|
tempDatabase[keys[i]] = db[keys[i]];
|
|
|
|
}
|
2018-07-17 13:08:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-06 00:05:29 +00:00
|
|
|
else if (splitTarget[0] == 'type')
|
|
|
|
{
|
|
|
|
// TYPE
|
|
|
|
let typeRequest = decodeURI(splitTarget[1]);
|
|
|
|
for (let i = 0; i < keys.length; i++)
|
|
|
|
{
|
|
|
|
let value = db[keys[i]];
|
|
|
|
if (typeof value.TYPE !== 'undefined')
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
if (typeof value.TYPE == 'object')
|
2018-10-29 12:33:45 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
// This entry has multiple types
|
|
|
|
for (let t = 0; t < value.TYPE.length; t++)
|
2018-10-29 12:33:45 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
if (value.TYPE[t] == typeRequest)
|
|
|
|
{
|
|
|
|
tempDatabase[keys[i]] = db[keys[i]];
|
|
|
|
}
|
2018-10-29 12:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-06 00:05:29 +00:00
|
|
|
else
|
2018-10-29 12:33:45 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
// This entry has a single type
|
|
|
|
if (value.TYPE == typeRequest)
|
|
|
|
{
|
|
|
|
tempDatabase[keys[i]] = db[keys[i]];
|
|
|
|
}
|
2018-10-29 12:33:45 +00:00
|
|
|
}
|
2018-07-17 13:08:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-06 00:05:29 +00:00
|
|
|
else if (splitTarget[0] == 'done')
|
|
|
|
{
|
|
|
|
// DONE
|
|
|
|
let doneValue = decodeURI(splitTarget[1]);
|
|
|
|
for (let i = 0; i < keys.length; i++)
|
|
|
|
{
|
|
|
|
let value = db[keys[i]];
|
|
|
|
if (doneValue == 'true')
|
2018-08-13 16:30:09 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
// true
|
|
|
|
if (typeof value.DONE !== 'undefined')
|
2018-08-13 16:30:09 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
if (value.DONE == 'true')
|
|
|
|
{
|
|
|
|
tempDatabase[keys[i]] = db[keys[i]];
|
|
|
|
}
|
2018-08-13 16:30:09 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-06 00:05:29 +00:00
|
|
|
else
|
2018-08-13 16:30:09 +00:00
|
|
|
{
|
2018-11-06 00:05:29 +00:00
|
|
|
// false
|
|
|
|
if (typeof value.DONE === 'undefined')
|
|
|
|
{
|
|
|
|
tempDatabase[keys[i]] = db[keys[i]];
|
|
|
|
}
|
|
|
|
else if (value.DONE == false)
|
|
|
|
{
|
|
|
|
tempDatabase[keys[i]] = db[keys[i]];
|
|
|
|
}
|
2018-08-13 16:30:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-17 13:08:20 +00:00
|
|
|
}
|
|
|
|
return tempDatabase;
|
|
|
|
}
|
|
|
|
|
2018-11-06 11:45:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-07-22 19:45:04 +00:00
|
|
|
this.stats = function(db = this.database)
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
|
|
|
// CALCULATE
|
|
|
|
let dbKeys = Object.keys(db);
|
|
|
|
var stats =
|
|
|
|
{
|
|
|
|
total: this.keys.length,
|
|
|
|
types: {},
|
|
|
|
tags: {},
|
|
|
|
terms: 0,
|
2018-08-13 16:30:09 +00:00
|
|
|
done: 0
|
2018-07-17 13:08:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < dbKeys.length; i++)
|
|
|
|
{
|
|
|
|
// TYPE
|
|
|
|
if (typeof db[dbKeys[i]].TYPE !== 'undefined')
|
|
|
|
{
|
|
|
|
if (typeof stats.types[db[dbKeys[i]].TYPE] !== 'undefined')
|
|
|
|
{
|
|
|
|
stats.types[db[dbKeys[i]].TYPE] ++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stats.types[db[dbKeys[i]].TYPE] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TAGS
|
|
|
|
if (typeof db[dbKeys[i]].TAGS !== 'undefined')
|
|
|
|
{
|
|
|
|
for (var t = 0; t < db[dbKeys[i]].TAGS.length; t++)
|
|
|
|
{
|
|
|
|
if (typeof stats.tags[db[dbKeys[i]].TAGS[t]] !== 'undefined')
|
|
|
|
{
|
|
|
|
stats.tags[db[dbKeys[i]].TAGS[t]] ++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stats.tags[db[dbKeys[i]].TAGS[t]] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TERM
|
|
|
|
if (typeof db[dbKeys[i]].TERM !== 'undefined')
|
|
|
|
{
|
2018-08-12 14:48:17 +00:00
|
|
|
let count = 0;
|
|
|
|
for (var t = 0; t < db[dbKeys[i]].TERM.length; t++)
|
|
|
|
{
|
|
|
|
if (db[dbKeys[i]].TERM[t].substr(0,2) == '> ')
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stats.terms += count;
|
2018-07-17 13:08:20 +00:00
|
|
|
}
|
2018-08-13 16:30:09 +00:00
|
|
|
|
|
|
|
// DONE
|
|
|
|
if (typeof db[dbKeys[i]].DONE !== 'undefined')
|
|
|
|
{
|
|
|
|
if (db[dbKeys[i]].DONE == 'true')
|
|
|
|
{
|
|
|
|
stats.done ++;
|
|
|
|
}
|
|
|
|
}
|
2018-07-17 14:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SORT TYPES, TAKE TOP X
|
|
|
|
// Create items array
|
|
|
|
var typeItems = Object.keys(stats.types).map(function(key)
|
|
|
|
{
|
|
|
|
return [key, stats.types[key]];
|
|
|
|
});
|
|
|
|
// Sort the array based on the second element
|
|
|
|
typeItems.sort(function(first, second)
|
|
|
|
{
|
|
|
|
return second[1] - first[1];
|
|
|
|
});
|
|
|
|
stats.types = typeItems;
|
|
|
|
|
2018-07-17 13:08:20 +00:00
|
|
|
// SORT TAGS, TAKE TOP X
|
|
|
|
// Create items array
|
2018-07-17 14:09:23 +00:00
|
|
|
var tagItems = Object.keys(stats.tags).map(function(key)
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
|
|
|
return [key, stats.tags[key]];
|
|
|
|
});
|
|
|
|
// Sort the array based on the second element
|
2018-07-17 14:09:23 +00:00
|
|
|
tagItems.sort(function(first, second)
|
2018-07-17 13:08:20 +00:00
|
|
|
{
|
|
|
|
return second[1] - first[1];
|
|
|
|
});
|
2018-07-17 14:09:23 +00:00
|
|
|
stats.tags = tagItems;
|
2018-07-17 13:08:20 +00:00
|
|
|
|
|
|
|
return stats;
|
|
|
|
}
|
|
|
|
}
|