Commit e0c43c46ddd7f9488ef076e0c91800e43bd376b3

Authored by randx
1 parent a9a3480d

Added project has_one :last_event assoc. Fixed tab line-height after font-awesom…

…e. Increased projects per page on dashboard
app/assets/stylesheets/gitlab_bootstrap/common.scss
... ... @@ -46,6 +46,9 @@
46 46 color:#888;
47 47 text-shadow:0 1px 1px #fff;
48 48 }
  49 + i[class^="icon-"] {
  50 + line-height:14px;
  51 + }
49 52 }
50 53 &.active {
51 54 > a {
... ...
app/controllers/dashboard_controller.rb
... ... @@ -4,7 +4,7 @@ class DashboardController < ApplicationController
4 4 def index
5 5 @groups = Group.where(id: current_user.projects.pluck(:group_id))
6 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 9 @events = Event.in_projects(current_user.project_ids).limit(20).offset(params[:offset] || 0)
10 10 @last_push = current_user.recent_push
... ...
app/models/project.rb
... ... @@ -25,6 +25,7 @@ class Project < ActiveRecord::Base
25 25 has_many :hooks, dependent: :destroy, class_name: "ProjectHook"
26 26 has_many :wikis, dependent: :destroy
27 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 30 delegate :name, to: :owner, allow_nil: true, prefix: true
30 31  
... ... @@ -141,15 +142,11 @@ class Project < ActiveRecord::Base
141 142 end
142 143  
143 144 def last_activity
144   - events.order("created_at ASC").last
  145 + last_event
145 146 end
146 147  
147 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 150 end
154 151  
155 152 def wiki_notes
... ...
spec/models/project_spec.rb
... ... @@ -169,10 +169,9 @@ describe Project do
169 169  
170 170 describe "last_activity" do
171 171 let(:project) { Factory :project }
172   - let(:last_event) { double }
173 172  
174 173 before do
175   - project.stub_chain(:events, :order).and_return( [ double, double, last_event ] )
  174 + project.stub(last_event: double)
176 175 end
177 176  
178 177 it { project.last_activity.should == last_event }
... ... @@ -182,8 +181,8 @@ describe Project do
182 181 let(:project) { Factory :project }
183 182  
184 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 186 project.last_activity_date.should == last_event.created_at
188 187 end
189 188  
... ...