Sort writeboards in basecamp by date
Saturday, 13 December 2008
As far as I know there is general consensus that writeboards suck. Still they exist, so we need to get along with them. One thing I find particularly annoying is the lack of a sorting function in the overview of existing writeboards.
Fortunately, basecamp is generous and provides the date of the last update in a human friendly way, e.g. “Updated 1 day ago” or “Updated 2 months ago”. So I just have to read these strings, convert them to something machine friendly in terms of easy comparability and rearrange the list of writeboards to reflect this order.
And here is the piece of code that does just that.
javascript:
weights = {};
weights['hour'] = 1;
weights['day'] = 24 * weights['hour'];
weights['month'] = weights['day'] * 30;
for (unit in weights)
weights[unit + 's'] = weights[unit];
var writeboards = [];
$$('ul#writeboards > li').each(function(writeboard) {
ago = writeboard.select('span.detail').first().innerHTML.match(/(\d+) (\w+)/);
writeboards.push({ id: writeboard.id, updated: weights[ago[2]] * parseInt(ago[1]) });
});
writeboards.sort(function(a, b) { return a['updated'] < b['updated'] ? -1 : 1 });
writeboards.each(function(writeboard) {
$('writeboards').appendChild($(writeboard['id']));
});
void(0);
A Short History of Nearly Everything
I Am a Strange Loop
Seven Languages in Seven Weeks