Commit e0c43c46ddd7f9488ef076e0c91800e43bd376b3
1 parent
a9a3480d
Exists in
master
and in
4 other branches
Added project has_one :last_event assoc. Fixed tab line-height after font-awesom…
…e. Increased projects per page on dashboard
Showing
4 changed files
with
10 additions
and
11 deletions
Show diff stats
app/assets/stylesheets/gitlab_bootstrap/common.scss
app/controllers/dashboard_controller.rb
| @@ -4,7 +4,7 @@ class DashboardController < ApplicationController | @@ -4,7 +4,7 @@ class DashboardController < ApplicationController | ||
| 4 | def index | 4 | def index |
| 5 | @groups = Group.where(id: current_user.projects.pluck(:group_id)) | 5 | @groups = Group.where(id: current_user.projects.pluck(:group_id)) |
| 6 | @projects = current_user.projects_with_events | 6 | @projects = current_user.projects_with_events |
| 7 | - @projects = @projects.page(params[:page]).per(20) | 7 | + @projects = @projects.page(params[:page]).per(30) |
| 8 | 8 | ||
| 9 | @events = Event.in_projects(current_user.project_ids).limit(20).offset(params[:offset] || 0) | 9 | @events = Event.in_projects(current_user.project_ids).limit(20).offset(params[:offset] || 0) |
| 10 | @last_push = current_user.recent_push | 10 | @last_push = current_user.recent_push |
app/models/project.rb
| @@ -25,6 +25,7 @@ class Project < ActiveRecord::Base | @@ -25,6 +25,7 @@ class Project < ActiveRecord::Base | ||
| 25 | has_many :hooks, dependent: :destroy, class_name: "ProjectHook" | 25 | has_many :hooks, dependent: :destroy, class_name: "ProjectHook" |
| 26 | has_many :wikis, dependent: :destroy | 26 | has_many :wikis, dependent: :destroy |
| 27 | has_many :protected_branches, dependent: :destroy | 27 | has_many :protected_branches, dependent: :destroy |
| 28 | + has_one :last_event, class_name: 'Event', order: 'events.created_at DESC', foreign_key: 'project_id' | ||
| 28 | 29 | ||
| 29 | delegate :name, to: :owner, allow_nil: true, prefix: true | 30 | delegate :name, to: :owner, allow_nil: true, prefix: true |
| 30 | 31 | ||
| @@ -141,15 +142,11 @@ class Project < ActiveRecord::Base | @@ -141,15 +142,11 @@ class Project < ActiveRecord::Base | ||
| 141 | end | 142 | end |
| 142 | 143 | ||
| 143 | def last_activity | 144 | def last_activity |
| 144 | - events.order("created_at ASC").last | 145 | + last_event |
| 145 | end | 146 | end |
| 146 | 147 | ||
| 147 | def last_activity_date | 148 | def last_activity_date |
| 148 | - if events.last | ||
| 149 | - events.last.created_at | ||
| 150 | - else | ||
| 151 | - updated_at | ||
| 152 | - end | 149 | + last_event.try(:created_at) || updated_at |
| 153 | end | 150 | end |
| 154 | 151 | ||
| 155 | def wiki_notes | 152 | def wiki_notes |
spec/models/project_spec.rb
| @@ -169,10 +169,9 @@ describe Project do | @@ -169,10 +169,9 @@ describe Project do | ||
| 169 | 169 | ||
| 170 | describe "last_activity" do | 170 | describe "last_activity" do |
| 171 | let(:project) { Factory :project } | 171 | let(:project) { Factory :project } |
| 172 | - let(:last_event) { double } | ||
| 173 | 172 | ||
| 174 | before do | 173 | before do |
| 175 | - project.stub_chain(:events, :order).and_return( [ double, double, last_event ] ) | 174 | + project.stub(last_event: double) |
| 176 | end | 175 | end |
| 177 | 176 | ||
| 178 | it { project.last_activity.should == last_event } | 177 | it { project.last_activity.should == last_event } |
| @@ -182,8 +181,8 @@ describe Project do | @@ -182,8 +181,8 @@ describe Project do | ||
| 182 | let(:project) { Factory :project } | 181 | let(:project) { Factory :project } |
| 183 | 182 | ||
| 184 | it 'returns the creation date of the project\'s last event if present' do | 183 | it 'returns the creation date of the project\'s last event if present' do |
| 185 | - last_event = double(created_at: 'now') | ||
| 186 | - project.stub(:events).and_return( [double, double, last_event] ) | 184 | + last_event = double(created_at: Time.now) |
| 185 | + project.stub(last_event: last_event) | ||
| 187 | project.last_activity_date.should == last_event.created_at | 186 | project.last_activity_date.should == last_event.created_at |
| 188 | end | 187 | end |
| 189 | 188 |