Adapt structure for Rails 3

pull/6827/head
Michael Frister 11 years ago committed by Michael Frister
parent ed32ab24c1
commit 37ad0ab3ce
  1. 3
      CHANGELOG.md
  2. 9
      README.md
  3. 9
      README.rdoc
  4. 0
      app/assets/stylesheets/excel_export.css
  5. 3
      app/views/hooks/printable_issues/_view_issues_sidebar_issues_bottom.rhtml
  6. 47
      app/views/issues/_list_printable.rhtml
  7. 33
      app/views/issues/printable.rhtml
  8. 24
      assets/stylesheets/issues_printable.css
  9. 4
      config/routes.rb
  10. 30
      init.rb
  11. 5
      lib/open_project/xls_export.rb
  12. 32
      lib/open_project/xls_export/engine.rb
  13. 0
      lib/open_project/xls_export/filename_helper.rb
  14. 0
      lib/open_project/xls_export/filter_settings_helper.rb
  15. 0
      lib/open_project/xls_export/hooks/cost_report_hook.rb
  16. 0
      lib/open_project/xls_export/hooks/issue_hook.rb
  17. 0
      lib/open_project/xls_export/patches/cost_reports_controller_patch.rb
  18. 28
      lib/open_project/xls_export/patches/issues_controller_patch.rb
  19. 0
      lib/open_project/xls_export/spreadsheet_builder.rb
  20. 5
      lib/open_project/xls_export/version.rb
  21. 0
      lib/open_project/xls_export/xls_views.rb
  22. 0
      lib/open_project/xls_export/xls_views/cost_entry_table.xls.rb
  23. 0
      lib/open_project/xls_export/xls_views/cost_report_table.xls.rb
  24. 0
      lib/open_project/xls_export/xls_views/simple_cost_report_table.xls.rb
  25. 1
      lib/openproject-xls_export.rb
  26. 55
      lib/printable_issues/issues_controller_patch.rb
  27. 22
      openproject-xls_export.gemspec

@ -0,0 +1,3 @@
# Changelog
* `#1476` Migration Rails3 Export

@ -0,0 +1,9 @@
# OpenProject XLS Export Plugin
Export issue lists as Excel spreadsheets (.xls). This plugin adds a link below each issue list which allows downloading the list as Excel spreadsheet.
Support for exporting cost entries and cost reports is not yet migrated to Rails 3 and disabled.
# Issue Tracker
https://www.openproject.org/projects/export/issues

@ -1,9 +0,0 @@
= Additional Formats
This plugin provides additional formats for exporting.
A printable html view for issues lists and an excel builder
used for issue exports and optionally (as a soft dependency)
for the cost reports of the redmine_costs plugin.
== Required gems
spreadsheet (>= 0.6.4.1)

@ -1,3 +0,0 @@
<% if params[:action] == "index" or params[:action] == "all" %>
<%= link_to l(:print_with_description), :controller => 'issues', :action => 'printable', :project_id => @project %><br />
<% end %>

@ -1,47 +0,0 @@
<% form_tag({}) do -%>
<%= hidden_field_tag 'back_url', url_for(params) %>
<table class="list issues printable">
<thead><tr>
<%= sort_header_tag('id', :caption => '#', :default_order => 'desc') %>
<% @columns.each do |column| %>
<%= column_header(column) %>
<% end %>
</tr></thead>
<% previous_group = false %>
<tbody>
<% issues.each do |issue| -%>
<% if @query.grouped? && (group = @query.group_by_column.value(issue)) != previous_group %>
<% reset_cycle %>
<tr class="group open">
<td colspan="<%= @columns.size + 1 %>">
<span class="expander" onclick="toggleRowGroup(this); return false;">&nbsp;</span>
<%= group.blank? ? 'None' : column_content(@query.group_by_column, issue) %> <span class="count">(<%= @issue_count_by_group[group] %>)</span>
</td>
</tr>
<% previous_group = group %>
<% end %>
<tr class="issue_columns <%= issue.css_classes %>">
<td><%= link_to issue.id, :controller => 'issues', :action => 'show', :id => issue %></td>
<% @columns.each do |column| -%>
<%= content_tag 'td',
case column.name
when :done_ratio
number_to_percentage(column.value(issue), :precision => 0)
else
column_content(column, issue)
end,
:class => column.name %>
<%- end %>
</tr>
<tr class="issue_description">
<td colspan="<%= @columns.size + 1 %>">
<p><strong><%=h issue.subject %></strong></p>
<div class="wiki">
<%= textilizable issue, :description, :attachments => issue.attachments %>
</div>
</td>
</tr>
<% end -%>
</tbody>
</table>
<% end -%>

