diff --git a/app/controllers/time_entry_reports_controller.rb b/app/controllers/time_entry_reports_controller.rb deleted file mode 100644 index bd69181920d9fbe2fa28fe3dfbd3492fe47a082d..0000000000000000000000000000000000000000 --- a/app/controllers/time_entry_reports_controller.rb +++ /dev/null @@ -1,82 +0,0 @@ -class TimeEntryReportsController < ApplicationController - menu_item :issues - before_filter :find_optional_project - - helper :sort - include SortHelper - helper :issues - helper :timelog - include TimelogHelper - helper :custom_fields - include CustomFieldsHelper - - def report - retrieve_date_range - @report = Redmine::Helpers::TimeReport.new(@project, @issue, params[:criteria], params[:columns], @from, @to) - - respond_to do |format| - format.html { render :layout => !request.xhr? } - format.csv { send_data(report_to_csv(@report), :type => 'text/csv; header=present', :filename => 'timelog.csv') } - end - end - - private - - # TODO: duplicated in TimelogController - def find_optional_project - if !params[:issue_id].blank? - @issue = Issue.find(params[:issue_id]) - @project = @issue.project - elsif !params[:project_id].blank? - @project = Project.find(params[:project_id]) - end - deny_access unless User.current.allowed_to?(:view_time_entries, @project, :global => true) - end - - # Retrieves the date range based on predefined ranges or specific from/to param dates - # TODO: duplicated in TimelogController - def retrieve_date_range - @free_period = false - @from, @to = nil, nil - - if params[:period_type] == '1' || (params[:period_type].nil? && !params[:period].nil?) - case params[:period].to_s - when 'today' - @from = @to = Date.today - when 'yesterday' - @from = @to = Date.today - 1 - when 'current_week' - @from = Date.today - (Date.today.cwday - 1)%7 - @to = @from + 6 - when 'last_week' - @from = Date.today - 7 - (Date.today.cwday - 1)%7 - @to = @from + 6 - when '7_days' - @from = Date.today - 7 - @to = Date.today - when 'current_month' - @from = Date.civil(Date.today.year, Date.today.month, 1) - @to = (@from >> 1) - 1 - when 'last_month' - @from = Date.civil(Date.today.year, Date.today.month, 1) << 1 - @to = (@from >> 1) - 1 - when '30_days' - @from = Date.today - 30 - @to = Date.today - when 'current_year' - @from = Date.civil(Date.today.year, 1, 1) - @to = Date.civil(Date.today.year, 12, 31) - end - elsif params[:period_type] == '2' || (params[:period_type].nil? && (!params[:from].nil? || !params[:to].nil?)) - begin; @from = params[:from].to_s.to_date unless params[:from].blank?; rescue; end - begin; @to = params[:to].to_s.to_date unless params[:to].blank?; rescue; end - @free_period = true - else - # default - end - - @from, @to = @to, @from if @from && @to && @from > @to - @from ||= (TimeEntry.earilest_date_for_project(@project) || Date.today) - @to ||= (TimeEntry.latest_date_for_project(@project) || Date.today) - end -end diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index 932ba7fff84bed960d49b70650c1ee13632e5491..063df30ccd89d6512df555c21c3d2bcac0d406ad 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -20,8 +20,8 @@ class TimelogController < ApplicationController before_filter :find_project, :only => [:new, :create] before_filter :find_time_entry, :only => [:show, :edit, :update] before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy] - before_filter :authorize, :except => [:index] - before_filter :find_optional_project, :only => [:index] + before_filter :authorize, :except => [:index, :report] + before_filter :find_optional_project, :only => [:index, :report] accept_rss_auth :index accept_api_auth :index, :show, :create, :update, :destroy @@ -95,6 +95,16 @@ class TimelogController < ApplicationController end end + def report + retrieve_date_range + @report = Redmine::Helpers::TimeReport.new(@project, @issue, params[:criteria], params[:columns], @from, @to) + + respond_to do |format| + format.html { render :layout => !request.xhr? } + format.csv { send_data(report_to_csv(@report), :type => 'text/csv; header=present', :filename => 'timelog.csv') } + end + end + def show respond_to do |format| # TODO: Implement html response diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index 5cef644d034712d74066b6a338012f6cbebc0eb3..8ba36ba045b425ec446f67a47e1d98e98289d934 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -68,7 +68,7 @@

<%= l(:label_spent_time) %>

<%= l_hours(@total_hours) %>

<%= 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}) %>

+ <%= link_to(l(:label_report), {:controller => 'timelog', :action => 'report', :project_id => @project}) %>

<% end %> <%= call_hook(:view_projects_show_sidebar_bottom, :project => @project) %> <% end %> diff --git a/app/views/timelog/_date_range.html.erb b/app/views/timelog/_date_range.html.erb index fb694a704bfc3dc3568aea44bf7de44fcc813035..d1ceb6fbd85d6e68f5b470c8eb1e1c3931619b4d 100644 --- a/app/views/timelog/_date_range.html.erb +++ b/app/views/timelog/_date_range.html.erb @@ -32,7 +32,7 @@ diff --git a/app/views/time_entry_reports/_report_criteria.html.erb b/app/views/timelog/_report_criteria.html.erb similarity index 100% rename from app/views/time_entry_reports/_report_criteria.html.erb rename to app/views/timelog/_report_criteria.html.erb diff --git a/app/views/time_entry_reports/report.html.erb b/app/views/timelog/report.html.erb similarity index 95% rename from app/views/time_entry_reports/report.html.erb rename to app/views/timelog/report.html.erb index bd876aacde5d7fdf27214179de4aac3080dc51bb..ddbb71852a601c9b3eb886a25a43f036adfa7c49 100644 --- a/app/views/time_entry_reports/report.html.erb +++ b/app/views/timelog/report.html.erb @@ -6,7 +6,7 @@

