Refactor: rename TimelogController#details to #index

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4235 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-10-06 18:23:45 +00:00
parent c43ef6e769
commit 2ecca7e4df
9 changed files with 51 additions and 52 deletions

View File

@ -18,9 +18,9 @@
class TimelogController < ApplicationController
menu_item :issues
before_filter :find_project, :authorize, :only => [:edit, :destroy]
before_filter :find_optional_project, :only => [:details]
before_filter :find_optional_project, :only => [:index]
verify :method => :post, :only => :destroy, :redirect_to => { :action => :details }
verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
helper :sort
include SortHelper
@ -29,7 +29,7 @@ class TimelogController < ApplicationController
helper :custom_fields
include CustomFieldsHelper
def details
def index
sort_init 'spent_on', 'desc'
sort_update 'spent_on' => 'spent_on',
'user' => 'user_id',
@ -95,7 +95,7 @@ class TimelogController < ApplicationController
if request.post? and @time_entry.save
flash[:notice] = l(:notice_successful_update)
redirect_back_or_default :action => 'details', :project_id => @time_entry.project
redirect_back_or_default :action => 'index', :project_id => @time_entry.project
return
end
end
@ -110,7 +110,7 @@ class TimelogController < ApplicationController
end
redirect_to :back
rescue ::ActionController::RedirectBackError
redirect_to :action => 'details', :project_id => @time_entry.project
redirect_to :action => 'index', :project_id => @time_entry.project
end
private

View File

@ -32,7 +32,7 @@
<th class="category"><%=l(:field_category)%>:</th><td class="category"><%=h @issue.category ? @issue.category.name : "-" %></td>
<% if User.current.allowed_to?(:view_time_entries, @project) %>
<th class="spent-time"><%=l(:label_spent_time)%>:</th>
<td class="spent-time"><%= @issue.spent_hours > 0 ? (link_to l_hours(@issue.spent_hours), {:controller => 'timelog', :action => 'details', :project_id => @project, :issue_id => @issue}) : "-" %></td>
<td class="spent-time"><%= @issue.spent_hours > 0 ? (link_to l_hours(@issue.spent_hours), {:controller => 'timelog', :action => 'index', :project_id => @project, :issue_id => @issue}) : "-" %></td>
<% end %>
</tr>
<tr>

View File

@ -67,7 +67,7 @@
<% if @total_hours && User.current.allowed_to?(:view_time_entries, @project) %>
<h3><%= l(:label_spent_time) %></h3>
<p><span class="icon icon-time"><%= l_hours(@total_hours) %></span></p>
<p><%= link_to(l(:label_details), {:controller => 'timelog', :action => 'details', :project_id => @project}) %> |
<p><%= link_to(l(:label_details), {:controller => 'timelog', :action => 'index', :project_id => @project}) %> |
<%= link_to(l(:label_report), {:controller => 'time_entry_reports', :action => 'report', :project_id => @project}) %></p>
<% end %>
<%= call_hook(:view_projects_show_sidebar_bottom, :project => @project) %>

View File

@ -28,8 +28,8 @@
<div class="tabs">
<% url_params = @free_period ? { :from => @from, :to => @to } : { :period => params[:period] } %>
<ul>
<li><%= link_to(l(:label_details), url_params.merge({:controller => 'timelog', :action => 'details', :project_id => @project, :issue_id => @issue }),
:class => (@controller.action_name == 'details' ? 'selected' : nil)) %></li>
<li><%= link_to(l(:label_details), url_params.merge({:controller => 'timelog', :action => 'index', :project_id => @project, :issue_id => @issue }),
:class => (@controller.action_name == 'index' ? 'selected' : nil)) %></li>
<li><%= link_to(l(:label_report), url_params.merge({:controller => 'time_entry_reports', :action => 'report', :project_id => @project, :issue_id => @issue}),
:class => (@controller.action_name == 'report' ? 'selected' : nil)) %></li>
</ul>

View File

@ -19,9 +19,9 @@ ActionController::Routing::Routes.draw do |map|
map.connect 'projects/:project_id/issues/:issue_id/time_entries/new', :action => 'edit', :controller => 'timelog'
map.with_options :controller => 'timelog' do |timelog|
timelog.connect 'projects/:project_id/time_entries', :action => 'details'
timelog.connect 'projects/:project_id/time_entries', :action => 'index'
timelog.with_options :action => 'details', :conditions => {:method => :get} do |time_details|
timelog.with_options :action => 'index', :conditions => {:method => :get} do |time_details|
time_details.connect 'time_entries'
time_details.connect 'time_entries.:format'
time_details.connect 'issues/:issue_id/time_entries'

