initial commit

This commit is contained in:
Christoffer Müller Madsen 2016-09-17 04:08:42 +02:00
commit cf743c2861
7 changed files with 143 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*~
node_modules

22
package.json Normal file
View File

@ -0,0 +1,22 @@
{
"name": "klandr-server",
"version": "0.0.1",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://mango.thedevcave.net/christoffermadsen/klandr-server"
},
"author": "Christoffer Müller Madsen <christoffer.m.madsen@thedevcave.net>",
"license": "ISC",
"dependencies": {
"domjs": "^0.3.0",
"ejs": "^2.5.2",
"express": "^4.14.0",
"mongodb": "^2.2.10",
"pug": "^2.0.0-beta6"
}
}

42
server.js Normal file
View File

@ -0,0 +1,42 @@
var express = require('express');
var app = express();
var MongoClient = require('mongodb').MongoClient, assert = require('assert');
var url = 'mongodb://localhost:27017/dat3holdetstime';
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/static'));
var mongodb;
// Connect to mongodb
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
console.log("Connected succesfully to Mongo server");
mongodb = db;
});
var getdata = function(callback) {
var collection = mongodb.collection("klandringer");
var cursor = collection.find();
cursor.toArray(function(err, result) {
if (err) {
throw err;
} else {
var klanddata = {};
for(var i = 0; i < result.length; i++) {
klanddata[result[i]['date']] = result[i]['data'];
}
callback(klanddata);
}
});
}
app.get('/', function(req, res) {
getdata(function(result) {
res.render("klandringer", {data:result});
});
});
app.listen(35211, function () {
console.log('Server listening on port 35211!');
});

21
static/klandringer.css Normal file
View File

@ -0,0 +1,21 @@
h2,h3,h4,p {
font-family: sans-serif;
margin-left: 5px;
}
h4 {
font-size: 1.17em;
}
p {
max-width: 600px;
margin-left: 15px;
}
table {
margin-left: 30px;
}
td {
text-align: center;
}

15
static/style.css Normal file
View File

@ -0,0 +1,15 @@
body {
font-family: monospace;
background-color: #fff;
color: #000;
}
a:link, a:visited {
color: #ff9900;
transition-duration: 0.3s;
}
a:hover, a:active {
color: #ffb84d;
transition-duration: 0.3s;
}

4
views/head.ejs Normal file
View File

@ -0,0 +1,4 @@
<meta charset="UTF-8">
<title>Holdets time på DAT3</title>
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="stylesheet" href="klandringer.css" type="text/css">

37
views/klandringer.ejs Normal file
View File

@ -0,0 +1,37 @@
<html>
<head>
<% include head %>
</head>
<body>
<h1>// Referater fra holdets time på DAT3 //</h1>
<ul>
<%
for (var key in data) { %>
<li><a href="#<%=key%>"><%=key%></a>
<ul>
<% for (var i in data[key]) {
var k = data[key][i]; %>
<li><a href="#<%=(k["klandrer"] + k["klandret"] + k["title"]).replace(/\s/g,'')%>"><%=k["klandrer"]%> v. <%=k["klandret"]%> - <i><%=k["title"]%></i></a></li>
<% } %>
</ul>
<% } %>
%>
</ul>
<%
for (var key in data) {
%>
<h2><%=key%></h2>
<%for (var i in data[key]) {
var k = data[key][i]; %>
<a name="<%=(k["klandrer"] + k["klandret"] + k["title"]).replace(/\s/g,'')%>"></a><h4><%=k["klandrer"]%> v. <%=k["klandret"]%> - <i><%=k["title"]%></i></h4>
<p>
<%-k["description"]%>
<br><br>
<i><%=k["taber"]%> taber!</i>
</p>
<% }
}
%>
<body>
</html>