Permalink
Browse files

reset

  • Loading branch information...
1 parent 66e4057 commit adc72b82c6bfa1a8848d269b47e8e8604ad0025d @vogievetsky vogievetsky committed Aug 23, 2012
Showing with 166 additions and 18 deletions.
  1. +28 −3 app.coffee
  2. +35 −4 app.js
  3. +3 −3 package.json
  4. +3 −0 public/index.html
  5. +27 −2 public/muse.coffee
  6. +16 −0 public/muse.css
  7. +25 −5 public/muse.js
  8. +25 −1 public/muse.scss
  9. +4 −0 todo
View
31 app.coffee
@@ -56,13 +56,16 @@ app = http.createServer (req, res) ->
if req.url is '/'
res.statusCode = 302
- res.setHeader('Location', '/dc')
- res.end('Redirecting to /dc')
- else if match = req.url.match(/^\/(\w+)$/)
+ res.setHeader('Location', '/DC')
+ res.end('Redirecting to /DC')
+ else if match = req.url.match(/^\/([a-z]+)$/i)
send(req, 'index.html')
.root('public')
.on('error', error)
.pipe(res)
+ else if req.url is '/_archive'
+ archive()
+ res.end('A reset has been sent')
else
send(req, req.url)
.root('public')
@@ -97,3 +100,25 @@ io.sockets.on 'connection', (socket) ->
return
return
+
+archive = ->
+ for locationName, location of locations
+ location.drawers = {}
+ location.dirty = true
+ io.sockets.emit('reset')
+ return
+
+# cron job :-)
+offset = -7 # PST
+getDate = -> (new Date(Date.now() + offset * 60 * 60 * 1000)).getUTCDate()
+lastDate = getDate()
+setInterval((->
+ nowDate = getDate()
+ return if lastDate is nowDate
+ archive()
+ lastDate = nowDate
+), 10000)
+
+
+
+
View
39 app.js
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.3.1
(function() {
- var LOCATION_DIR, app, file, fs, http, io, json, locationName, locationNames, locations, send, _i, _len;
+ var LOCATION_DIR, app, archive, file, fs, getDate, http, io, json, lastDate, locationName, locationNames, locations, offset, send, _i, _len;
http = require('http');
@@ -70,10 +70,13 @@
};
if (req.url === '/') {
res.statusCode = 302;
- res.setHeader('Location', '/dc');
- res.end('Redirecting to /dc');
- } else if (match = req.url.match(/^\/(\w+)$/)) {
+ res.setHeader('Location', '/DC');
+ res.end('Redirecting to /DC');
+ } else if (match = req.url.match(/^\/([a-z]+)$/i)) {
send(req, 'index.html').root('public').on('error', error).pipe(res);
+ } else if (req.url === '/_archive') {
+ archive();
+ res.end('A reset has been sent');
} else {
send(req, req.url).root('public').on('error', error).pipe(res);
}
@@ -102,4 +105,32 @@
});
});
+ archive = function() {
+ var location, locationName;
+ for (locationName in locations) {
+ location = locations[locationName];
+ location.drawers = {};
+ location.dirty = true;
+ }
+ io.sockets.emit('reset');
+ };
+
+ offset = -7;
+
+ getDate = function() {
+ return (new Date(Date.now() + offset * 60 * 60 * 1000)).getUTCDate();
+ };
+
+ lastDate = getDate();
+
+ setInterval((function() {
+ var nowDate;
+ nowDate = getDate();
+ if (lastDate === nowDate) {
+ return;
+ }
+ archive();
+ return lastDate = nowDate;
+ }), 10000);
+
}).call(this);
View
6 package.json
@@ -2,14 +2,14 @@
"name": "muse",
"subdomain": "muse",
"scripts": {
- "start": "app.coffee"
+ "start": "app.js"
},
- "version": "0.0.0-1",
+ "version": "0.0.5",
"engines": {
"node": "0.6.x"
},
"dependencies": {
- "paperboy": "0.0.5",
+ "send": "0.0.4",
"socket.io": "0.9.9"
}
}
View
3 public/index.html
@@ -12,6 +12,9 @@
</div>
<div class="edit-cont">
</div>
+ <div class="loading-cont">
+ <div class="msg">Loading...</div>
+ </div>
</body>
<script src="/muse.js"></script>
</html>
View
29 public/muse.coffee
@@ -46,18 +46,24 @@ msgs = msgs.split('-----')
drawers = []
drawerPos = {}
-drawerState = {}
for ix in [0...number]
for iy in [0...number]
id = "#{ix}_#{iy}"
drawers.push(id)
x = ix * (drawerWidth + gap) + gap
y = iy * (drawerHeight + gap) + gap
drawerPos[id] = { ix, iy, x, y }
- drawerState[id] = {
+
+
+drawerState = {}
+resetDrawerState = ->
+ for d in drawers
+ drawerState[d] = {
open: false
cards: []
}
+ return
+resetDrawerState()
drawers.sort (da, db) ->
np1o2 = (number+1)
@@ -212,6 +218,14 @@ update_drawers()
editCont = d3.select('.edit-cont')
.style('display', 'none')
+hideLoading = ->
+ d3.select('.loading-cont')
+ .style('opacity', 1)
+ .transition()
+ .duration(1000)
+ .style('opacity', 0)
+ .remove()
+
# -------------------------------------------------------
# -------------------------------------------------------
@@ -229,6 +243,7 @@ if window.io
for k,v of dr
drawerState[k] = v or { open: false, cards: [] }
update_drawers()
+ hideLoading()
return
socket.on 'drawerChange', (drawer, state) ->
@@ -240,6 +255,12 @@ if window.io
return
return
+ socket.on 'reset', ->
+ console.log 'GOT reset'
+ resetDrawerState()
+ update_drawers()
+ return
+
notify_change = (d) ->
socket.emit('drawerChange', d, drawerState[d])
return
@@ -248,3 +269,7 @@ else
for d in drawers
d.cards = if Math.random() > 0.85 then [msgs[Math.floor(Math.random() * msgs.length)]] else []
+
+ hideLoading()
+
+
View
16 public/muse.css
@@ -214,3 +214,19 @@ html, body {
margin-top: -325px;
width: 930px;
height: 650px; }
+
+.loading-cont {
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ left: 0;
+ right: 0;
+ background: rgba(255, 255, 255, 0.8); }
+ .loading-cont .msg {
+ font-size: 40px;
+ position: absolute;
+ left: 0;
+ right: 0;
+ text-align: center;
+ top: 50%;
+ margin-top: -23px; }
View
30 public/muse.js
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.3.1
(function() {
- var box_click, cross, d, drawerChest, drawerClassFn, drawerDepth, drawerHeight, drawerPos, drawerState, drawerWidth, drawers, drawersCont, editCont, gap, id, ix, iy, make_box, make_cards, msgs, myDrawer, notify_change, number, openDepth, scale, socket, update_drawers, x, y, _i, _j, _k, _len;
+ var box_click, cross, d, drawerChest, drawerClassFn, drawerDepth, drawerHeight, drawerPos, drawerState, drawerWidth, drawers, drawersCont, editCont, gap, hideLoading, id, ix, iy, make_box, make_cards, msgs, myDrawer, notify_change, number, openDepth, resetDrawerState, scale, socket, update_drawers, x, y, _i, _j, _k, _len;
if (window.console == null) {
window.console = {
@@ -31,8 +31,6 @@
drawerPos = {};
- drawerState = {};
-
for (ix = _i = 0; 0 <= number ? _i < number : _i > number; ix = 0 <= number ? ++_i : --_i) {
for (iy = _j = 0; 0 <= number ? _j < number : _j > number; iy = 0 <= number ? ++_j : --_j) {
id = "" + ix + "_" + iy;
@@ -45,12 +43,23 @@
x: x,
y: y
};
- drawerState[id] = {
+ }
+ }
+
+ drawerState = {};
+
+ resetDrawerState = function() {
+ var d, _k, _len;
+ for (_k = 0, _len = drawers.length; _k < _len; _k++) {
+ d = drawers[_k];
+ drawerState[d] = {
open: false,
cards: []
};
}
- }
+ };
+
+ resetDrawerState();
drawers.sort(function(da, db) {
var daix, daiy, dbix, dbiy, np1o2;
@@ -202,6 +211,10 @@
editCont = d3.select('.edit-cont').style('display', 'none');
+ hideLoading = function() {
+ return d3.select('.loading-cont').style('opacity', 1).transition().duration(1000).style('opacity', 0).remove();
+ };
+
if (window.io) {
console.log('IO detected');
socket = io.connect();
@@ -219,6 +232,7 @@
};
}
update_drawers();
+ hideLoading();
});
socket.on('drawerChange', function(drawer, state) {
var d, _k, _len;
@@ -232,6 +246,11 @@
}
}
});
+ socket.on('reset', function() {
+ console.log('GOT reset');
+ resetDrawerState();
+ update_drawers();
+ });
notify_change = function(d) {
socket.emit('drawerChange', d, drawerState[d]);
};
@@ -241,6 +260,7 @@
d = drawers[_k];
d.cards = Math.random() > 0.85 ? [msgs[Math.floor(Math.random() * msgs.length)]] : [];
}
+ hideLoading();
}
}).call(this);
View
26 public/muse.scss
@@ -265,4 +265,28 @@ html, body {
.edit-cont {
@include center-xy($totalOuterWidth, $totalOuterHeight);
-}
+}
+
+.loading-cont {
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ left: 0;
+ right: 0;
+ background: rgba(255, 255, 255, 0.8);
+
+ .msg {
+ font-size: 40px;
+ position: absolute;
+ left: 0;
+ right: 0;
+ text-align: center;
+ top: 50%;
+ margin-top: -23px;
+ }
+}
+
+
+
+
+
View
4 todo
@@ -0,0 +1,4 @@
+- refresh
+
+- archive
+- editing

0 comments on commit adc72b8

Please sign in to comment.