View File

@ -85,7 +85,7 @@ Redmine::AccessControl.map do |map|
map.project_module :time_tracking do |map|
map.permission :log_time, {:timelog => :edit}, :require => :loggedin
map.permission :view_time_entries, :timelog => [:details], :time_entry_reports => [:report]
map.permission :view_time_entries, :timelog => [:index], :time_entry_reports => [:report]
map.permission :edit_time_entries, {:timelog => [:edit, :destroy]}, :require => :member
map.permission :edit_own_time_entries, {:timelog => [:edit, :destroy]}, :require => :loggedin
map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member

View File

@ -83,7 +83,7 @@ class TimelogControllerTest < ActionController::TestCase
:spent_on => '2008-03-14',
:issue_id => '1',
:hours => '7.3'}
assert_redirected_to :action => 'details', :project_id => 'ecookbook'
assert_redirected_to :action => 'index', :project_id => 'ecookbook'
i = Issue.find(1)
t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
@ -104,7 +104,7 @@ class TimelogControllerTest < ActionController::TestCase
post :edit, :id => 1,
:time_entry => {:issue_id => '2',
:hours => '8'}
assert_redirected_to :action => 'details', :project_id => 'ecookbook'
assert_redirected_to :action => 'index', :project_id => 'ecookbook'
entry.reload
assert_equal 8, entry.hours
@ -115,7 +115,7 @@ class TimelogControllerTest < ActionController::TestCase
def test_destroy
@request.session[:user_id] = 2
post :destroy, :id => 1
assert_redirected_to :action => 'details', :project_id => 'ecookbook'
assert_redirected_to :action => 'index', :project_id => 'ecookbook'
assert_equal I18n.t(:notice_successful_delete), flash[:notice]
assert_nil TimeEntry.find_by_id(1)
end
@ -129,7 +129,7 @@ class TimelogControllerTest < ActionController::TestCase
@request.session[:user_id] = 2
post :destroy, :id => 1
assert_redirected_to :action => 'details', :project_id => 'ecookbook'
assert_redirected_to :action => 'index', :project_id => 'ecookbook'
assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
assert_not_nil TimeEntry.find_by_id(1)
@ -137,18 +137,18 @@ class TimelogControllerTest < ActionController::TestCase
TimeEntry.before_destroy.reject! {|callback| callback.method == :stop_callback_chain }
end
def test_details_all_projects
get :details
def test_index_all_projects
get :index
assert_response :success
assert_template 'details'
assert_template 'index'
assert_not_nil assigns(:total_hours)
assert_equal "162.90", "%.2f" % assigns(:total_hours)
end
def test_details_at_project_level
get :details, :project_id => 1
def test_index_at_project_level
get :index, :project_id => 1
assert_response :success
assert_template 'details'
assert_template 'index'
assert_not_nil assigns(:entries)
assert_equal 4, assigns(:entries).size
# project and subproject
@ -160,10 +160,10 @@ class TimelogControllerTest < ActionController::TestCase
assert_equal '2007-04-22'.to_date, assigns(:to)
end
def test_details_at_project_level_with_date_range
get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30'
def test_index_at_project_level_with_date_range
get :index, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30'
assert_response :success
assert_template 'details'
assert_template 'index'
assert_not_nil assigns(:entries)
assert_equal 3, assigns(:entries).size
assert_not_nil assigns(:total_hours)
@ -172,28 +172,28 @@ class TimelogControllerTest < ActionController::TestCase
assert_equal '2007-04-30'.to_date, assigns(:to)
end
def test_details_at_project_level_with_period
get :details, :project_id => 1, :period => '7_days'
def test_index_at_project_level_with_period
get :index, :project_id => 1, :period => '7_days'
assert_response :success
assert_template 'details'
assert_template 'index'
assert_not_nil assigns(:entries)
assert_not_nil assigns(:total_hours)
assert_equal Date.today - 7, assigns(:from)
assert_equal Date.today, assigns(:to)
end
def test_details_one_day
get :details, :project_id => 1, :from => "2007-03-23", :to => "2007-03-23"
def test_index_one_day
get :index, :project_id => 1, :from => "2007-03-23", :to => "2007-03-23"
assert_response :success
assert_template 'details'
assert_template 'index'
assert_not_nil assigns(:total_hours)
assert_equal "4.25", "%.2f" % assigns(:total_hours)
end
def test_details_at_issue_level
get :details, :issue_id => 1
def test_index_at_issue_level
get :index, :issue_id => 1
assert_response :success
assert_template 'details'
assert_template 'index'
assert_not_nil assigns(:entries)
assert_equal 2, assigns(:entries).size
assert_not_nil assigns(:total_hours)
@ -203,26 +203,26 @@ class TimelogControllerTest < ActionController::TestCase
assert_equal '2007-04-22'.to_date, assigns(:to)
end
def test_details_atom_feed
get :details, :project_id => 1, :format => 'atom'
def test_index_atom_feed
get :index, :project_id => 1, :format => 'atom'
assert_response :success
assert_equal 'application/atom+xml', @response.content_type
assert_not_nil assigns(:items)
assert assigns(:items).first.is_a?(TimeEntry)
end
def test_details_all_projects_csv_export
def test_index_all_projects_csv_export
Setting.date_format = '%m/%d/%Y'
get :details, :format => 'csv'
get :index, :format => 'csv'
assert_response :success
assert_equal 'text/csv', @response.content_type
assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
end
def test_details_csv_export
def test_index_csv_export
Setting.date_format = '%m/%d/%Y'
get :details, :project_id => 1, :format => 'csv'
get :index, :project_id => 1, :format => 'csv'
assert_response :success
assert_equal 'text/csv', @response.content_type
assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")

