diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 22859793..602d551f 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -16,9 +16,10 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class IssuesController < ApplicationController - layout 'base', :except => :export_pdf - before_filter :find_project, :authorize, :except => [:index, :preview] - accept_key_auth :index + layout 'base' + before_filter :find_project, :authorize, :except => [:index, :changes, :preview] + before_filter :find_optional_project, :only => [:index, :changes] + accept_key_auth :index, :changes cache_sweeper :issue_sweeper, :only => [ :edit, :change_status, :destroy ] @@ -37,37 +38,54 @@ class IssuesController < ApplicationController helper :queries helper :sort include SortHelper + include IssuesHelper def index sort_init "#{Issue.table_name}.id", "desc" sort_update retrieve_query if @query.valid? - @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) - @issue_pages = Paginator.new self, @issue_count, 25, params['page'] + limit = %w(pdf csv).include?(params[:format]) ? Setting.issues_export_limit.to_i : 25 + @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) + @issue_pages = Paginator.new self, @issue_count, limit, params['page'] @issues = Issue.find :all, :order => sort_clause, :include => [ :assigned_to, :status, :tracker, :project, :priority, :category ], :conditions => @query.statement, - :limit => @issue_pages.items_per_page, - :offset => @issue_pages.current.offset + :limit => limit, + :offset => @issue_pages.current.offset + respond_to do |format| + format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } + format.atom { render_feed(@issues, :title => l(:label_issue_plural)) } + format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') } + format.pdf { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') } + end + else + # Send html if the query is not valid + render(:template => 'issues/index.rhtml', :layout => !request.xhr?) end - respond_to do |format| - format.html { render :layout => false if request.xhr? } - format.atom { render_feed(@issues, :title => l(:label_issue_plural)) } + end + + def changes + sort_init "#{Issue.table_name}.id", "desc" + sort_update + retrieve_query + if @query.valid? + @changes = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], + :conditions => @query.statement, + :limit => 25, + :order => "#{Journal.table_name}.created_on DESC" end + @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) + render :layout => false, :content_type => 'application/atom+xml' end def show @custom_values = @issue.custom_values.find(:all, :include => :custom_field) @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") - - if params[:format]=='pdf' - @options_for_rfpdf ||= {} - @options_for_rfpdf[:file_name] = "#{@project.identifier}-#{@issue.id}.pdf" - render :template => 'issues/show.rfpdf', :layout => false - else - @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user - render :template => 'issues/show.rhtml' + @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user + respond_to do |format| + format.html { render :template => 'issues/show.rhtml' } + format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } end end @@ -152,7 +170,7 @@ class IssuesController < ApplicationController def destroy @issue.destroy - redirect_to :controller => 'projects', :action => 'list_issues', :id => @project + redirect_to :action => 'index', :project_id => @project end def destroy_attachment @@ -195,23 +213,38 @@ private render_404 end + def find_optional_project + return true unless params[:project_id] + @project = Project.find(params[:project_id]) + authorize + rescue ActiveRecord::RecordNotFound + render_404 + end + # Retrieve query from session or build a new query def retrieve_query - if params[:set_filter] or !session[:query] or session[:query].project_id - # Give it a name, required to be valid - @query = Query.new(:name => "_", :executed_by => logged_in_user) - if params[:fields] and params[:fields].is_a? Array - params[:fields].each do |field| - @query.add_filter(field, params[:operators][field], params[:values][field]) - end - else - @query.available_filters.keys.each do |field| - @query.add_short_filter(field, params[field]) if params[field] - end - end + if params[:query_id] + @query = Query.find(params[:query_id], :conditions => {:project_id => (@project ? @project.id : nil)}) + @query.executed_by = logged_in_user session[:query] = @query else - @query = session[:query] + if params[:set_filter] or !session[:query] or session[:query].project != @project + # Give it a name, required to be valid + @query = Query.new(:name => "_", :executed_by => logged_in_user) + @query.project = @project + if params[:fields] and params[:fields].is_a? Array + params[:fields].each do |field| + @query.add_filter(field, params[:operators][field], params[:values][field]) + end + else + @query.available_filters.keys.each do |field| + @query.add_short_filter(field, params[field]) if params[field] + end + end + session[:query] = @query + else + @query = session[:query] + end end end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ae9c242e..4356ec77 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -15,8 +15,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require 'csv' - class ProjectsController < ApplicationController layout 'base' before_filter :find_project, :except => [ :index, :list, :add ] @@ -238,118 +236,13 @@ class ProjectsController < ApplicationController end flash[:notice] = l(:notice_successful_create) Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') - redirect_to :action => 'list_issues', :id => @project + redirect_to :controller => 'issues', :action => 'index', :project_id => @project return end end @priorities = Enumeration::get_values('IPRI') end - # Show filtered/sorted issues list of @project - def list_issues - sort_init "#{Issue.table_name}.id", "desc" - sort_update - - retrieve_query - - @results_per_page_options = [ 15, 25, 50, 100 ] - if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i - @results_per_page = params[:per_page].to_i - session[:results_per_page] = @results_per_page - else - @results_per_page = session[:results_per_page] || 25 - end - - if @query.valid? - @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) - @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] - @issues = Issue.find :all, :order => sort_clause, - :include => [ :assigned_to, :status, :tracker, :project, :priority, :category ], - :conditions => @query.statement, - :limit => @issue_pages.items_per_page, - :offset => @issue_pages.current.offset - end - - render :layout => false if request.xhr? - end - - # Export filtered/sorted issues list to CSV - def export_issues_csv - sort_init "#{Issue.table_name}.id", "desc" - sort_update - - retrieve_query - render :action => 'list_issues' and return unless @query.valid? - - @issues = Issue.find :all, :order => sort_clause, - :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ], - :conditions => @query.statement, - :limit => Setting.issues_export_limit.to_i - - ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') - export = StringIO.new - CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| - # csv header fields - headers = [ "#", l(:field_status), - l(:field_project), - l(:field_tracker), - l(:field_priority), - l(:field_subject), - l(:field_assigned_to), - l(:field_author), - l(:field_start_date), - l(:field_due_date), - l(:field_done_ratio), - l(:field_created_on), - l(:field_updated_on) - ] - for custom_field in @project.all_custom_fields - headers << custom_field.name - end - csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } - # csv lines - @issues.each do |issue| - fields = [issue.id, issue.status.name, - issue.project.name, - issue.tracker.name, - issue.priority.name, - issue.subject, - (issue.assigned_to ? issue.assigned_to.name : ""), - issue.author.name, - issue.start_date ? l_date(issue.start_date) : nil, - issue.due_date ? l_date(issue.due_date) : nil, - issue.done_ratio, - l_datetime(issue.created_on), - l_datetime(issue.updated_on) - ] - for custom_field in @project.all_custom_fields - fields << (show_value issue.custom_value_for(custom_field)) - end - csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } - end - end - export.rewind - send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') - end - - # Export filtered/sorted issues to PDF - def export_issues_pdf - sort_init "#{Issue.table_name}.id", "desc" - sort_update - - retrieve_query - render :action => 'list_issues' and return unless @query.valid? - - @issues = Issue.find :all, :order => sort_clause, - :include => [ :author, :status, :tracker, :priority, :project ], - :conditions => @query.statement, - :limit => Setting.issues_export_limit.to_i - - @options_for_rfpdf ||= {} - @options_for_rfpdf[:file_name] = "export.pdf" - render :layout => false - end - # Bulk edit issues def bulk_edit_issues if request.post? @@ -383,7 +276,7 @@ class ProjectsController < ApplicationController else flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #')) end - redirect_to :action => 'list_issues', :id => @project + redirect_to :controller => 'issues', :action => 'index', :project_id => @project return end if current_role && User.current.allowed_to?(:change_issue_status, @project) @@ -399,7 +292,7 @@ class ProjectsController < ApplicationController def move_issues @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] - redirect_to :action => 'list_issues', :id => @project and return unless @issues + redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues @projects = [] # find projects to which the user is allowed to move the issue User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')} @@ -424,7 +317,7 @@ class ProjectsController < ApplicationController i.save end flash[:notice] = l(:notice_successful_update) - redirect_to :action => 'list_issues', :id => @project + redirect_to :controller => 'issues', :action => 'index', :project_id => @project end end @@ -659,31 +552,4 @@ private @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } end end - - # Retrieve query from session or build a new query - def retrieve_query - if params[:query_id] - @query = @project.queries.find(params[:query_id]) - @query.executed_by = logged_in_user - session[:query] = @query - else - if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id - # Give it a name, required to be valid - @query = Query.new(:name => "_", :executed_by => logged_in_user) - @query.project = @project - if params[:fields] and params[:fields].is_a? Array - params[:fields].each do |field| - @query.add_filter(field, params[:operators][field], params[:values][field]) - end - else - @query.available_filters.keys.each do |field| - @query.add_short_filter(field, params[field]) if params[field] - end - end - session[:query] = @query - else - @query = session[:query] - end - end - end end diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb index 72819bd6..7feafd35 100644 --- a/app/controllers/queries_controller.rb +++ b/app/controllers/queries_controller.rb @@ -39,7 +39,7 @@ class QueriesController < ApplicationController if request.post? && params[:confirm] && @query.save flash[:notice] = l(:notice_successful_create) - redirect_to :controller => 'projects', :action => 'list_issues', :id => @project, :query_id => @query + redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query return end render :layout => false if request.xhr? @@ -57,7 +57,7 @@ class QueriesController < ApplicationController if @query.save flash[:notice] = l(:notice_successful_update) - redirect_to :controller => 'projects', :action => 'list_issues', :id => @project, :query_id => @query + redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query end end end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 997f094a..c779c9d1 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -15,6 +15,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +require 'csv' + module IssuesHelper def render_issue_tooltip(issue) @@ -101,4 +103,54 @@ module IssuesHelper end end end + + def issues_to_csv(issues, project = nil) + ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') + export = StringIO.new + CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| + # csv header fields + headers = [ "#", + l(:field_status), + l(:field_project), + l(:field_tracker), + l(:field_priority), + l(:field_subject), + l(:field_assigned_to), + l(:field_author), + l(:field_start_date), + l(:field_due_date), + l(:field_done_ratio), + l(:field_created_on), + l(:field_updated_on) + ] + # only export custom fields if project is given + for custom_field in project.all_custom_fields + headers << custom_field.name + end if project + csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } + # csv lines + issues.each do |issue| + fields = [issue.id, + issue.status.name, + issue.project.name, + issue.tracker.name, + issue.priority.name, + issue.subject, + (issue.assigned_to ? issue.assigned_to.name : ""), + issue.author.name, + issue.start_date ? l_date(issue.start_date) : nil, + issue.due_date ? l_date(issue.due_date) : nil, + issue.done_ratio, + l_datetime(issue.created_on), + l_datetime(issue.updated_on) + ] + for custom_field in project.all_custom_fields + fields << (show_value issue.custom_value_for(custom_field)) + end if project + csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } + end + end + export.rewind + export + end end diff --git a/app/models/journal.rb b/app/models/journal.rb index a68988a7..331d7a72 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -29,6 +29,10 @@ class Journal < ActiveRecord::Base :project_key => "#{Issue.table_name}.project_id", :date_column => "#{Issue.table_name}.created_on" + acts_as_event :title => Proc.new {|o| "#{o.issue.tracker.name} ##{o.issue.id}: #{o.issue.subject}"}, + :description => :notes, + :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id}} + def save # Do not save an empty journal (details.empty? && notes.blank?) ? false : super diff --git a/app/views/issues/_sidebar.rhtml b/app/views/issues/_sidebar.rhtml index b171dbd0..3b42ce46 100644 --- a/app/views/issues/_sidebar.rhtml +++ b/app/views/issues/_sidebar.rhtml @@ -4,7 +4,7 @@ <% end %>

