Overhauled entire website with 0 change in looks

So I can finally work on implementing #35 but it feels like I did nothing :(
This commit is contained in:
Danielv123 committed 2017-03-08 11:32:01 +01:00
1 parent cc6ff973b5
commit 9edf4dc18e
12 files changed
+138 -268

No files matched your search

+10 -1
View File
@@ -5,13 +5,14 @@ const masterModFolder = "./database/masterMods/"
const mkdirp = require("mkdirp");
mkdirp.sync("./database");
mkdirp.sync(masterModFolder);
const path = require("path")
const fs = require("fs")
var nedb = require("nedb")
// require config.json
var config = require('./config');
var express = require("express");
var ejs = require("ejs");
// Required for express post requests
var bodyParser = require("body-parser");
var fileUpload = require('express-fileupload');
@@ -21,6 +22,14 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(fileUpload());
// dynamic HTML generations with EJS
app.set('views', path.join(__dirname, 'static'));
app.set('view engine', 'ejs');
var routes = require("./routes.js");
routes(app);
// Set folder to serve static content from (the website)
app.use(express.static('static'));
// mod downloads
+1
View File
@@ -16,6 +16,7 @@
"body-parser": "^1.15.2",
"canvasjs": "^1.8.1",
"child_process": "^1.0.2",
"ejs": "^2.5.6",
"express": "^4.14.0",
"express-fileupload": "0.0.6",
"find-remove": "^1.0.0",
+8
View File
@@ -0,0 +1,8 @@
module.exports = function(app) {
app.get("/", function(req, res) {
res.render("index");
});
app.get("/nodes", function(req, res) {
res.render("nodes");
});
};
+4
View File
@@ -0,0 +1,4 @@
<title>Clusterio</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/canvasjs/1.7.0/canvasjs.js" type="text/javascript"></script>
<script src="main.js"></script>
+16
View File
@@ -0,0 +1,16 @@
<!doctype HTML>
<head>
<%- include("head.html") %>
</head>
<body>
<%- include("sidebar.html") %>
<div id="body">
<div id="storage">
<h2>Storage</h2>
<div id="contents">
</div>
<canvas id="contentGraph" width="200" height="200"></canvas>
</div>
</div>
</body>
-48
View File
@@ -1,48 +0,0 @@
<!doctype HTML>
<head>
<title>Clusterio</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/canvasjs/1.7.0/canvasjs.js" type="text/javascript"></script>
<script src="main.js"></script>
</head>
<body>
<div id="header">
</div>
<div id="sidenav">
<div id="logo">
<h1>Clusterio</h1>
</div>
<div id="storage-menu" onclick="display('storage');" class="button-black menuItem">
<p>Storage</p>
</div>
<!--<div id="production-menu" onclick="display('production');" class="button-black menuItem">
<p>Production</p>
</div>-->
<div id="slaves-menu" onclick="display('slaves');" class="button-black menuItem">
<p>Slaves</p>
</div>
</div>
<div id="body">
<div id="storage">
<h2>Storage</h2>
<div id="contents">
</div>
<canvas id="contentGraph" width="200" height="200"></canvas>
</div>
<div id="production">
<h2>Production</h2>
<div id="legend">
</div>
<div id="productionChart" style="height: 300px; width: 100%;"></div>
</div>
<div id="slaves">
<h2>Slaves</h2>
<div id="display">
</div>
</div>
</div>
</body>
-216
View File
@@ -29,196 +29,7 @@ function capitalizeFirstLetter(string) {
function hideThis(object) {
object.style.visibility = "hidden";
}
// function to sort arrays of objects after a keys value
function sortByKey(array, key) {
return array.sort(function(a, b) {
var x = Number(a[key]); var y = Number(b[key]);
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
});
}
// function to draw data we recieve from ajax requests
function drawcontents(data) {
var data = sortByKey(data, "count");
result = "<table>";
for(i = 0;i < data.length; i++) {
var img = "";
if(imagedata[data[i].name]){
img = "https://wiki.factorio.com/images/" + imagedata[data[i].name] + ".png"
} else {
img = "https://wiki.factorio.com/images/" + capitalizeFirstLetter(data[i].name) + ".png";
}
result = result + "<tr><td><image src='" + img + "' onerror='hideThis(this);'></td><td>" + data[i].name + "</td><td>" + data[i].count + "</td></tr>";
}
result = result + "</table>"
document.getElementById("contents").innerHTML = result;
}
// handle the navigation buttons
currentPage = ""
function display(page) {
var pages = document.querySelector("#body").childNodes;
for(i=0;i<pages.length;i++){
if(pages[i].style){
pages[i].style.display = "none";
}
}
if(typeof page == "string" && document.querySelector("#" + page)) {
document.querySelector("#" + page).style.display = "block";
currentPage = page;
}
}
// setTimeout is used to put this processing in the back of the queue, after the HTML canvas is done
window.onload = function () {
display("storage")
// dataPoints
var dataPoints1 = [];
var dataPoints2 = [];
var chart = new CanvasJS.Chart("productionChart",{
zoomEnabled: true,
title: {
text: "Production"
},
toolTip: {
shared: true
},
legend: {
verticalAlign: "top",
horizontalAlign: "center",
fontSize: 14,
fontWeight: "bold",
fontFamily: "calibri",
fontColor: "dimGrey"
},
axisX: {
title: "Shows items in network"
},
axisY:{
prefix: '',
includeZero: true
},
data: [{
// dataSeries1
type: "line",
xValueType: "dateTime",
showInLegend: true,
name: "Company A",
dataPoints: dataPoints1
},
{
// dataSeries2
type: "line",
xValueType: "dateTime",
showInLegend: true,
name: "Company B" ,
dataPoints: dataPoints2
}],
legend:{
cursor:"pointer",
itemclick : function(e) {
if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
}
else {
e.dataSeries.visible = true;
}
chart.render();
}
}
});
var updateInterval = 10000;
// initial value
var yValue1 = 640;
var yValue2 = 604;
var time = new Date;
time.setHours(9);
time.setMinutes(30);
time.setSeconds(00);
time.setMilliseconds(00);
// starting at 9.30 am
var updateChart = function (count) {
count = count || 1;
// count is number of times loop runs to generate random dataPoints.
for (var i = 0; i < count; i++) {
// add interval duration to time
time.setTime(time.getTime()+ updateInterval);
// generating random values
var deltaY1 = .5 + Math.random() *(-.5-.5);
var deltaY2 = .5 + Math.random() *(-.5-.5);
// adding random value and rounding it to two digits.
yValue1 = Math.round((yValue1 + deltaY1)*100)/100;
yValue2 = Math.round((yValue2 + deltaY2)*100)/100;
// pushing the new values
dataPoints1.push({
x: time.getTime(),
y: yValue1
});
dataPoints2.push({
x: time.getTime(),
y: yValue2
});
};
// updating legend text with updated with y Value
chart.options.data[0].legendText = " Company A $" + yValue1;
chart.options.data[1].legendText = " Company B $" + yValue2;
chart.render();
};
// generates first set of dataPoints
updateChart(3000);
// update chart after specified interval
setInterval(function(){updateChart()}, updateInterval);
}
var piedata = {};
var piedataOld = {};
// get cluster inventory from master
setInterval(function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
data = JSON.parse(xmlhttp.responseText);
if(currentPage = "storage"){
drawcontents(data);
}
// render our piechart with up to date information
// items-in-network-chart
if(piedata) {
piedataOld = piedata;
}
piedata = [];
for(i=0;i<data.length;i++) {
piedata[piedata.length] = {
value: Number(data[i].count),
color: hashColor(data[i].name),
label: data[i].name,
}
}
}
}
xmlhttp.open("GET", "inventory", true);
xmlhttp.send();
}, 500)
// get all slaves recently connected to master
Date.prototype.yyyymmdd = function(time) { // http://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object
var mm = this.getMonth() + 1; // getMonth() is zero-based
var dd = this.getDate();
@@ -229,33 +40,6 @@ Date.prototype.yyyymmdd = function(time) { // http://stackoverflow.com/questions
};
var date = new Date();
// ask master for slaves
setInterval(function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var slaveData = JSON.parse(xmlhttp.responseText);
var HTML = "<p>Current connections:</p>"
for(i=0;i<Object.keys(slaveData).length;i++){
var key = Object.keys(slaveData)[i]
// Date.getYear.getmonth.getDay
if(Date.now() - slaveData[key].time < 12000) {
// Display ISO 6801 compliant date to please Zarthus
// maybe include an option to use y-ymd-ymd-y for Trangar compatibility as well
var seenDate = date.yyyymmdd(slaveData[key].time)
if(g.trangarTime == true){
var seenDate = (seenDate+"")[0]+"-"+(seenDate+"")[1]+(seenDate+"")[4]+(seenDate+"")[6]+"-"+(seenDate+"")[2]+(seenDate+"")[5]+(seenDate+"")[7]+"-"+(seenDate+"")[3]
}
HTML += "<div class='slaveBox'><h2>ID: " + slaveData[key].unique + "</h2><p>Last seen: "+seenDate+"</p><p>Port: "+slaveData[key].serverPort+"</p><p>Host: "+slaveData[key].mac+"</p></div>"
}
}
document.querySelector("#slaves > #display").innerHTML = HTML
}
}
xmlhttp.open("GET", "slaves", true);
xmlhttp.send();
}, 500)
// image data
// key is the name of the item in the database, value is the name of the image on wiki.factorio.com/images/*
// this list has to include all entities that doesn't just follow the simple capitalize first letter convention
+17
View File
@@ -0,0 +1,17 @@
<!doctype HTML>
<head>
<%- include("head.html") %>
<script src="slaveDisplay.js"></script>
</head>
<body>
<%- include("sidebar.html") %>
<div id="body">
<div id="slaves">
<h2>Slaves</h2>
<div id="display">
</div>
</div>
</div>
</body>
+17
View File
@@ -0,0 +1,17 @@
<div id="header">
</div>
<div id="sidenav">
<div id="logo">
<h1>Clusterio</h1>
</div>
<a href="/"><div id="storage-menu" class="button-black menuItem">
<p>Storage</p>
</div></a>
<!--<div id="production-menu" onclick="display('production');" class="button-black menuItem">
<p>Production</p>
</div>-->
<a href="nodes"><div id="slaves-menu" class="button-black menuItem">
<p>Slaves</p>
</div></a>
</div>
+28
View File
@@ -0,0 +1,28 @@
// ask master for slaves
setInterval(function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var slaveData = JSON.parse(xmlhttp.responseText);
var HTML = "<p>Current connections:</p>"
for(i=0;i<Object.keys(slaveData).length;i++){
var key = Object.keys(slaveData)[i]
// Date.getYear.getmonth.getDay
if(Date.now() - slaveData[key].time < 12000) {
// Display ISO 6801 compliant date to please Zarthus
// maybe include an option to use y-ymd-ymd-y for Trangar compatibility as well
var seenDate = date.yyyymmdd(slaveData[key].time)
if(g.trangarTime == true){
var seenDate = (seenDate+"")[0]+"-"+(seenDate+"")[1]+(seenDate+"")[4]+(seenDate+"")[6]+"-"+(seenDate+"")[2]+(seenDate+"")[5]+(seenDate+"")[7]+"-"+(seenDate+"")[3]
}
HTML += "<div class='slaveBox'><h2>ID: " + slaveData[key].unique + "</h2><p>Last seen: "+seenDate+"</p><p>Port: "+slaveData[key].serverPort+"</p><p>Host: "+slaveData[key].mac+"</p></div>"
}
}
document.querySelector("#slaves > #display").innerHTML = HTML
}
}
xmlhttp.open("GET", "slaves", true);
xmlhttp.send();
}, 500)
// get all slaves recently connected to master
+37
View File
@@ -0,0 +1,37 @@
// function to draw data we recieve from ajax requests
function drawcontents(data) {
var data = sortByKey(data, "count");
result = "<table>";
for(i = 0;i < data.length; i++) {
var img = "";
if(imagedata[data[i].name]){
img = "https://wiki.factorio.com/images/" + imagedata[data[i].name] + ".png"
} else {
img = "https://wiki.factorio.com/images/" + capitalizeFirstLetter(data[i].name) + ".png";
}
result = result + "<tr><td><image src='" + img + "' onerror='hideThis(this);'></td><td>" + data[i].name + "</td><td>" + data[i].count + "</td></tr>";
}
result = result + "</table>"
document.getElementById("contents").innerHTML = result;
}
// get cluster inventory from master
setInterval(function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
data = JSON.parse(xmlhttp.responseText);
drawcontents(data);
}
}
xmlhttp.open("GET", "inventory", true);
xmlhttp.send();
}, 500)
// function to sort arrays of objects after a keys value
function sortByKey(array, key) {
return array.sort(function(a, b) {
var x = Number(a[key]); var y = Number(b[key]);
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
});
}
-3
View File
@@ -16,9 +16,6 @@
#body {
margin-left:200px;
}
#body > div {
display:none;
}
#body > #production {
display:block;
}