View File

@ -222,6 +222,17 @@ class RoutingTest < ActionController::IntegrationTest
end
context "timelogs" do
should_route :get, "/time_entries", :controller => 'timelog', :action => 'index'
should_route :get, "/time_entries.csv", :controller => 'timelog', :action => 'index', :format => 'csv'
should_route :get, "/time_entries.atom", :controller => 'timelog', :action => 'index', :format => 'atom'
should_route :get, "/projects/567/time_entries", :controller => 'timelog', :action => 'index', :project_id => '567'
should_route :get, "/projects/567/time_entries.csv", :controller => 'timelog', :action => 'index', :project_id => '567', :format => 'csv'
should_route :get, "/projects/567/time_entries.atom", :controller => 'timelog', :action => 'index', :project_id => '567', :format => 'atom'
should_route :get, "/issues/234/time_entries", :controller => 'timelog', :action => 'index', :issue_id => '234'
should_route :get, "/issues/234/time_entries.csv", :controller => 'timelog', :action => 'index', :issue_id => '234', :format => 'csv'
should_route :get, "/issues/234/time_entries.atom", :controller => 'timelog', :action => 'index', :issue_id => '234', :format => 'atom'
should_route :get, "/projects/ecookbook/issues/123/time_entries", :controller => 'timelog', :action => 'index', :project_id => 'ecookbook', :issue_id => '123'
should_route :get, "/issues/567/time_entries/new", :controller => 'timelog', :action => 'edit', :issue_id => '567'
should_route :get, "/projects/ecookbook/time_entries/new", :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook'
should_route :get, "/projects/ecookbook/issues/567/time_entries/new", :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook', :issue_id => '567'
@ -234,18 +245,6 @@ class RoutingTest < ActionController::IntegrationTest
should_route :get, "/time_entries/report", :controller => 'time_entry_reports', :action => 'report'
should_route :get, "/projects/567/time_entries/report", :controller => 'time_entry_reports', :action => 'report', :project_id => '567'
should_route :get, "/projects/567/time_entries/report.csv", :controller => 'time_entry_reports', :action => 'report', :project_id => '567', :format => 'csv'
should_route :get, "/time_entries", :controller => 'timelog', :action => 'details'
should_route :get, "/time_entries.csv", :controller => 'timelog', :action => 'details', :format => 'csv'
should_route :get, "/time_entries.atom", :controller => 'timelog', :action => 'details', :format => 'atom'
should_route :get, "/projects/567/time_entries", :controller => 'timelog', :action => 'details', :project_id => '567'
should_route :get, "/projects/567/time_entries.csv", :controller => 'timelog', :action => 'details', :project_id => '567', :format => 'csv'
should_route :get, "/projects/567/time_entries.atom", :controller => 'timelog', :action => 'details', :project_id => '567', :format => 'atom'
should_route :get, "/issues/234/time_entries", :controller => 'timelog', :action => 'details', :issue_id => '234'
should_route :get, "/issues/234/time_entries.csv", :controller => 'timelog', :action => 'details', :issue_id => '234', :format => 'csv'
should_route :get, "/issues/234/time_entries.atom", :controller => 'timelog', :action => 'details', :issue_id => '234', :format => 'atom'
should_route :get, "/projects/ecookbook/issues/123/time_entries", :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123'
end
context "users" do