<%= l(:label_issue_plural) %>

-<%= link_to l(:label_issue_view_all), :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1 %>
+<%= link_to l(:label_issue_view_all), { :set_filter => 1 } %>
<%= link_to l(:field_summary), :controller => 'reports', :action => 'issue_report', :id => @project %>
<%= link_to l(:label_change_log), :controller => 'projects', :action => 'changelog', :id => @project %> @@ -14,5 +14,5 @@ :order => "name ASC", :conditions => ["is_public = ? or user_id = ?", true, (User.current.logged? ? User.current.id : 0)]) queries.each do |query| %> -<%= link_to query.name, :controller => 'projects', :action => 'list_issues', :id => @project, :query_id => query %>
+<%= link_to query.name, :controller => 'issues', :action => 'index', :project_id => @project, :query_id => query %>
<% end %> diff --git a/app/views/issues/changes.rxml b/app/views/issues/changes.rxml new file mode 100644 index 00000000..f1aa5d20 --- /dev/null +++ b/app/views/issues/changes.rxml @@ -0,0 +1,30 @@ +xml.instruct! +xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do + xml.title @title + xml.link "rel" => "self", "href" => url_for(:controller => 'feeds', :action => 'history', :format => 'atom', :only_path => false) + xml.link "rel" => "alternate", "href" => url_for(:controller => 'welcome', :only_path => false) + xml.id url_for(:controller => 'welcome', :only_path => false) + xml.updated((@changes.first ? @changes.first.event_datetime : Time.now).xmlschema) + xml.author { xml.name "#{Setting.app_title}" } + @changes.each do |change| + issue = change.issue + xml.entry do + xml.title "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}" + xml.link "rel" => "alternate", "href" => url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false) + xml.id url_for(:controller => 'issues' , :action => 'show', :id => issue, :journal_id => change, :only_path => false) + xml.updated change.created_on.xmlschema + xml.author do + xml.name change.user.name + xml.email(change.user.mail) + end + xml.content "type" => "html" do + xml.text! '' + xml.text! textilizable(change.notes) unless change.notes.blank? + end + end + end +end \ No newline at end of file diff --git a/app/views/issues/context_menu.rhtml b/app/views/issues/context_menu.rhtml index 798fd42c..e44911da 100644 --- a/app/views/issues/context_menu.rhtml +++ b/app/views/issues/context_menu.rhtml @@ -1,4 +1,4 @@ -<% back_to = url_for(:controller => 'projects', :action => 'list_issues', :id => @project) %> +<% back_to = url_for(:controller => 'issues', :action => 'index', :project_id => @project) %>