Commit 485c5199b7ea01b85bdacb15a41bcfb18451597c
1 parent
267bd606
Exists in
master
and in
4 other branches
user dashboard
Showing
7 changed files
with
73 additions
and
4 deletions
Show diff stats
app/controllers/dashboard_controller.rb
app/helpers/dashboard_helper.rb
| 1 | 1 | module DashboardHelper |
| 2 | + def path_to_object(project, object) | |
| 3 | + case object.class.name.to_s | |
| 4 | + when "Issue" then project_issues_path(project, project.issues.find(object.id)) | |
| 5 | + when "Grit::Commit" then project_commit_path(project, project.repo.commits(object.id).first) | |
| 6 | + else "#" | |
| 7 | + end | |
| 8 | + end | |
| 2 | 9 | end | ... | ... |
app/models/project.rb
| ... | ... | @@ -119,6 +119,26 @@ class Project < ActiveRecord::Base |
| 119 | 119 | repo rescue false |
| 120 | 120 | end |
| 121 | 121 | |
| 122 | + def last_activity | |
| 123 | + updates(1).first | |
| 124 | + rescue | |
| 125 | + nil | |
| 126 | + end | |
| 127 | + | |
| 128 | + def last_activity_date | |
| 129 | + last_activity.try(:created_at) | |
| 130 | + end | |
| 131 | + | |
| 132 | + def updates(n = 3) | |
| 133 | + [ | |
| 134 | + fresh_commits(n), | |
| 135 | + issues.last(n), | |
| 136 | + notes.fresh.limit(n) | |
| 137 | + ].compact.flatten.sort do |x, y| | |
| 138 | + y.created_at <=> x.created_at | |
| 139 | + end[0..n] | |
| 140 | + end | |
| 141 | + | |
| 122 | 142 | def commit(commit_id = nil) |
| 123 | 143 | if commit_id |
| 124 | 144 | repo.commits(commit_id).first |
| ... | ... | @@ -131,16 +151,16 @@ class Project < ActiveRecord::Base |
| 131 | 151 | @heads ||= repo.heads |
| 132 | 152 | end |
| 133 | 153 | |
| 134 | - def fresh_commits | |
| 154 | + def fresh_commits(n = 10) | |
| 135 | 155 | commits = heads.map do |h| |
| 136 | - repo.commits(h.name, 10) | |
| 156 | + repo.commits(h.name, n) | |
| 137 | 157 | end.flatten.uniq { |c| c.id } |
| 138 | 158 | |
| 139 | 159 | commits.sort! do |x, y| |
| 140 | 160 | y.committed_date <=> x.committed_date |
| 141 | 161 | end |
| 142 | 162 | |
| 143 | - commits[0..10] | |
| 163 | + commits[0..n] | |
| 144 | 164 | end |
| 145 | 165 | |
| 146 | 166 | def commits_since(date) | ... | ... |
app/views/dashboard/index.html.haml
| 1 | -timeline | |
| 1 | +#dashboard-content.dashboard-content.content | |
| 2 | + %aside | |
| 3 | + %h4 | |
| 4 | + %a.button-small.button-green{:href => ""} New Repository | |
| 5 | + Your Repositories | |
| 6 | + %ol.project-list | |
| 7 | + - @projects.each do |project| | |
| 8 | + %li | |
| 9 | + %a{:href => "#"} | |
| 10 | + %span.arrow → | |
| 11 | + %span.project-name= project.name | |
| 12 | + %span.time | |
| 13 | + %strong Last activity: | |
| 14 | + = project.last_activity_date ? time_ago_in_words(project.last_activity_date) + " ago" : "Never" | |
| 15 | + #news-feed.news-feed | |
| 16 | + %h2.icon | |
| 17 | + %span> | |
| 18 | + Dashboard | |
| 19 | + - @active_projects.each do |project| | |
| 20 | + .project-box.project-updates.ui-box.ui-box-small.ui-box-big | |
| 21 | + %h3= project.name | |
| 22 | + .data | |
| 23 | + - project.updates.each do |update| | |
| 24 | + %a.project-update{:href => path_to_object(project, update)} | |
| 25 | + %img{:src => "http://placehold.it/40x40"} | |
| 26 | + %span.update-title [#{update.class.name}] added a matcher that helps debugging matching problems | |
| 27 | + %span.update-author | |
| 28 | + %strong= update.author.name | |
| 29 | + authored | |
| 30 | + = time_ago_in_words(update.created_at) | |
| 31 | + ago | |
| 32 | + %br | |
| 33 | + / .project-update | |
| 34 | + / .project-updates | |
| 35 | + / #news-feed | |
| 36 | +/ #dashboard-content | ... | ... |
app/views/layouts/_head_panel.html.erb
| ... | ... | @@ -10,6 +10,7 @@ |
| 10 | 10 | </div> |
| 11 | 11 | <div class="right"> |
| 12 | 12 | <%= link_to truncate(@project.name, :length => 20), project_path(@project), :class => "current button" if @project && !@project.new_record? %> |
| 13 | + <%= link_to 'Dashboard', dashboard_path, :class => current_page?(dashboard_path) ? "current button" : "button" %> | |
| 13 | 14 | <%= link_to 'Projects', projects_path, :class => current_page?(projects_path) ? "current button" : "button" %> |
| 14 | 15 | <%= link_to('Admin', admin_root_path, :class => admin_namespace? ? "current button" : "button" ) if current_user.is_admin? %> |
| 15 | 16 | <%= link_to profile_path, :class => ((controller.controller_name == "keys" || controller.controller_name == "profile") ? "current button" : "button") do %> | ... | ... |
config/routes.rb
| ... | ... | @@ -15,6 +15,7 @@ Gitlab::Application.routes.draw do |
| 15 | 15 | put "profile/password", :to => "profile#password_update" |
| 16 | 16 | put "profile/edit", :to => "profile#social_update" |
| 17 | 17 | get "profile", :to => "profile#show" |
| 18 | + get "dashboard", :to => "dashboard#index" | |
| 18 | 19 | #get "profile/:id", :to => "profile#show" |
| 19 | 20 | |
| 20 | 21 | resources :projects, :only => [:new, :create, :index] | ... | ... |