commit cf743c286102e9a6af7b968ed361ca08788749f9 Author: Christoffer Müller Madsen Date: Sat Sep 17 04:08:42 2016 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5396b94 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +node_modules diff --git a/package.json b/package.json new file mode 100644 index 0000000..6db61d6 --- /dev/null +++ b/package.json @@ -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 ", + "license": "ISC", + "dependencies": { + "domjs": "^0.3.0", + "ejs": "^2.5.2", + "express": "^4.14.0", + "mongodb": "^2.2.10", + "pug": "^2.0.0-beta6" + } +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..4ea7645 --- /dev/null +++ b/server.js @@ -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!'); + }); \ No newline at end of file diff --git a/static/klandringer.css b/static/klandringer.css new file mode 100644 index 0000000..08904ee --- /dev/null +++ b/static/klandringer.css @@ -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; +} diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..f366d27 --- /dev/null +++ b/static/style.css @@ -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; + } \ No newline at end of file diff --git a/views/head.ejs b/views/head.ejs new file mode 100644 index 0000000..552c514 --- /dev/null +++ b/views/head.ejs @@ -0,0 +1,4 @@ + +Holdets time på DAT3 + + diff --git a/views/klandringer.ejs b/views/klandringer.ejs new file mode 100644 index 0000000..019f635 --- /dev/null +++ b/views/klandringer.ejs @@ -0,0 +1,37 @@ + + + <% include head %> + + +

// Referater fra holdets time på DAT3 //

+ + +<% +for (var key in data) { +%> +

<%=key%>

+ <%for (var i in data[key]) { + var k = data[key][i]; %> + ">

<%=k["klandrer"]%> v. <%=k["klandret"]%> - <%=k["title"]%>

+

+ <%-k["description"]%> +

+ <%=k["taber"]%> taber! +

+ <% } +} +%> + +