Browse Source

Merge pull request #48 from jrtechs/adminAnalytics

Traffic Log on Admin Page
pull/60/head
Jeffery Russell 6 years ago
committed by GitHub
parent
commit
1a34128cb7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 54565 additions and 29 deletions
  1. +5
    -1
      admin/admin.js
  2. +71
    -0
      admin/analytics.js
  3. +0
    -24
      admin/analytics/analytics.js
  4. +2
    -2
      admin/login.js
  5. +14
    -1
      includes/html/adminHeader.html
  6. BIN
      includes/js/vis/dist/img/network/acceptDeleteIcon.png
  7. BIN
      includes/js/vis/dist/img/network/addNodeIcon.png
  8. BIN
      includes/js/vis/dist/img/network/backIcon.png
  9. BIN
      includes/js/vis/dist/img/network/connectIcon.png
  10. BIN
      includes/js/vis/dist/img/network/cross.png
  11. BIN
      includes/js/vis/dist/img/network/cross2.png
  12. BIN
      includes/js/vis/dist/img/network/deleteIcon.png
  13. BIN
      includes/js/vis/dist/img/network/downArrow.png
  14. BIN
      includes/js/vis/dist/img/network/editIcon.png
  15. BIN
      includes/js/vis/dist/img/network/leftArrow.png
  16. BIN
      includes/js/vis/dist/img/network/minus.png
  17. BIN
      includes/js/vis/dist/img/network/plus.png
  18. BIN
      includes/js/vis/dist/img/network/rightArrow.png
  19. BIN
      includes/js/vis/dist/img/network/upArrow.png
  20. BIN
      includes/js/vis/dist/img/network/zoomExtends.png
  21. +34
    -0
      includes/js/vis/dist/vis-graph3d.min.js
  22. +1
    -0
      includes/js/vis/dist/vis-network.min.css
  23. +42
    -0
      includes/js/vis/dist/vis-network.min.js
  24. +1
    -0
      includes/js/vis/dist/vis-timeline-graph2d.min.css
  25. +40
    -0
      includes/js/vis/dist/vis-timeline-graph2d.min.js
  26. +1448
    -0
      includes/js/vis/dist/vis.css
  27. +52833
    -0
      includes/js/vis/dist/vis.js
  28. +1
    -0
      includes/js/vis/dist/vis.js.map
  29. +1
    -0
      includes/js/vis/dist/vis.map
  30. +1
    -0
      includes/js/vis/dist/vis.min.css
  31. +46
    -0
      includes/js/vis/dist/vis.min.js
  32. +0
    -1
      sites/admin.js
  33. +20
    -0
      templates/admin/analytics.html
  34. +5
    -0
      utils/sql.js

+ 5
- 1
admin/admin.js View File

@ -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();

+ 71
- 0
admin/analytics.js View File

@ -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);
});
});
}
};

+ 0
- 24
admin/analytics/analytics.js View File

@ -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("<div class=\"col-md-6\">" +
html.join('') +
"</div></div>");
}).catch(function(error)
{
console.log("error in addCategory.js");
reject(error);
})
});
}
};

admin/login/login.js → admin/login.js View File

@ -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');

+ 14
- 1
includes/html/adminHeader.html View File

@ -41,7 +41,17 @@
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<script src="../../admin/login/login.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous">
</script>
<script src="/includes/js/vis/dist/vis.js"></script>
<link href="/includes/js/vis/dist/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" />
</head>
@ -72,6 +82,9 @@
<li class="nav-item">
<a class="nav-link" href="/admin/users">Users</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/admin/analytics">Analytics</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="nav-item">

BIN
includes/js/vis/dist/img/network/acceptDeleteIcon.png View File

Before After
Width: 24  |  Height: 24  |  Size: 20 KiB

BIN
includes/js/vis/dist/img/network/addNodeIcon.png View File

Before After
Width: 24  |  Height: 24  |  Size: 20 KiB

BIN
includes/js/vis/dist/img/network/backIcon.png View File

Before After
Width: 24  |  Height: 24  |  Size: 20 KiB

BIN
includes/js/vis/dist/img/network/connectIcon.png View File