@ -1,33 +0,0 @@
<h2><%= @query.new_record? ? l(:label_issue_plural) : h(@query.name) %></h2>
<% html_title(@query.new_record? ? l(:label_issue_plural) : @query.name) %>
<%= error_messages_for 'query' %>
<% if @query.valid? %>
<table>
<tr>
<td><strong><%= l(:label_filter_plural) %>:</strong></td>
<td><%= FilterSettingsHelper.filter_settings(@query).join(", ") %></td>
</tr>
<% if group_by_settings = FilterSettingsHelper.group_by_setting(@query) %>
<tr>
<td><strong><%= l(:field_group_by) %>:</strong></td>
<td><%= group_by_settings %></td>
</tr>
<% end %>
</table>
<% if @issues.empty? %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% else %>
<style type='text/css'>
#main-menu { display: none; }
#content { margin-left: 0; }
</style>
<p><%= link_to l(:button_back), :project_id => @project, :action => 'index' %></p>
<%= render :partial => 'issues/list_printable', :locals => {:issues => @issues, :query => @query} %>
<p><%= link_to l(:button_back), :project_id => @project, :action => 'index' %></p>
<% end %>
<% end %>

@ -1,24 +0,0 @@
table.printable,
table.printable tr,
table.printable td {
border: 0 none;
}
table.printable tr th {
background-color: #fff;
border-bottom: 2px solid #000;
}
table.printable tr.issue_description {
margin-bottom: 4px;
}
table.printable tr.issue_description td {
border-bottom: 1px solid #000;
padding-bottom: 1em;
}
#main.nosidebar #content {
/* Fix for custom themes */
width: auto;
}

@ -1,4 +0,0 @@
ActionController::Routing::Routes.draw do |map|
map.connect 'projects/:project_id/issues/printable', :controller => 'issues', :action => 'printable'
map.connect 'issues/printable', :controller => 'issues', :action => 'printable'
end

@ -1,30 +0,0 @@
require 'redmine'
Redmine::Plugin.register :redmine_additional_formats do
name 'Redmine Additional Formats plugin'
author 'Holger Just, Tim Felgentreff @ finnlabs'
author_url 'http://finn.de/team#h.just'
description 'This plugin provides additional formats for exporting, like a printable view for issue lists and an excel builder for issue exports'
version '0.4.2'
requires_redmine :version_or_higher => '0.9'
requires_redmine_plugin :redmine_reporting, :version_or_higher => '0.1'
Redmine::AccessControl.permission(:view_issues).actions << "issues/printable"
end
require 'dispatcher'
Dispatcher.to_prepare do
# Controller Patches
require_dependency 'printable_issues/issues_controller_patch'
require_dependency 'xls_report/issues_controller_patch'
require_dependency 'xls_report/cost_reports_controller_patch'
# Initialization
Mime::Type.register('application/vnd.ms-excel', :xls, %w(application/vnd.ms-excel)) unless defined? Mime::XLS
end
# Hooks
require 'additional_formats/filename_helper'
require 'different_formats/issue_hook'
require 'xls_report/cost_report_hook'

@ -0,0 +1,5 @@
module OpenProject
module XlsExport
require "open_project/xls_export/engine"
end
end

@ -0,0 +1,32 @@
module OpenProject::XlsExport
class Engine < ::Rails::Engine
engine_name :openproject_xls_export
include OpenProject::Plugins::ActsAsOpEngine
register_plugin 'OpenProject XLS Export',
'openproject-xls_export',
:author_url => 'http://finn.de/',
:requires_openproject => '>= 3.0.0pre11'
assets %w(excel_export.css)
patches [:IssuesController]
# disabled since not yet migrated: :CostReportsController
initializer 'xls_export.register_hooks' do
# don't use require_dependency to not reload hooks in development mode
# disabled since not yet migrated
# require 'open_project/xls_export/hooks/cost_report_hook.rb'
require 'open_project/xls_export/hooks/issue_hook.rb'
end
initializer 'xls_export.register_mimetypes' do
Mime::Type.register('application/vnd.ms-excel',
:xls,
%w(application/vnd.ms-excel)) unless defined? Mime::XLS
end
end
end

