diff --git a/app.js b/app.js index 065ce1d..db3dd2d 100644 --- a/app.js +++ b/app.js @@ -35,10 +35,14 @@ io.configure(function () { // Use the port that Heroku provides or default to 5000 var port = process.env.PORT || 5000; -app.listen(port, function() { - console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); +var host = process.env.HOST || '0.0.0.0'; +app.listen(port, host, function() { + console.log("Express server listening on %j in %s mode", app.address(), app.settings.env); }); +// configure title +app.title = process.env.TITLE || 'Timer' + app.get('/', routes.index); var stopwatch = new Stopwatch(); @@ -63,7 +67,46 @@ io.sockets.on('connection', function (socket) { stopwatch.stop(); }); + socket.on('click:zero', function () { + stopwatch.zero(); + }); + socket.on('click:reset', function () { stopwatch.reset(); }); -}); \ No newline at end of file + + socket.on('click:resetShort', function () { + stopwatch.resetShort(); + }); +}); + +app.post('/reset/', function (req, res) { + stopwatch.reset(); + res.send("OK"); +}); +app.post('/reset-short/', function (req, res) { + stopwatch.resetShort(); + res.send("OK"); +}); +app.post('/start-from-reset/', function (req, res) { + stopwatch.reset(); + stopwatch.start(); + res.send("OK"); +}); +app.post('/start-from-reset-short/', function (req, res) { + stopwatch.resetShort(); + stopwatch.start(); + res.send("OK"); +}); +app.post('/start/', function (req, res) { + stopwatch.start(); + res.send("OK"); +}); +app.post('/stop/', function (req, res) { + stopwatch.stop(); + res.send("OK"); +}); +app.post('/zero/', function (req, res) { + stopwatch.zero(); + res.send("OK"); +}); diff --git a/models/stopwatch.js b/models/stopwatch.js index 29ace51..44c467f 100644 --- a/models/stopwatch.js +++ b/models/stopwatch.js @@ -2,6 +2,9 @@ var util = require('util'), events = require('events') _ = require('underscore'); +var DEFAULT_TIME = 45* 60 * 1000; +var DEFAULT_SHORT_TIME = 5 * 60 * 1000; + // --------------------------------------------- // Constructor // --------------------------------------------- @@ -13,7 +16,9 @@ function Stopwatch() { this.hour = 3600000; this.minute = 60000; this.second = 1000; - this.time = this.hour; + this.defaultTime = DEFAULT_TIME; + this.defaultShortTime = DEFAULT_SHORT_TIME; + this.time = this.defaultTime; this.interval = undefined; events.EventEmitter.call(this); @@ -55,7 +60,19 @@ Stopwatch.prototype.stop = function() { Stopwatch.prototype.reset = function() { console.log('Resetting Stopwatch!'); - this.time = this.hour; + this.time = this.defaultTime; + this.emit('reset:stopwatch', this.formatTime(this.time)); +}; + +Stopwatch.prototype.zero = function() { + console.log('Zeroing Stopwatch!'); + this.time = 1000; + this.emit('reset:stopwatch', this.formatTime(this.time)); +}; + +Stopwatch.prototype.resetShort = function() { + console.log('Resetting Stopwatch to Short!'); + this.time = this.defaultShortTime; this.emit('reset:stopwatch', this.formatTime(this.time)); }; @@ -102,4 +119,4 @@ Stopwatch.prototype.getTime = function() { // --------------------------------------------- // Export // --------------------------------------------- -module.exports = Stopwatch; \ No newline at end of file +module.exports = Stopwatch; diff --git a/public/css/main.css b/public/css/main.css index 469fb5f..e865142 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -55,4 +55,4 @@ button.thoughtbot:active { -webkit-box-shadow: inset 0px 0px 0px 1px rgba(255, 115, 100, 0.4); -moz-box-shadow: inset 0px 0px 0px 1px rgba(255, 115, 100, 0.4); box-shadow: inset 0px 0px 0px 1px rgba(255, 115, 100, 0.4); -} \ No newline at end of file +} diff --git a/public/js/main.js b/public/js/main.js index 986ab5a..5d6286c 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -14,4 +14,8 @@ $('#stop').click(function() { $('#reset').click(function() { socket.emit('click:reset'); -}); \ No newline at end of file +}); + +$('#resetShort').click(function() { + socket.emit('click:resetShort'); +}); diff --git a/routes/index.js b/routes/index.js index 8662c02..8fd06f6 100644 --- a/routes/index.js +++ b/routes/index.js @@ -5,5 +5,5 @@ var app = require('../app'); */ exports.index = function(req, res) { - res.render('index') -}; \ No newline at end of file + res.render('index', {"title": app.title}) +}; diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..b8039ad --- /dev/null +++ b/start.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Usage: +# HOST=127.0.0.1 PORT=5051 TITLE=HALL-B ./start.sh + +cd "$(dirname "$0")" + +NODE_ENV=production node app.js diff --git a/views/index.ejs b/views/index.ejs index 1fa1d27..9a8f3d0 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -3,4 +3,7 @@ - \ No newline at end of file + + + + diff --git a/views/layout.ejs b/views/layout.ejs index 9839179..4a2648b 100644 --- a/views/layout.ejs +++ b/views/layout.ejs @@ -2,7 +2,7 @@ - DEFCON + <%= title => @@ -24,4 +24,4 @@ - \ No newline at end of file +