From defc4529afbed56a9c2ab906dee1b97eb2381066 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 30 Sep 2012 22:47:59 -0500 Subject: make the github stuff look a lot nicer --- root/static/github_activity.js | 72 ++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 27 deletions(-) (limited to 'root/static/github_activity.js') diff --git a/root/static/github_activity.js b/root/static/github_activity.js index a20dd12..5c4cc55 100644 --- a/root/static/github_activity.js +++ b/root/static/github_activity.js @@ -13,42 +13,34 @@ var GithubActivity = (function($, _) { var self = {}, gh = 'http://github.com/', - default_template = '
  • \ + default_template = '
  • \ <% if (type == "PushEvent") { %> \ - <%= actor %> \ - pushed \ - to \ - <%= repository.name %> on \ - <% print(created_at.substring(0, 10)); %>. \ - \ + <%= sha[0].substring(0,6) %> \ +
    <%= (sha[2].split("\\n"))[0] %>
    <% }); %>\ <% } else if (type == "GistEvent") { %> \ - <%= actor %> \ - <%= payload.action %>d gist: \ - <%= payload.desc %>.\ + <%= payload.action %>d gist: \ + <%= payload.desc %> \ <% } else if (type == "CreateEvent") { %> \ - <%= actor %> \ - created <%= payload.ref_type %> \ + created <%= payload.ref_type %> \ <%= payload.ref %> in \ - <%= repository.name %> on \ - <% print(created_at.substring(0, 10)); %>. \ + <%= repository.name %> \ <% } else if (type == "PullRequestEvent") { %> \ - <%= actor %> \ - <%= payload.action %> pull request \ + <%= payload.action %> pull request \ \ #<%= payload.number %>: <%= payload.pull_request.title %> \ - on <% print(created_at.substring(0, 10)); %>. \ <% } else if (type == "IssueCommentEvent") { %> \ - <%= actor %> \ - commented on issue \ + commented on issue \ #<% print(url.replace(/.*\\/issues\\/(\\d+)#.*/, "$1")); %> \ - in <%= repository.name %> \ - on <% print(created_at.substring(0, 10)); %>. \ + in \ + <%= repository.name %> \ <% } else { %> \ - Unknown event type <% type %>. \ + Unknown event type <% type %> \ <% } %>\
  • '; @@ -60,12 +52,38 @@ var GithubActivity = (function($, _) { var url = 'https://github.com/' + username + '.json?callback=?', template = $(tmpl_selector).html() || default_template, - compiled = _.template(template); + compiled = _.template(template), + current_date = '', + $current_list; $.getJSON(url, {}, function (data) { $.each(data.slice(0, 6), function(index, commit) { - $(selector).append(compiled(commit)); + var date = commit.created_at.substring(0, 10); + if (date != current_date) { + if (current_date) { + var $new_item = $('
  • '); + $new_item.append('
    ' + current_date + '
    '); + var $div = $('
    '); + $div.append($current_list); + $new_item.append($div); + $(selector).append($new_item); + } + + $current_list = $(''); + current_date = date; + } + var $action = $(compiled(commit)); + if (index % 2) { + $action.addClass('odd') + } + $current_list.append($action); }); + var $new_item = $('
  • '); + $new_item.append('
    ' + current_date + '
    '); + var $div = $('
    '); + $div.append($current_list); + $new_item.append($div); + $(selector).append($new_item); }); }; -- cgit v1.2.3-54-g00ecf