diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 2476b17e..1c50c66e 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -1,5 +1,6 @@ class DashboardController < ApplicationController def index @projects = current_user.projects.all + @active_projects = @projects.select(&:last_activity_date).sort_by(&:last_activity_date).reverse end end diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb index a94ddfc2..878c877d 100644 --- a/app/helpers/dashboard_helper.rb +++ b/app/helpers/dashboard_helper.rb @@ -1,2 +1,9 @@ module DashboardHelper + def path_to_object(project, object) + case object.class.name.to_s + when "Issue" then project_issues_path(project, project.issues.find(object.id)) + when "Grit::Commit" then project_commit_path(project, project.repo.commits(object.id).first) + else "#" + end + end end diff --git a/app/models/project.rb b/app/models/project.rb index ef7f4e46..54cf77e4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -119,6 +119,26 @@ class Project < ActiveRecord::Base repo rescue false end + def last_activity + updates(1).first + rescue + nil + end + + def last_activity_date + last_activity.try(:created_at) + end + + def updates(n = 3) + [ + fresh_commits(n), + issues.last(n), + notes.fresh.limit(n) + ].compact.flatten.sort do |x, y| + y.created_at <=> x.created_at + end[0..n] + end + def commit(commit_id = nil) if commit_id repo.commits(commit_id).first @@ -131,16 +151,16 @@ class Project < ActiveRecord::Base @heads ||= repo.heads end - def fresh_commits + def fresh_commits(n = 10) commits = heads.map do |h| - repo.commits(h.name, 10) + repo.commits(h.name, n) end.flatten.uniq { |c| c.id } commits.sort! do |x, y| y.committed_date <=> x.committed_date end - commits[0..10] + commits[0..n] end def commits_since(date) diff --git a/app/views/dashboard/index.html.haml b/app/views/dashboard/index.html.haml index f4ce9a17..da0cbc7c 100644 --- a/app/views/dashboard/index.html.haml +++ b/app/views/dashboard/index.html.haml @@ -1 +1,36 @@ -timeline +#dashboard-content.dashboard-content.content + %aside + %h4 + %a.button-small.button-green{:href => ""} New Repository + Your Repositories + %ol.project-list + - @projects.each do |project| + %li + %a{:href => "#"} + %span.arrow → + %span.project-name= project.name + %span.time + %strong Last activity: + = project.last_activity_date ? time_ago_in_words(project.last_activity_date) + " ago" : "Never" + #news-feed.news-feed + %h2.icon + %span> + Dashboard + - @active_projects.each do |project| + .project-box.project-updates.ui-box.ui-box-small.ui-box-big + %h3= project.name + .data + - project.updates.each do |update| + %a.project-update{:href => path_to_object(project, update)} + %img{:src => "http://placehold.it/40x40"} + %span.update-title [#{update.class.name}] added a matcher that helps debugging matching problems + %span.update-author + %strong= update.author.name + authored + = time_ago_in_words(update.created_at) + ago + %br + / .project-update + / .project-updates + / #news-feed +/ #dashboard-content diff --git a/app/views/layouts/_head_panel.html.erb b/app/views/layouts/_head_panel.html.erb index 07de8de4..6dad1084 100644 --- a/app/views/layouts/_head_panel.html.erb +++ b/app/views/layouts/_head_panel.html.erb @@ -10,6 +10,7 @@