Commit a07923a549d53527442967aac9c4baf9596f3c1f

Authored by gitlabhq
1 parent b5a5e5a4

recent radio button

app/controllers/projects_controller.rb
... ... @@ -60,24 +60,21 @@ class ProjectsController < ApplicationController
60 60 end
61 61  
62 62 def show
63   - if @project.repo_exists?
64   - @date = case params[:view]
65   - when "week" then Date.today - 7.days
66   - else Date.today
67   - end.at_beginning_of_day
68   -
69   - @heads = @project.repo.heads
70   - @commits = @heads.map do |h|
71   - @project.repo.log(h.name, nil, :since => @date)
72   - end.flatten.uniq { |c| c.id }
73   -
74   - @commits.sort! do |x, y|
75   - y.committed_date <=> x.committed_date
76   - end
  63 + return render "projects/empty" unless @project.repo_exists?
  64 + @date = case params[:view]
  65 + when "week" then Date.today - 7.days
  66 + when "day" then Date.today
  67 + else nil
  68 + end
  69 +
  70 + if @date
  71 + @date = @date.at_beginning_of_day
77 72  
  73 + @commits = @project.commits_since(@date)
78 74 @messages = project.notes.since(@date).order("created_at DESC")
79   - else
80   - return render "projects/empty"
  75 + else
  76 + @commits = @project.fresh_commits
  77 + @messages = project.notes.fresh.limit(10)
81 78 end
82 79 end
83 80  
... ... @@ -89,11 +86,12 @@ class ProjectsController &lt; ApplicationController
89 86 @date = case params[:view]
90 87 when "week" then Date.today - 7.days
91 88 when "all" then nil
92   - else Date.today
  89 + when "day" then Date.today
  90 + else nil
93 91 end
94 92  
95 93 @notes = @project.common_notes.order("created_at DESC")
96   - @notes = @notes.since(@date.at_beginning_of_day) if @date
  94 + @notes = @date ? @notes.since(@date.at_beginning_of_day) : @notes.fresh.limit(10)
97 95 @note = Note.new
98 96 end
99 97  
... ...
app/models/note.rb
... ... @@ -24,6 +24,7 @@ class Note &lt; ActiveRecord::Base
24 24  
25 25 scope :last_week, where("created_at >= :date", :date => (Date.today - 7.days))
26 26 scope :since, lambda { |day| where("created_at >= :date", :date => (day)) }
  27 + scope :fresh, order("created_at DESC")
27 28  
28 29 mount_uploader :attachment, AttachmentUploader
29 30 end
... ...
app/models/project.rb
... ... @@ -126,6 +126,34 @@ class Project &lt; ActiveRecord::Base
126 126 end
127 127 end
128 128  
  129 + def heads
  130 + @heads ||= repo.heads
  131 + end
  132 +
  133 + def fresh_commits
  134 + commits = heads.map do |h|
  135 + repo.commits(h.name, 10)
  136 + end.flatten.uniq { |c| c.id }
  137 +
  138 + commits.sort! do |x, y|
  139 + y.committed_date <=> x.committed_date
  140 + end
  141 +
  142 + commits[0..10]
  143 + end
  144 +
  145 + def commits_since(date)
  146 + commits = heads.map do |h|
  147 + repo.log(h.name, nil, :since => date)
  148 + end.flatten.uniq { |c| c.id }
  149 +
  150 + commits.sort! do |x, y|
  151 + y.committed_date <=> x.committed_date
  152 + end
  153 +
  154 + commits
  155 + end
  156 +
129 157 def tree(fcommit, path = nil)
130 158 fcommit = commit if fcommit == :head
131 159 tree = fcommit.tree
... ...
app/views/projects/show.html.haml
1 1 %div
2   - %h2.left Recent history
  2 + %h2.left History
3 3 .right
4 4 = form_tag project_path(@project), :method => :get do
5 5 .span-2
6   - = radio_button_tag :view, "day", (params[:view] || "day") == "day", :onclick => "this.form.submit()", :id => "day_view"
  6 + = radio_button_tag :view, "recent", (params[:view] || "recent") == "recent", :onclick => "this.form.submit()", :id => "recent_view"
  7 + = label_tag "recent_view","Recent"
  8 + .span-2
  9 + = radio_button_tag :view, "day", params[:view] == "day", :onclick => "this.form.submit()", :id => "day_view"
7 10 = label_tag "day_view","Today"
8 11 .span-2
9 12 = radio_button_tag :view, "week", params[:view] == "week", :onclick => "this.form.submit()", :id => "week_view"
... ...
app/views/projects/wall.html.haml
... ... @@ -4,7 +4,10 @@
4 4 .right
5 5 = form_tag wall_project_path(@project), :method => :get do
6 6 .span-2
7   - = radio_button_tag :view, "day", (params[:view] || "day") == "day", :onclick => "this.form.submit()", :id => "day_view"
  7 + = radio_button_tag :view, "recent", (params[:view] || "recent") == "recent", :onclick => "this.form.submit()", :id => "recent_view"
  8 + = label_tag "recent_view","Recent"
  9 + .span-2
  10 + = radio_button_tag :view, "day", params[:view] == "day", :onclick => "this.form.submit()", :id => "day_view"
8 11 = label_tag "day_view","Today"
9 12 .span-2
10 13 = radio_button_tag :view, "week", params[:view] == "week", :onclick => "this.form.submit()", :id => "week_view"
... ...
spec/requests/projects_spec.rb
... ... @@ -73,7 +73,7 @@ describe &quot;Projects&quot; do
73 73 end
74 74  
75 75 it "should beahave like dashboard" do
76   - page.should have_content("Recent history")
  76 + page.should have_content("History")
77 77 end
78 78  
79 79 end
... ...