Permalink
Browse files

Items split across days.

  • Loading branch information...
1 parent 2c1dd3a commit 943ca82fd3a34e490c5939c63afbfc3bbe4c4315 @ahw committed Dec 2, 2012
Showing with 47 additions and 53 deletions.
  1. +9 −0 app.js
  2. +6 −4 public/css/style.css
  3. +6 −1 routes/events.js
  4. +19 −39 routes/helpers.js
  5. +1 −1 routes/visualize.js
  6. +6 −5 views/dividers.jade
  7. +0 −3 views/layout.jade
View
@@ -70,6 +70,15 @@ checkAuth = function(req, res, next) {
}
};
+isMobile = function(req) {
+
+ var isMobile = /mobile/i.test(req.header('user-agent'));
+ if (isMobile) {
+ console.log('User agent is mobile');
+ }
+ return isMobile;
+};
+
app.get('/login', function(req, res) {
if (req.session.is_logged_in == true) {
console.log('[AUTH] Already logged in, redirecting.');
View
@@ -59,8 +59,11 @@ select {
text-align:center;
}
+#visualize-dividers {
+ border: 1px solid gray;
+}
+
.day-row {
- width:80%;
height:40px;
display:block;
margin:0;
@@ -70,16 +73,15 @@ select {
.day-block {
background-color:#333;
- float:left;
height:40px;
display:block;
- margin-top:1px;
- margin-right:1px;
color:white;
+ float:left;
}
.day-block-empty {
background-color:white;
+ background-color:#c00;
}
.day-block[data-name=sleep] {
View
@@ -12,7 +12,12 @@ module.exports = function(app) {
var context = {
events : events
};
- res.render('index', context);
+
+ if (isMobile(req)) {
+ res.render('mobile/index', context);
+ } else {
+ res.render('index', context);
+ }
});
});
View
@@ -24,7 +24,6 @@ module.exports = function(app) {
var history = [];
db.sort(TIMESTAMPS,
'LIMIT', startIndex, limit,
- 'DESC',
'GET', '#',
'GET', 'event:*->name',
'GET', 'event:*->start',
@@ -85,56 +84,37 @@ module.exports = function(app) {
// of lists; one list for each day of history,
// containing all the events which started on that
// particular day.
+ if (splitAcrossDays && durationMillis + offsetFromEod > 0) {
+ item.duration.millis = -1 * item.offsetFromEod;
+ var newItem = {
+ start : endOfDay + 1,
+ name : name,
+ durationMillis : durationMillis + offsetFromEod
+ };
+
+ console.log('[HELPER] Item duration truncated from '
+ + moment.duration(durationMillis, 'milliseconds').humanize()
+ + ' to '
+ + moment.duration(newItem.durationMillis, 'milliseconds').humanize());
+ console.log('[HELPER] New item inserted with start time '
+ + moment(newItem.start).format('ddd MMM Do, h:mm:ss a'));
+ reply.splice(4 * (i+1), 0, newItem.start, newItem.name, newItem.start, newItem.durationMillis);
+ }
if (dayString != previousDayString) {
// Reset the day string.
previousDayString = dayString;
- // Push the "day" struct.
+ // Append the "day" struct.
history.push(day);
// Start with a blank day again.
day = [];
// Push this item onto the new day.
- day.unshift(item);
- } else if (splitAcrossDays) {
- // Assert: its duration is too long. Need to
- // split across to the next day.
- console.log(JSON.stringify(item));
- var oldDuration = item.duration.millis;
- item.duration.millis = Math.min(item.duration.millis, -1 * item.offsetFromEod);
- if (oldDuration != item.duration.millis) {
- console.log('[HELPER] Truncated duration from ' + oldDuration + ' to ' + item.duration.millis);
- }
-
- // var newStart = item.start + newDuration;
- // var newMoment = moment(newStart);
- // console.log('[HELPER] Start before split = ' + m.format('ddd MMM Do, h:mm:ss a'));
- // console.log('[HELPER] Start after split = ' + newMoment.format('ddd MMM Do, h:mm:ss a'));
- // var newDuration = item.duration.millis + item.offsetFromEod;
- // item.duration.millis = -1 * item.offsetFromEod;
- // day.unshift(item);
-
- // var newItem = {
- // name : item.name,
- // duration : {
- // humanized : moment.duration(newDuration, 'milliseconds').humanize(),
- // millis : newDuration
- // },
- // offsetFromSod : 0,
- // offFromEod : -1,
- // start : {
- // millis : newStart
- // }
- // };
- // history.push(day);
- // day = [];
- // day.unshift(newItem);
- // previousDayString = newMoment.format('YYYY-MM-DD');
- day.unshift(item);
+ day.push(item);
} else {
// Assert: this item was started on the same day as the
// previous; just push it to the same day struct.
- day.unshift(item);
+ day.push(item);
}
} else {
View
@@ -2,7 +2,7 @@ module.exports = function(app) {
app.get('/visualize/stack', checkAuth, function(req, res) {
getHistory(function(history) {
- var context = { history : history };
+ var context = { history : history.reverse() };
res.render('stack', context);
});
});
View
@@ -5,18 +5,19 @@ block content
- var previousDay = "";
each day in historyByDay
- var offset = day[0].offsetFromSod;
- - offset = offset / (36 * 60 * 60 * 10);
+ - offset = offset / (24 * 60 * 60 * 10);
+ - offset = 0;
div.day-row(style='position:relative; left:' + offset + '%')
each item in day
- //- Scale items such that 36 hours = 100%.
+ //- Scale items such that 24 hours = 100%.
- var scale;
- if (item.duration.millis) {
//- Can use the item's duration
- - scale = parseInt(item.duration.millis) / (36 * 60 * 60 * 10);
+ - scale = parseInt(item.duration.millis) / (24 * 60 * 60 * 10);
- } else {
//- Assert: item has no duration, so calculate how long its
//- been so far.
- - scale = (Date.now() - item.start.millis) / (36 * 60 * 60 * 10);
+ - scale = (Date.now() - item.start.millis) / (24 * 60 * 60 * 10);
- }
- var classString = 'day-block';
@@ -32,4 +33,4 @@ block content
data-name=item.name,
data-start-formatted=item.start.formatted,
data-duration-humanized=item.duration.humanized,
- style=styleString)
+ style=styleString) #{item.start.formatted}
View
@@ -11,9 +11,6 @@ html(lang="en")
script(type='text/javascript', src='/js/lib/jquery.js')
script(type='text/javascript', src='/js/lib/jquery-ui.js')
script(type='text/javascript', src='/js/lib/underscore.js')
- script(type='text/javascript', src='/js/lib/json2.js')
- script(type='text/javascript', src='/js/lib/backbone.js')
- script(type='text/javascript', src='/js/lib/deep-model.js')
script(type='text/javascript', src='/js/lib/sprintf.js')
script(type='text/javascript', src='/js/lib/bootstrap.min.js')
script(type='text/javascript', src='/js/dividers.js')

0 comments on commit 943ca82

Please sign in to comment.