Commit a07923a549d53527442967aac9c4baf9596f3c1f
1 parent
b5a5e5a4
Exists in
master
and in
4 other branches
recent radio button
Showing
6 changed files
with
55 additions
and
22 deletions
Show diff stats
app/controllers/projects_controller.rb
@@ -60,24 +60,21 @@ class ProjectsController < ApplicationController | @@ -60,24 +60,21 @@ class ProjectsController < ApplicationController | ||
60 | end | 60 | end |
61 | 61 | ||
62 | def show | 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 | @messages = project.notes.since(@date).order("created_at DESC") | 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 | end | 78 | end |
82 | end | 79 | end |
83 | 80 | ||
@@ -89,11 +86,12 @@ class ProjectsController < ApplicationController | @@ -89,11 +86,12 @@ class ProjectsController < ApplicationController | ||
89 | @date = case params[:view] | 86 | @date = case params[:view] |
90 | when "week" then Date.today - 7.days | 87 | when "week" then Date.today - 7.days |
91 | when "all" then nil | 88 | when "all" then nil |
92 | - else Date.today | 89 | + when "day" then Date.today |
90 | + else nil | ||
93 | end | 91 | end |
94 | 92 | ||
95 | @notes = @project.common_notes.order("created_at DESC") | 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 | @note = Note.new | 95 | @note = Note.new |
98 | end | 96 | end |
99 | 97 |
app/models/note.rb
@@ -24,6 +24,7 @@ class Note < ActiveRecord::Base | @@ -24,6 +24,7 @@ class Note < ActiveRecord::Base | ||
24 | 24 | ||
25 | scope :last_week, where("created_at >= :date", :date => (Date.today - 7.days)) | 25 | scope :last_week, where("created_at >= :date", :date => (Date.today - 7.days)) |
26 | scope :since, lambda { |day| where("created_at >= :date", :date => (day)) } | 26 | scope :since, lambda { |day| where("created_at >= :date", :date => (day)) } |
27 | + scope :fresh, order("created_at DESC") | ||
27 | 28 | ||
28 | mount_uploader :attachment, AttachmentUploader | 29 | mount_uploader :attachment, AttachmentUploader |
29 | end | 30 | end |
app/models/project.rb
@@ -126,6 +126,34 @@ class Project < ActiveRecord::Base | @@ -126,6 +126,34 @@ class Project < ActiveRecord::Base | ||
126 | end | 126 | end |
127 | end | 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 | def tree(fcommit, path = nil) | 157 | def tree(fcommit, path = nil) |
130 | fcommit = commit if fcommit == :head | 158 | fcommit = commit if fcommit == :head |
131 | tree = fcommit.tree | 159 | tree = fcommit.tree |
app/views/projects/show.html.haml
1 | %div | 1 | %div |
2 | - %h2.left Recent history | 2 | + %h2.left History |
3 | .right | 3 | .right |
4 | = form_tag project_path(@project), :method => :get do | 4 | = form_tag project_path(@project), :method => :get do |
5 | .span-2 | 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 | = label_tag "day_view","Today" | 10 | = label_tag "day_view","Today" |
8 | .span-2 | 11 | .span-2 |
9 | = radio_button_tag :view, "week", params[:view] == "week", :onclick => "this.form.submit()", :id => "week_view" | 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,7 +4,10 @@ | ||
4 | .right | 4 | .right |
5 | = form_tag wall_project_path(@project), :method => :get do | 5 | = form_tag wall_project_path(@project), :method => :get do |
6 | .span-2 | 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 | = label_tag "day_view","Today" | 11 | = label_tag "day_view","Today" |
9 | .span-2 | 12 | .span-2 |
10 | = radio_button_tag :view, "week", params[:view] == "week", :onclick => "this.form.submit()", :id => "week_view" | 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 "Projects" do | @@ -73,7 +73,7 @@ describe "Projects" do | ||
73 | end | 73 | end |
74 | 74 | ||
75 | it "should beahave like dashboard" do | 75 | it "should beahave like dashboard" do |
76 | - page.should have_content("Recent history") | 76 | + page.should have_content("History") |
77 | end | 77 | end |
78 | 78 | ||
79 | end | 79 | end |