From c94159ab089fe964263643ffc7e881ba8cac3f23 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 1 Mar 2012 20:40:32 +0200 Subject: [PATCH] improved dashboard --- app/assets/stylesheets/common.scss | 20 +++++++++----- app/controllers/dashboard_controller.rb | 6 ++--- app/models/project.rb | 24 +++++------------ app/views/dashboard/_events_feed.html.haml | 21 ++------------- app/views/dashboard/index.html.haml | 9 ++++--- app/views/events/_event.html.haml | 31 ++++++++++++++++++++++ 6 files changed, 62 insertions(+), 49 deletions(-) create mode 100644 app/views/events/_event.html.haml diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index 5670f1e0..44f0a417 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -615,6 +615,7 @@ p.time { margin:auto; .wll { + padding:5px; border:none; &:hover { background:none; @@ -623,12 +624,19 @@ p.time { h4 { color:#666; } + &.event_feed { + min-height:40px; + border-bottom:1px solid #eee; + .avatar { + width:32px; + } + ul { + margin-left:50px; + .avatar { + width:24px; + } + } + } } } } - -.event_feed { - ul { - margin-left:50px; - } -} diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index fe9604ec..8fa41298 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -4,12 +4,12 @@ class DashboardController < ApplicationController def index @projects = current_user.projects.all - @active_projects = @projects.select(&:repo_exists?).select(&:last_activity_date_cached).sort_by(&:last_activity_date_cached).reverse + @active_projects = @projects.select(&:last_activity_date).sort_by(&:last_activity_date).reverse - @merge_requests = MergeRequest.where("author_id = :id or assignee_id = :id", :id => current_user.id).opened.order("created_at DESC").limit(10) + @merge_requests = MergeRequest.where("author_id = :id or assignee_id = :id", :id => current_user.id).opened.order("created_at DESC").limit(5) @user = current_user - @issues = current_user.assigned_issues.opened.order("created_at DESC").limit(10) + @issues = current_user.assigned_issues.opened.order("created_at DESC").limit(5) @issues = @issues.includes(:author, :project) @events = Event.where(:project_id => @projects.map(&:id)).recent.limit(20) diff --git a/app/models/project.rb b/app/models/project.rb index c9b6f73b..7a99ee6f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -277,31 +277,21 @@ class Project < ActiveRecord::Base end def last_activity - updates(1).first + events.last rescue nil end def last_activity_date - last_activity.try(:created_at) + if events.last + events.last.created_at + else + updated_at + end end def last_activity_date_cached(expire = 1.hour) - activity_date_key = "project_#{id}_activity_date" - - cached_activities = Rails.cache.read(activity_date_key) - if cached_activities - activity_date = if cached_activities == "Never" - nil - else - cached_activities - end - else - activity_date = last_activity_date - Rails.cache.write(activity_date_key, activity_date || "Never", :expires_in => expire) - end - - activity_date + last_activity_date end # Get project updates from cache diff --git a/app/views/dashboard/_events_feed.html.haml b/app/views/dashboard/_events_feed.html.haml index e3413195..97659753 100644 --- a/app/views/dashboard/_events_feed.html.haml +++ b/app/views/dashboard/_events_feed.html.haml @@ -1,19 +1,2 @@ -- @events.each do |event| - .wll.event_feed - - if event.push? - - if event.new_branch? - User pushed new branch - - else - = image_tag gravatar_icon(event.pusher_email), :class => "avatar" - #{event.pusher_name} pushed to - = link_to project_commits_path(event.project, :ref => event.branch_name) do - %strong= event.branch_name - %span.cgray - = time_ago_in_words(event.created_at) - ago. - - if event.commits.count > 1 - = link_to compare_project_commits_path(event.project, :from => event.commits.first.prev_commit_id, :to => event.commits.last.id) do - Compare #{event.commits.first.commit.id[0..8]}...#{event.commits.last.id[0..8]} - - @project = event.project - %ul.unstyled - = render event.commits += render @events + diff --git a/app/views/dashboard/index.html.haml b/app/views/dashboard/index.html.haml index 27490e40..c9963d74 100644 --- a/app/views/dashboard/index.html.haml +++ b/app/views/dashboard/index.html.haml @@ -8,7 +8,7 @@ %div.dashboard_category %h3 - Projects + = link_to "Projects" , "#projects", :id => "projects" %small ( most recent ) @@ -34,7 +34,8 @@ - unless @merge_requests.blank? %div.dashboard_category %h3 - Merge Requests + = link_to "Merge Requests" , "#merge_requests", :id => "merge_requests" + %small ( authored or assigned to you ) %strong.right = link_to dashboard_merge_requests_path do @@ -46,7 +47,7 @@ - unless @issues.blank? %div.dashboard_category %h3 - Issues + = link_to "Issues" , "#issues", :id => "issues" %small ( assigned to you ) %strong.right = link_to dashboard_merge_requests_path do @@ -58,7 +59,7 @@ - unless @events.blank? %div.dashboard_category %h3 - Activities + = link_to "Activities" , "#activities", :id => "activities" %hr .row diff --git a/app/views/events/_event.html.haml b/app/views/events/_event.html.haml new file mode 100644 index 00000000..e5d24077 --- /dev/null +++ b/app/views/events/_event.html.haml @@ -0,0 +1,31 @@ +.wll.event_feed + - if event.push? + - if event.new_branch? + = image_tag gravatar_icon(event.pusher_email), :class => "avatar" + %strong #{event.pusher_name} + pushed new branch + = link_to project_commits_path(event.project, :ref => event.branch_name) do + %strong= event.branch_name + at + %strong= link_to event.project.name, event.project + %span.cgray + = time_ago_in_words(event.created_at) + ago. + - else + = image_tag gravatar_icon(event.pusher_email), :class => "avatar" + %strong #{event.pusher_name} + pushed to + = link_to project_commits_path(event.project, :ref => event.branch_name) do + %strong= event.branch_name + at + %strong= link_to event.project.name, event.project + %span.cgray + = time_ago_in_words(event.created_at) + ago. + - if event.commits.count > 1 + = link_to compare_project_commits_path(event.project, :from => event.commits.first.prev_commit_id, :to => event.commits.last.id) do + Compare #{event.commits.first.commit.id[0..8]}...#{event.commits.last.id[0..8]} + - @project = event.project + %ul.unstyled + = render event.commits +