diff --git a/admin/admin.js b/admin/admin.js index 4bf6292..72534e5 100644 --- a/admin/admin.js +++ b/admin/admin.js @@ -48,6 +48,10 @@ module.exports= { page = "./users.js"; } + else if(filename.includes("/analytics")) + { + page = "./analytics.js" + } require(page).main(postData, templateContext).then(function(template) { @@ -61,7 +65,7 @@ module.exports= } else { - require("./login/login.js").main(request, clientAddress, templateContext) + require("./login.js").main(request, clientAddress, templateContext) .then(function() { resolve(); diff --git a/admin/analytics.js b/admin/analytics.js new file mode 100644 index 0000000..3877d51 --- /dev/null +++ b/admin/analytics.js @@ -0,0 +1,71 @@ + +/** Whiskers template file */ +const TEMPLATE_FILE = "admin/analytics.html"; + + +const includes = require('../includes/includes.js'); + +//updates db +const sql = require('../utils/sql'); + + +const generateData = function(templateContext) +{ + return new Promise(function(resolve, reject) + { + var data = []; + + sql.getTraffic().then(function(traffic) + { + var start = traffic[0].date; + var currentMonth = new Date(start.getUTCFullYear(), start.getMonth(), 1, 0,0,0); + templateContext.start = JSON.stringify(currentMonth); + var monthCount = 0; + for(var i = 0; i < traffic.length; i++) + { + var currentDate = traffic[i].date; + + if(currentMonth.getMonth() != currentDate.getMonth()) + { + var foo = new Object(); + foo.x = currentMonth; + foo.y = monthCount; + data.push(foo); + monthCount = 0; + currentMonth = new Date(currentDate.getUTCFullYear(), currentDate.getMonth(), 1, 0,0,0); + } + monthCount = monthCount + 1; + } + templateContext.finish = JSON.stringify(currentMonth); + templateContext.dataset = JSON.stringify(data); + resolve(); + }); + }); +}; + + +module.exports= + { + /** + * Fetches context information for the admin blog page and handles post + * data sent regarding editing blog. + * + * @param postData posted by user + * @param templateContext json object used as the template context + * @returns {Promise} renders the template used for this page + */ + main: function(postData, templateContext) + { + return new Promise(function(resolve, reject) + { + Promise.all([includes.fetchTemplate(TEMPLATE_FILE), generateData(templateContext)]).then(function(template) + { + resolve(template[0]); + }).catch(function(error) + { + console.log("error in add admin blog.js"); + reject(error); + }); + }); + } + }; \ No newline at end of file diff --git a/admin/analytics/analytics.js b/admin/analytics/analytics.js deleted file mode 100644 index d52eaf3..0000000 --- a/admin/analytics/analytics.js +++ /dev/null @@ -1,24 +0,0 @@ - - - -module.exports= - { - main: function(postData) - { - return new Promise(function(resolve, reject) - { - Promise.all([utils.include("./admin/addCategory.html"), - printCategories(), - processPost(postData)]).then(function(html) - { - resolve("
" + - html.join('') + - "
"); - }).catch(function(error) - { - console.log("error in addCategory.js"); - reject(error); - }) - }); - } - }; \ No newline at end of file diff --git a/admin/login/login.js b/admin/login.js similarity index 97% rename from admin/login/login.js rename to admin/login.js index 220f369..ea752a2 100644 --- a/admin/login/login.js +++ b/admin/login.js @@ -1,8 +1,8 @@ //file io -const utils = require('../../utils/utils.js'); +const utils = require('../utils/utils.js'); //update db -const sql = require('../../utils/sql'); +const sql = require('../utils/sql'); const qs = require('querystring'); diff --git a/includes/html/adminHeader.html b/includes/html/adminHeader.html index 6076443..37c79c9 100644 --- a/includes/html/adminHeader.html +++ b/includes/html/adminHeader.html @@ -41,7 +41,17 @@ - + + + + + + + + @@ -72,6 +82,9 @@ +