@ -1,8 +1,8 @@
require_dependency 'issues_controller'
require_dependency 'xls_report/spreadsheet_builder'
require_dependency 'additional_formats/filter_settings_helper'
#require_dependency 'issues_controller'
#require_dependency 'xls_report/spreadsheet_builder'
#require_dependency 'additional_formats/filter_settings_helper'
module XlsReport
module OpenProject::XlsExport::Patches
module IssuesControllerPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
@ -23,7 +23,7 @@ module XlsReport
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
:order => sort_clause)
unless @issues.empty?
send_data(issues_to_xls, :type => "application/vnd.ms-excel",
send_data(issues_to_xls, :type => "application/vnd.ms-excel",
:filename => FilenameHelper.sane_filename("(#{I18n.l(DateTime.now)}) Issue Report#{" " + @project.name if @project}.xls"))
end
end
@ -32,14 +32,14 @@ module XlsReport
super(&block)
end
end
# Convert an issues query with associated issues to xls using the queries columns as headers
def build_spreadsheet(project, issues, query)
columns = query.columns
sb = SpreadsheetBuilder.new
project_name = (project.name if project) || "All Projects"
sb.add_title("#{project_name} >> #{l(:label_issue_plural)} (#{format_date(Date.today)})")
filters = FilterSettingsHelper.filter_settings(query)
sb.add_headers l(:label_filter_plural)
sb.add_row(filters)
@ -49,17 +49,17 @@ module XlsReport
sb.add_row group_by_settings
end
sb.add_empty_row
headers = (columns.collect(&:caption) << l(:field_description)).unshift("#")
headers = (columns.collect(&:caption) << l(:field_description)).unshift("#")
sb.add_headers headers
issues.each do |issue|
sb.add_row((columns.collect do |column|
cv = column.value(issue)
(cv.respond_to? :name) ? cv.name : cv
end << issue.description).unshift(issue.id))
end
headers.each_with_index do |h,idx|
h = h.to_s.downcase
if (h =~ /.*hours.*/ or h == "spent_time")
@ -68,10 +68,10 @@ module XlsReport
sb.add_format_option_to_column idx, :number_format => number_to_currency(0.00)
end
end
sb
end
# Return an xls file from a spreadsheet builder
def issues_to_xls
build_spreadsheet(@project, @issues, @query).xls
@ -79,5 +79,3 @@ module XlsReport
end
end
end
IssuesController.send(:include, XlsReport::IssuesControllerPatch)

@ -0,0 +1,5 @@
module OpenProject
module XlsExport
VERSION = "1.0.0"
end
end

@ -0,0 +1 @@
require 'open_project/xls_export'

@ -1,55 +0,0 @@
require_dependency 'issues_controller'
module PrintableIssues
module IssuesControllerPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
before_filter :find_optional_project,
:only => self.filter_chain.select{|f| f.method == :find_optional_project}[0].options[:only] + [:printable]
before_filter :authorize,
:except => self.filter_chain.select{|f| f.method == :authorize}[0].options[:except] + [:printable]
accept_key_auth :printable
end
end
module InstanceMethods
def printable
retrieve_query
sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
if @query.respond_to? :sortable_columns
sort_update(@query.sortable_columns)
else
sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
end
if @query.valid?
limit = Setting.issues_export_limit.to_i
@issue_count = @query.issue_count
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
:limit => limit,
:offset => 0,
:order => sort_clause)
@issue_count_by_group = @query.issue_count_by_group
@columns = @query.columns.reject{|c| %w(subject).include? c.name.to_s}
respond_to do |format|
format.html { render :template => 'issues/printable.rhtml', :layout => !request.xhr? }
end
else
# Send html if the query is not valid
render(:template => 'issues/printable.rhtml', :layout => !request.xhr?)
end
rescue ActiveRecord::RecordNotFound
render_404
end
end
end
end
IssuesController.send(:include, PrintableIssues::IssuesControllerPatch)

@ -0,0 +1,22 @@
# encoding: UTF-8
$:.push File.expand_path("../lib", __FILE__)
require 'open_project/xls_export/version'
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "openproject-xls_export"
s.version = OpenProject::XlsExport::VERSION
s.authors = "Finn GmbH"
s.email = "info@finn.de"
s.homepage = "http://www.finn.de"
s.summary = 'OpenProject plugin for exporting issue lists as Excel spreadsheets'
s.description = 'Export issue lists as Excel spreadsheets (.xls). Support for exporting
cost entries and cost reports is not yet migrated to Rails 3 and disabled.'
s.license = "GPLv3"
s.files = Dir["{app,config,db,lib}/**/*"] + %w(CHANGELOG.md README.md)
s.add_dependency "rails", "~> 3.2.14"
s.add_dependency "spreadsheet", "~>0.6.0"
s.add_dependency "openproject-plugins", "~> 1.0.0"
end
Loading…
Cancel
Save