<%= l(:label_spent_time) %>

-<% form_tag({:controller => 'time_entry_reports', :action => 'report', :project_id => @project, :issue_id => @issue}, :method => :get, :id => 'query_form') do %> +<% form_tag({:controller => 'timelog', :action => 'report', :project_id => @project, :issue_id => @issue}, :method => :get, :id => 'query_form') do %> <% @report.criteria.each do |criterion| %> <%= hidden_field_tag 'criteria[]', criterion, :id => nil %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 3364682b725db2ec376d6e88e527f82538e3e205..55b6ffe84aa7b1992afe8842b2e3808cc95a79a3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,15 +14,6 @@ ActionController::Routing::Routes.draw do |map| map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow' map.connect 'help/:ctrl/:page', :controller => 'help' - map.with_options :controller => 'time_entry_reports', :action => 'report',:conditions => {:method => :get} do |time_report| - time_report.connect 'projects/:project_id/issues/:issue_id/time_entries/report' - time_report.connect 'projects/:project_id/issues/:issue_id/time_entries/report.:format' - time_report.connect 'projects/:project_id/time_entries/report' - time_report.connect 'projects/:project_id/time_entries/report.:format' - time_report.connect 'time_entries/report' - time_report.connect 'time_entries/report.:format' - end - map.bulk_edit_time_entry 'time_entries/bulk_edit', :controller => 'timelog', :action => 'bulk_edit', :conditions => { :method => :get } map.bulk_update_time_entry 'time_entries/bulk_edit', @@ -30,7 +21,7 @@ ActionController::Routing::Routes.draw do |map| map.time_entries_context_menu '/time_entries/context_menu', :controller => 'context_menus', :action => 'time_entries' - map.resources :time_entries, :controller => 'timelog' + map.resources :time_entries, :controller => 'timelog', :collection => {:report => :get} map.connect 'projects/:id/wiki', :controller => 'wikis', :action => 'edit', :conditions => {:method => :post} map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :get} @@ -79,7 +70,7 @@ ActionController::Routing::Routes.draw do |map| end map.resources :issues do |issues| - issues.resources :time_entries, :controller => 'timelog' + issues.resources :time_entries, :controller => 'timelog', :collection => {:report => :get} issues.resources :relations, :shallow => true, :controller => 'issue_relations', :only => [:index, :show, :create, :destroy] end @@ -118,12 +109,12 @@ ActionController::Routing::Routes.draw do |map| } do |project| project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy] project.resources :issues, :only => [:index, :new, :create] do |issues| - issues.resources :time_entries, :controller => 'timelog' + issues.resources :time_entries, :controller => 'timelog', :collection => {:report => :get} end project.resources :files, :only => [:index, :new, :create] project.resources :versions, :shallow => true, :collection => {:close_completed => :put}, :member => {:status_by => :post} project.resources :news, :shallow => true - project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id' + project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id', :collection => {:report => :get} project.resources :queries, :only => [:new, :create] project.resources :issue_categories, :shallow => true project.resources :documents, :shallow => true, :member => {:add_attachment => :post} diff --git a/lib/redmine.rb b/lib/redmine.rb index ca748b611001b9d4b288fe34a84fd3c134e79120..6fdb2192cd56050622840558acb2bc1e3c9b21ff 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -89,7 +89,7 @@ Redmine::AccessControl.map do |map| map.project_module :time_tracking do |map| map.permission :log_time, {:timelog => [:new, :create]}, :require => :loggedin - map.permission :view_time_entries, :timelog => [:index, :show], :time_entry_reports => [:report] + map.permission :view_time_entries, :timelog => [:index, :report, :show] map.permission :edit_time_entries, {:timelog => [:edit, :update, :destroy, :bulk_edit, :bulk_update]}, :require => :member map.permission :edit_own_time_entries, {:timelog => [:edit, :update, :destroy,:bulk_edit, :bulk_update]}, :require => :loggedin map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member diff --git a/test/functional/time_entry_reports_controller_test.rb b/test/functional/time_entry_reports_controller_test.rb index 1c5c5801e67d0461ddd45dfed82f3076f5b136b4..c9256145a655d9c3370999e1319abf6625f40470 100644 --- a/test/functional/time_entry_reports_controller_test.rb +++ b/test/functional/time_entry_reports_controller_test.rb @@ -2,6 +2,8 @@ require File.expand_path('../../test_helper', __FILE__) class TimeEntryReportsControllerTest < ActionController::TestCase + tests TimelogController + fixtures :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index 42dd558498294371cda7692a63416536105e0181..bcb35b33b08502e88da2e886c6759bd3e5df619a 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -329,12 +329,10 @@ class RoutingTest < ActionController::IntegrationTest should_route :put, "/projects/ecookbook/issues/234/time_entries/22", :controller => 'timelog', :action => 'update', :id => '22', :issue_id => '234', :project_id => 'ecookbook' should_route :delete, "/projects/ecookbook/issues/234/time_entries/55", :controller => 'timelog', :action => 'destroy', :id => '55', :issue_id => '234', :project_id => 'ecookbook' - end - context "time_entry_reports" do - 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/report", :controller => 'timelog', :action => 'report' + should_route :get, "/projects/567/time_entries/report", :controller => 'timelog', :action => 'report', :project_id => '567' + should_route :get, "/projects/567/time_entries/report.csv", :controller => 'timelog', :action => 'report', :project_id => '567', :format => 'csv' end context "users" do