Before After
Width: 24  |  Height: 24  |  Size: 20 KiB

BIN
includes/js/vis/dist/img/network/cross.png View File

Before After
Width: 7  |  Height: 7  |  Size: 18 KiB

BIN
includes/js/vis/dist/img/network/cross2.png View File

Before After
Width: 5  |  Height: 5  |  Size: 17 KiB

BIN
includes/js/vis/dist/img/network/deleteIcon.png View File

Before After
Width: 24  |  Height: 24  |  Size: 20 KiB

BIN
includes/js/vis/dist/img/network/downArrow.png View File

Before After
Width: 30  |  Height: 30  |  Size: 4.4 KiB

BIN
includes/js/vis/dist/img/network/editIcon.png View File

Before After
Width: 24  |  Height: 24  |  Size: 20 KiB

BIN
includes/js/vis/dist/img/network/leftArrow.png View File

Before After
Width: 30  |  Height: 30  |  Size: 4.4 KiB

BIN
includes/js/vis/dist/img/network/minus.png View File

Before After
Width: 30  |  Height: 30  |  Size: 4.0 KiB

BIN
includes/js/vis/dist/img/network/plus.png View File

Before After
Width: 30  |  Height: 30  |  Size: 4.2 KiB

BIN
includes/js/vis/dist/img/network/rightArrow.png View File

Before After
Width: 30  |  Height: 30  |  Size: 4.4 KiB

BIN
includes/js/vis/dist/img/network/upArrow.png View File

Before After
Width: 30  |  Height: 30  |  Size: 4.4 KiB

BIN
includes/js/vis/dist/img/network/zoomExtends.png View File

Before After
Width: 30  |  Height: 30  |  Size: 4.4 KiB

+ 34
- 0
includes/js/vis/dist/vis-graph3d.min.js
File diff suppressed because it is too large
View File


+ 1
- 0
includes/js/vis/dist/vis-network.min.css
File diff suppressed because it is too large
View File


+ 42
- 0
includes/js/vis/dist/vis-network.min.js
File diff suppressed because it is too large
View File


+ 1
- 0
includes/js/vis/dist/vis-timeline-graph2d.min.css
File diff suppressed because it is too large
View File


+ 40
- 0
includes/js/vis/dist/vis-timeline-graph2d.min.js
File diff suppressed because it is too large
View File


+ 1448
- 0
includes/js/vis/dist/vis.css
File diff suppressed because it is too large
View File


+ 52833
- 0
includes/js/vis/dist/vis.js
File diff suppressed because it is too large
View File


+ 1
- 0
includes/js/vis/dist/vis.js.map
File diff suppressed because it is too large
View File


+ 1
- 0
includes/js/vis/dist/vis.map
File diff suppressed because it is too large
View File


+ 1
- 0
includes/js/vis/dist/vis.min.css
File diff suppressed because it is too large
View File


+ 46
- 0
includes/js/vis/dist/vis.min.js
File diff suppressed because it is too large
View File


+ 0
- 1
sites/admin.js View File

@ -31,7 +31,6 @@ module.exports=
const clientAddress = (request.headers['x-forwarded-for'] || '').split(',')[0]
|| request.connection.remoteAddress;
result.writeHead(200, {'Content-Type': 'text/html'});
const file = "../admin/admin.js";

+ 20
- 0
templates/admin/analytics.html View File

@ -0,0 +1,20 @@
<h4 class="text-center">Traffic Graph</h4>
<div class="row">
<div class="col-12">
<div id="visualization"></div>
</div>
<br><br>
<script type="text/javascript">
var container = document.getElementById('visualization');
var items = {dataset};
var dataset = new vis.DataSet(items);
var options = {
start: {start},
end: {finish},
};
var graph2d = new vis.Graph2d(container, dataset, options);
</script>
</div>

+ 5
- 0
utils/sql.js View File

@ -634,5 +634,10 @@ module.exports=
"('" + page + "', '" + ip + "', now())";
insert(q);
},
getTraffic: function()
{
return fetch("select * from traffic_log");
}
};

Loading…
Cancel
Save