Added fragment caching for calendar and gantt views

git-svn-id: http://redmine.rubyforge.org/svn/trunk@515 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-05-06 16:40:33 +00:00
parent 7eb6471559
commit b748455d96
6 changed files with 85 additions and 36 deletions

View File

@ -19,6 +19,8 @@ class IssuesController < ApplicationController
layout 'base', :except => :export_pdf layout 'base', :except => :export_pdf
before_filter :find_project, :authorize before_filter :find_project, :authorize
cache_sweeper :issue_sweeper, :only => [ :edit, :change_status, :destroy ]
helper :custom_fields helper :custom_fields
include CustomFieldsHelper include CustomFieldsHelper
helper :ifpdf helper :ifpdf

View File

@ -22,6 +22,8 @@ class ProjectsController < ApplicationController
before_filter :find_project, :authorize, :except => [ :index, :list, :add ] before_filter :find_project, :authorize, :except => [ :index, :list, :add ]
before_filter :require_admin, :only => [ :add, :destroy ] before_filter :require_admin, :only => [ :add, :destroy ]
cache_sweeper :issue_sweeper, :only => [ :add_issue ]
helper :sort helper :sort
include SortHelper include SortHelper
helper :custom_fields helper :custom_fields

View File

@ -0,0 +1,38 @@
# redMine - project management software
# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class IssueSweeper < ActionController::Caching::Sweeper
observe Issue
def after_save(issue)
expire_cache_for(issue)
end
def after_destroy(issue)
expire_cache_for(issue)
end
private
def expire_cache_for(issue)
# fragments of the main project
expire_fragment(Regexp.new("projects/(calendar|gantt)/#{issue.project_id}\\."))
# fragments of the root project that include subprojects issues
unless issue.project.parent_id.nil?
expire_fragment(Regexp.new("projects/(calendar|gantt)/#{issue.project.parent_id}\\..*subprojects"))
end
end
end

View File

@ -1,3 +1,4 @@
<% cache(:year => @year, :month => @month, :tracker_ids => @selected_tracker_ids, :subprojects => params[:with_subprojects], :lang => current_language) do %>
<h2><%= l(:label_calendar) %></h2> <h2><%= l(:label_calendar) %></h2>
<% form_tag do %> <% form_tag do %>
@ -88,3 +89,4 @@ end %>
<%= image_tag 'arrow_from.png' %>&nbsp;&nbsp;<%= l(:text_tip_task_begin_day) %><br /> <%= image_tag 'arrow_from.png' %>&nbsp;&nbsp;<%= l(:text_tip_task_begin_day) %><br />
<%= image_tag 'arrow_to.png' %>&nbsp;&nbsp;<%= l(:text_tip_task_end_day) %><br /> <%= image_tag 'arrow_to.png' %>&nbsp;&nbsp;<%= l(:text_tip_task_end_day) %><br />
<%= image_tag 'arrow_bw.png' %>&nbsp;&nbsp;<%= l(:text_tip_task_begin_end_day) %><br /> <%= image_tag 'arrow_bw.png' %>&nbsp;&nbsp;<%= l(:text_tip_task_begin_end_day) %><br />
<% end %>

View File

@ -1,3 +1,28 @@
<% zoom = 1
@zoom.times { zoom = zoom * 2 }
subject_width = 330
header_heigth = 18
headers_height = header_heigth
show_weeks = false
show_days = false
if @zoom >1
show_weeks = true
headers_height = 2*header_heigth
if @zoom > 2
show_days = true
headers_height = 3*header_heigth
end
end
g_width = (@date_to - @date_from + 1)*zoom
g_height = [(20 * @events.length + 6)+150, 206].max
t_height = g_height + headers_height
%>
<% cache(:year => @year_from, :month => @month_from, :months => @months, :zoom => @zoom, :tracker_ids => @selected_tracker_ids, :subprojects => params[:with_subprojects], :lang => current_language) do %>
<div class="contextual"> <div class="contextual">
<%= l(:label_export_to) %> <%= l(:label_export_to) %>
<%= link_to 'PDF', {:zoom => @zoom, :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects], :output => 'pdf'}, :class => 'icon icon-pdf' %> <%= link_to 'PDF', {:zoom => @zoom, :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects], :output => 'pdf'}, :class => 'icon icon-pdf' %>
@ -47,30 +72,6 @@
</table> </table>
<% end %> <% end %>
<% zoom = 1
@zoom.times { zoom = zoom * 2 }
subject_width = 330
header_heigth = 18
headers_height = header_heigth
show_weeks = false
show_days = false
if @zoom >1
show_weeks = true
headers_height = 2*header_heigth
if @zoom > 2
show_days = true
headers_height = 3*header_heigth
end
end
g_width = (@date_to - @date_from + 1)*zoom
g_height = [(20 * @events.length + 6)+150, 206].max
t_height = g_height + headers_height
%>
<table width="100%" style="border:0; border-collapse: collapse;"> <table width="100%" style="border:0; border-collapse: collapse;">
<tr> <tr>
<td style="width:<%= subject_width %>px;"> <td style="width:<%= subject_width %>px;">
@ -171,14 +172,6 @@ if show_days
end end
end %> end %>
<%
#
# Today red line
#
if Date.today >= @date_from and Date.today <= @date_to %>
<div style="position: absolute;height:<%= g_height %>px;top:<%= headers_height + 1 %>px;left:<%= ((Date.today-@date_from+1)*zoom).floor()-1 %>px;width:10px;border-left: 1px dashed red;">&nbsp;</div>
<% end %>
<% <%
# #
# Tasks # Tasks
@ -226,6 +219,18 @@ top = headers_height + 10
<% end %> <% end %>
<% top = top + 20 <% top = top + 20
end %> end %>
<% end # cache
%>
<%
#
# Today red line (excluded from cache)
#
if Date.today >= @date_from and Date.today <= @date_to %>
<div style="position: absolute;height:<%= g_height %>px;top:<%= headers_height + 1 %>px;left:<%= ((Date.today-@date_from+1)*zoom).floor()-1 %>px;width:10px;border-left: 1px dashed red;">&nbsp;</div>
<% end %>
</div> </div>
</td> </td>
</tr> </tr>

View File

@ -13,8 +13,8 @@ Rails::Initializer.run do |config|
# Skip frameworks you're not going to use # Skip frameworks you're not going to use
# config.frameworks -= [ :action_web_service, :action_mailer ] # config.frameworks -= [ :action_web_service, :action_mailer ]
# Add additional load paths for your own custom dirs # Add additional load paths for sweepers
# config.load_paths += %W( #{RAILS_ROOT}/extras ) config.load_paths += %W( #{RAILS_ROOT}/app/sweepers )
# Force all environments to use the same logger level # Force all environments to use the same logger level
# (by default production uses :info, the others :debug) # (by default production uses :info, the others :debug)