Skip to content
Browse files

[#2373] Added a box for the last 5 Status Updates to the project home…

…page.

* Requires a core hook :view_projects_show_left
* Also adds the redmine_status.css to the HEAD of each page

Signed-off-by: Brian Terlson <btthalion@gmail.com>
  • Loading branch information...
1 parent c5be609 commit 10ab6f2feb027ef13980c5a715d1aa4349c887ed @edavis10 edavis10 committed with Apr 25, 2009
View
6 app/models/status.rb
@@ -66,11 +66,11 @@ def recipients
end
end
- def self.recent_updates_for(project=nil)
+ def self.recent_updates_for(project=nil, number=100)
if project
- return self.visible_to_user(User.current, project).recent(100).by_date.for_project(project)
+ return self.visible_to_user(User.current, project).recent(number).by_date.for_project(project)
else
- return self.visible_to_user(User.current, project).recent(100).by_date
+ return self.visible_to_user(User.current, project).recent(number).by_date
end
end
View
2 assets/stylesheets/redmine_status.css
@@ -1,7 +1,7 @@
.status_user { font-weight: bold; }
.status_message p { display: inline; }
.time { font-weight: normal; font-size: 0.9em; }
-img.gravatar { float:left; margin: 0 10px 0 0;}
+.status_user img.gravatar { float:left; margin: 0 10px 0 0;}
.smaller_project {font-size: 80%;}
.icon-news { background-image: url(../../../images/news.png); }
.icon-search { background-image: url(../images/magnifier.png); }
View
13 features/recent_statuses.feature
@@ -0,0 +1,13 @@
+Feature: Recent Statuses
+ As a user
+ I want to see recent statuses on different pages
+ So I don't always have to go to the status plugin to see updates
+
+ Scenario: Recent statuses on the Project Overview
+ Given I am logged in
+ And I am a member of a project
+ And there are "6" statuses
+ And I am on the Project Overview page
+
+ Then I should see "Status Updates"
+ And I should see "5" updates in the left content
View
14 features/step_definitions/status_steps.rb
@@ -70,6 +70,14 @@ def strip_hash_from_hashtag(hashtag)
visit url_for(:controller => 'statuses', :action => 'search')
end
+Given /^I am on the Project Overview page$/ do
+ unless @project
+ @project = make_project_with_enabled_modules
+ end
+
+ visit url_for(:controller => 'projects', :action => 'show', :id => @project.id)
+end
+
Given /^there are "(.*)" statuses$/ do |number|
number.to_i.times do
@@ -200,6 +208,12 @@ def strip_hash_from_hashtag(hashtag)
current_email.body.should have_tag('p.status_message', :count => count.to_i)
end
+Then /^I should see "(.*)" updates in the left content$/ do |count|
+ response.should have_tag("div.box#statuses") do
+ with_tag("dd.status_message", :count => count.to_i)
+ end
+end
+
Then /^I should see a "top" menu item called "Status updates"$/ do
response.should have_tag("div#top-menu") do
with_tag("a", "Status updates")
View
3 init.rb
@@ -9,6 +9,9 @@
ActiveRecord::Base.observers << :status_observer
end
+require 'status_layout_hooks'
+require 'status_project_hooks'
+
Redmine::Plugin.register :status do
name 'Redmine Status Updates'
author 'Brian Terlson'
View
5 lib/status_layout_hooks.rb
@@ -0,0 +1,5 @@
+class StatusProjectHooks < Redmine::Hook::ViewListener
+ def view_layouts_base_html_head(context = {})
+ return stylesheet_link_tag("redmine_status.css", :plugin => "redmine_status")
+ end
+end
View
37 lib/status_project_hooks.rb
@@ -0,0 +1,37 @@
+class StatusProjectHooks < Redmine::Hook::ViewListener
+ include GravatarHelper::PublicMethods
+ include StatusesHelper
+
+ def view_projects_show_left(context = {})
+
+ if context[:project]
+ @project = context[:project]
+
+ if @project.module_enabled?(:statuses) && authorize_for('statuses', 'index')
+
+ html = '<div class="box" id="statuses">'
+ html += '<h3 class="icon22 icon22-users">Developer Status</h3>'
+
+ Status.recent_updates_for(@project, 5).each do |status|
+ html += <<EOHTML
+ <div>
+ <dl>
+ <dt class="status_user">#{ avatar(status.user) }#{h status.user.name}</dt>
+ <dd class="status_message">
+ <span class="time">#{format_time(status.created_at, true)}:</span>
+ <p>#{format_status_message(status)}</p>
+ </dd>
+ </dl>
+ </div>
+ <div style="clear:both;"></div>
+EOHTML
+ end
+ html += link_to("View all statuses", :controller => 'statuses', :action => 'index', :id => @project)
+ html += '</div>'
+
+ return html
+ end
+ end
+ end
+
+end
View
65 spec/lib/status_project_hooks_spec.rb
@@ -0,0 +1,65 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe StatusProjectHooks, "#view_projects_show_left", :type => :view do
+ include Redmine::Hook::Helper
+ include ActionView::Helpers::UrlHelper
+ include ActionController::UrlWriter
+
+ before(:each) do
+ @project = mock_model(Project, :module_enabled? => true)
+ @context = { :project => @project }
+
+ @current_user = mock_model(User, :name => 'Test', :admin? => false, :logged? => true, :language => :en, :allowed_to? => true, :time_zone => nil)
+ User.stub!(:current).and_return(@current_user)
+
+ Status.stub!(:recent_updates_for).and_return([])
+ # Hack to make RSpec play nicely with call_hook's default contexts
+ self.stub!(:controller).and_return(@controller)
+ end
+
+ it "should do nothing if the Status module isn't active" do
+ @project.should_receive(:module_enabled?).with(:statuses).and_return(nil)
+ response = call_hook(:view_projects_show_left, @context)
+ response.should be_empty
+ end
+
+ it "should do nothing if the user doesn't have permission to view_statuses" do
+ StatusProjectHooks.instance.should_receive(:authorize_for).with('statuses', 'index').and_return(false)
+ response = call_hook(:view_projects_show_left, @context)
+ response.should be_empty
+ end
+
+ describe 'with the Status module enabled and a valid user' do
+ it 'should render a box div' do
+ response = call_hook(:view_projects_show_left, @context)
+ response.should have_tag('div.box#statuses')
+ end
+
+ it 'should render the latest 5 statuses' do
+ Status.should_receive(:recent_updates_for).with(@project, 5).and_return do
+ r = []
+ 5.times do |i|
+ r << Status.new(:user => @current_user, :message => "Message #{i}")
+ end
+ r
+ end
+
+ response = call_hook(:view_projects_show_left, @context)
+ response.should have_tag("div.box#statuses") do
+ with_tag("dd.status_message", :count => 5)
+ end
+ end
+
+ it 'should link to view all statuses' do
+ response = call_hook(:view_projects_show_left, @context)
+ response.should have_tag('a[href=?]',
+ url_for(:controller => 'statuses',
+ :action => 'index',
+ :id => @project.id,
+ :only_path => true),
+ 'View all statuses')
+ end
+
+ end
+end
+

0 comments on commit 10ab6f2

Please sign in to comment.
Something went wrong with that request. Please try again.