Refactor: move Project Calendar to it's own controller.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3732 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
469ff0fb4e
commit
36c82ecc1f
|
@ -0,0 +1,38 @@
|
||||||
|
class CalendarsController < ApplicationController
|
||||||
|
before_filter :find_optional_project
|
||||||
|
|
||||||
|
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||||
|
|
||||||
|
helper :issues
|
||||||
|
helper :projects
|
||||||
|
helper :queries
|
||||||
|
include QueriesHelper
|
||||||
|
|
||||||
|
def show
|
||||||
|
if params[:year] and params[:year].to_i > 1900
|
||||||
|
@year = params[:year].to_i
|
||||||
|
if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
|
||||||
|
@month = params[:month].to_i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@year ||= Date.today.year
|
||||||
|
@month ||= Date.today.month
|
||||||
|
|
||||||
|
@calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
|
||||||
|
retrieve_query
|
||||||
|
@query.group_by = nil
|
||||||
|
if @query.valid?
|
||||||
|
events = []
|
||||||
|
events += @query.issues(:include => [:tracker, :assigned_to, :priority],
|
||||||
|
:conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
|
||||||
|
)
|
||||||
|
events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
|
||||||
|
|
||||||
|
@calendar.events = events
|
||||||
|
end
|
||||||
|
|
||||||
|
render :layout => false if request.xhr?
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
|
@ -22,8 +22,8 @@ class IssuesController < ApplicationController
|
||||||
before_filter :find_issue, :only => [:show, :edit, :update, :reply]
|
before_filter :find_issue, :only => [:show, :edit, :update, :reply]
|
||||||
before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
|
before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
|
||||||
before_filter :find_project, :only => [:new, :create, :update_form, :preview, :auto_complete]
|
before_filter :find_project, :only => [:new, :create, :update_form, :preview, :auto_complete]
|
||||||
before_filter :authorize, :except => [:index, :changes, :calendar, :preview, :context_menu]
|
before_filter :authorize, :except => [:index, :changes, :preview, :context_menu]
|
||||||
before_filter :find_optional_project, :only => [:index, :changes, :calendar]
|
before_filter :find_optional_project, :only => [:index, :changes]
|
||||||
before_filter :check_for_default_issue_status, :only => [:new, :create]
|
before_filter :check_for_default_issue_status, :only => [:new, :create]
|
||||||
before_filter :build_new_issue_from_params, :only => [:new, :create]
|
before_filter :build_new_issue_from_params, :only => [:new, :create]
|
||||||
accept_key_auth :index, :show, :changes
|
accept_key_auth :index, :show, :changes
|
||||||
|
@ -318,32 +318,6 @@ class IssuesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def calendar
|
|
||||||
if params[:year] and params[:year].to_i > 1900
|
|
||||||
@year = params[:year].to_i
|
|
||||||
if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
|
|
||||||
@month = params[:month].to_i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@year ||= Date.today.year
|
|
||||||
@month ||= Date.today.month
|
|
||||||
|
|
||||||
@calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
|
|
||||||
retrieve_query
|
|
||||||
@query.group_by = nil
|
|
||||||
if @query.valid?
|
|
||||||
events = []
|
|
||||||
events += @query.issues(:include => [:tracker, :assigned_to, :priority],
|
|
||||||
:conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
|
|
||||||
)
|
|
||||||
events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
|
|
||||||
|
|
||||||
@calendar.events = events
|
|
||||||
end
|
|
||||||
|
|
||||||
render :layout => false if request.xhr?
|
|
||||||
end
|
|
||||||
|
|
||||||
def context_menu
|
def context_menu
|
||||||
@issues = Issue.find_all_by_id(params[:ids], :include => :project)
|
@issues = Issue.find_all_by_id(params[:ids], :include => :project)
|
||||||
if (@issues.size == 1)
|
if (@issues.size == 1)
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
<p style="float:right;">
|
<p style="float:right;">
|
||||||
<%= link_to_remote ('« ' + (@month==1 ? "#{month_name(12)} #{@year-1}" : "#{month_name(@month-1)}")),
|
<%= link_to_remote ('« ' + (@month==1 ? "#{month_name(12)} #{@year-1}" : "#{month_name(@month-1)}")),
|
||||||
{:update => "content", :url => { :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1) }},
|
{:update => "content", :url => { :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1) }},
|
||||||
{:href => url_for(:action => 'calendar', :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1))}
|
{:href => url_for(:action => 'show', :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1))}
|
||||||
%> |
|
%> |
|
||||||
<%= link_to_remote ((@month==12 ? "#{month_name(1)} #{@year+1}" : "#{month_name(@month+1)}") + ' »'),
|
<%= link_to_remote ((@month==12 ? "#{month_name(1)} #{@year+1}" : "#{month_name(@month+1)}") + ' »'),
|
||||||
{:update => "content", :url => { :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1) }},
|
{:update => "content", :url => { :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1) }},
|
||||||
{:href => url_for(:action => 'calendar', :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1))}
|
{:href => url_for(:action => 'show', :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1))}
|
||||||
%>
|
%>
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<p>
|
<p>
|
||||||
<%= link_to l(:label_issue_view_all), :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 %>
|
<%= link_to l(:label_issue_view_all), :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 %>
|
||||||
<% if User.current.allowed_to?(:view_calendar, @project, :global => true) %>
|
<% if User.current.allowed_to?(:view_calendar, @project, :global => true) %>
|
||||||
| <%= link_to(l(:label_calendar), :controller => 'issues', :action => 'calendar', :project_id => @project) %>
|
| <%= link_to(l(:label_calendar), :controller => 'calendars', :action => 'show', :project_id => @project) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if User.current.allowed_to?(:view_gantt, @project, :global => true) %>
|
<% if User.current.allowed_to?(:view_gantt, @project, :global => true) %>
|
||||||
| <%= link_to(l(:label_gantt), :controller => 'gantts', :action => 'show', :project_id => @project) %>
|
| <%= link_to(l(:label_gantt), :controller => 'gantts', :action => 'show', :project_id => @project) %>
|
||||||
|
|
|
@ -111,7 +111,7 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
issues_views.connect 'projects/:project_id/issues.:format', :action => 'index'
|
issues_views.connect 'projects/:project_id/issues.:format', :action => 'index'
|
||||||
issues_views.connect 'projects/:project_id/issues/new', :action => 'new'
|
issues_views.connect 'projects/:project_id/issues/new', :action => 'new'
|
||||||
issues_views.connect 'projects/:project_id/issues/gantt', :controller => 'gantts', :action => 'show'
|
issues_views.connect 'projects/:project_id/issues/gantt', :controller => 'gantts', :action => 'show'
|
||||||
issues_views.connect 'projects/:project_id/issues/calendar', :action => 'calendar'
|
issues_views.connect 'projects/:project_id/issues/calendar', :controller => 'calendars', :action => 'show'
|
||||||
issues_views.connect 'projects/:project_id/issues/:copy_from/copy', :action => 'new'
|
issues_views.connect 'projects/:project_id/issues/:copy_from/copy', :action => 'new'
|
||||||
issues_views.connect 'issues/:id', :action => 'show', :id => /\d+/
|
issues_views.connect 'issues/:id', :action => 'show', :id => /\d+/
|
||||||
issues_views.connect 'issues/:id.:format', :action => 'show', :id => /\d+/
|
issues_views.connect 'issues/:id.:format', :action => 'show', :id => /\d+/
|
||||||
|
@ -122,6 +122,7 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
issues_actions.connect 'issues', :action => 'index'
|
issues_actions.connect 'issues', :action => 'index'
|
||||||
issues_actions.connect 'projects/:project_id/issues', :action => 'create'
|
issues_actions.connect 'projects/:project_id/issues', :action => 'create'
|
||||||
issues_actions.connect 'projects/:project_id/issues/gantt', :controller => 'gantts', :action => 'show'
|
issues_actions.connect 'projects/:project_id/issues/gantt', :controller => 'gantts', :action => 'show'
|
||||||
|
issues_actions.connect 'projects/:project_id/issues/calendar', :controller => 'calendars', :action => 'show'
|
||||||
issues_actions.connect 'issues/:id/quoted', :action => 'reply', :id => /\d+/
|
issues_actions.connect 'issues/:id/quoted', :action => 'reply', :id => /\d+/
|
||||||
issues_actions.connect 'issues/:id/:action', :action => /edit|move|destroy/, :id => /\d+/
|
issues_actions.connect 'issues/:id/:action', :action => /edit|move|destroy/, :id => /\d+/
|
||||||
issues_actions.connect 'issues.:format', :action => 'create', :format => /xml/
|
issues_actions.connect 'issues.:format', :action => 'create', :format => /xml/
|
||||||
|
@ -134,6 +135,7 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
issues_actions.connect 'issues/:id.:format', :action => 'destroy', :id => /\d+/, :format => /xml/
|
issues_actions.connect 'issues/:id.:format', :action => 'destroy', :id => /\d+/, :format => /xml/
|
||||||
end
|
end
|
||||||
issues_routes.connect 'issues/gantt', :controller => 'gantts', :action => 'show'
|
issues_routes.connect 'issues/gantt', :controller => 'gantts', :action => 'show'
|
||||||
|
issues_routes.connect 'issues/calendar', :controller => 'calendars', :action => 'show'
|
||||||
issues_routes.connect 'issues/:action'
|
issues_routes.connect 'issues/:action'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ Redmine::AccessControl.map do |map|
|
||||||
map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin
|
map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin
|
||||||
# Gantt & calendar
|
# Gantt & calendar
|
||||||
map.permission :view_gantt, :gantts => :show
|
map.permission :view_gantt, :gantts => :show
|
||||||
map.permission :view_calendar, :issues => :calendar
|
map.permission :view_calendar, :calendars => :show
|
||||||
# Watchers
|
# Watchers
|
||||||
map.permission :view_issue_watchers, {}
|
map.permission :view_issue_watchers, {}
|
||||||
map.permission :add_issue_watchers, {:watchers => :new}
|
map.permission :add_issue_watchers, {:watchers => :new}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class CalendarsControllerTest < ActionController::TestCase
|
||||||
|
fixtures :all
|
||||||
|
|
||||||
|
def test_calendar
|
||||||
|
get :show, :project_id => 1
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'calendar'
|
||||||
|
assert_not_nil assigns(:calendar)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_cross_project_calendar
|
||||||
|
get :show
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'calendar'
|
||||||
|
assert_not_nil assigns(:calendar)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -231,20 +231,6 @@ class IssuesControllerTest < ActionController::TestCase
|
||||||
assert_equal columns, session[:query][:column_names].map(&:to_s)
|
assert_equal columns, session[:query][:column_names].map(&:to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_calendar
|
|
||||||
get :calendar, :project_id => 1
|
|
||||||
assert_response :success
|
|
||||||
assert_template 'calendar'
|
|
||||||
assert_not_nil assigns(:calendar)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_cross_project_calendar
|
|
||||||
get :calendar
|
|
||||||
assert_response :success
|
|
||||||
assert_template 'calendar'
|
|
||||||
assert_not_nil assigns(:calendar)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_changes
|
def test_changes
|
||||||
get :changes, :project_id => 1
|
get :changes, :project_id => 1
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
|
|
@ -90,10 +90,10 @@ class RoutingTest < ActionController::IntegrationTest
|
||||||
|
|
||||||
should_route :post, "/issues/1/quoted", :controller => 'issues', :action => 'reply', :id => '1'
|
should_route :post, "/issues/1/quoted", :controller => 'issues', :action => 'reply', :id => '1'
|
||||||
|
|
||||||
should_route :get, "/issues/calendar", :controller => 'issues', :action => 'calendar'
|
should_route :get, "/issues/calendar", :controller => 'calendars', :action => 'show'
|
||||||
should_route :post, "/issues/calendar", :controller => 'issues', :action => 'calendar'
|
should_route :post, "/issues/calendar", :controller => 'calendars', :action => 'show'
|
||||||
should_route :get, "/projects/project-name/issues/calendar", :controller => 'issues', :action => 'calendar', :project_id => 'project-name'
|
should_route :get, "/projects/project-name/issues/calendar", :controller => 'calendars', :action => 'show', :project_id => 'project-name'
|
||||||
should_route :post, "/projects/project-name/issues/calendar", :controller => 'issues', :action => 'calendar', :project_id => 'project-name'
|
should_route :post, "/projects/project-name/issues/calendar", :controller => 'calendars', :action => 'show', :project_id => 'project-name'
|
||||||
|
|
||||||
should_route :get, "/issues/gantt", :controller => 'gantts', :action => 'show'
|
should_route :get, "/issues/gantt", :controller => 'gantts', :action => 'show'
|
||||||
should_route :post, "/issues/gantt", :controller => 'gantts', :action => 'show'
|
should_route :post, "/issues/gantt", :controller => 'gantts', :action => 'show'
|
||||||
|
|
Loading…
Reference in New Issue