Permalink
Browse files

Fixed redmine-2.1 compatibility

  • Loading branch information...
1 parent c5672f0 commit 9d999f9ff3e7511f49abb5c0ca69755085fbc3a2 @nettsundere nettsundere committed Dec 19, 2012
View
@@ -1,7 +1,2 @@
-gem "acts-as-taggable-on",
- :git => "git://github.com/Undev/acts-as-taggable-on.git",
- :branch => "rails2"
-
-gem "rails_sql_views",
- :git => "git://github.com/Undev/rails_sql_views.git",
- :branch => "rails2"
+gem 'acts-as-taggable-on', '~> 2.3.1'
+gem "rails_sql_views", :git => "git://github.com/anathematic/rails_sql_views.git"
View
@@ -27,7 +27,7 @@ You need to set up database for acts-as-taggable-on:
1a) for Rails 2 (which Redmine currently uses):
$ env RAILS_ENV=production script/generate acts_as_taggable_on_migration
1b) for Rails 3:
- $ rails generation acts_as_taggable_on:migration
+ $ rails generate acts_as_taggable_on:migration
2)
$ rake db:migrate RAILS_ENV=production
$ rake db:migrate_plugins RAILS_ENV=production
@@ -67,4 +67,4 @@ into
add_index :taggings, :taggable_type
add_index :taggings, :context
-in the migration of acts-as-taggable-on
+in the migration of acts-as-taggable-on
View
@@ -1,12 +0,0 @@
-require 'rake'
-require 'rake/testtask'
-
-desc "Default: run unit tests."
-task :default => :test
-
-desc "Test the redmine_tagging plugin."
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
-end
@@ -10,7 +10,7 @@ def destroy
context = TaggingPlugin::ContextHelper.context_for(@project)
- tag.taggings.find_each(:conditions => ['context=?', context]) do |tagging|
+ tag.taggings.where(:context => context).find_each do |tagging|
if tagging.taggable_type = "Issue"
affected_issue = Issue.find(tagging.taggable_id)
affected_issue.init_journal(User.current)
@@ -1,4 +1,4 @@
-module ApplicationHelper
+module TaggingHelper
def link_to_project_tag_filter(project, tag, options = {}, html_options = {})
options.reverse_merge!({
:status => 'o',
View
@@ -1,4 +1,6 @@
class IssueTag < ActiveRecord::Base
+ set_primary_key :id
+
belongs_to :issue
def readonly?
@@ -1,4 +1,6 @@
class WikiPageTag < ActiveRecord::Base
+ set_primary_key :id
+
belongs_to :wiki_page
def readonly?
@@ -11,12 +11,12 @@ api.array :issues, api_meta(:total_count => @issue_count, :offset => @offset, :l
api.category(:id => issue.category_id, :name => issue.category.name) unless issue.category.nil?
api.fixed_version(:id => issue.fixed_version_id, :name => issue.fixed_version.name) unless issue.fixed_version.nil?
api.parent(:id => issue.parent_id) unless issue.parent.nil?
-
- api.subject issue.subject
+
+ api.subject issue.subject
api.description issue.description
- api.start_date issue.start_date
- api.due_date issue.due_date
- api.done_ratio issue.done_ratio
+ api.start_date issue.start_date
+ api.due_date issue.due_date
+ api.done_ratio issue.done_ratio
api.estimated_hours issue.estimated_hours
render_api_custom_values issue.custom_field_values, api
@@ -29,6 +29,12 @@ api.array :issues, api_meta(:total_count => @issue_count, :offset => @offset, :l
api.tag(:id => issue_tag.tag[1..-1])
end
end
+
+ api.array :relations do
+ issue.relations.each do |relation|
+ api.relation(:id => relation.id, :issue_id => relation.issue_from_id, :issue_to_id => relation.issue_to_id, :relation_type => relation.relation_type, :delay => relation.delay)
+ end
+ end if include_in_api_response?('relations')
end
end
end
@@ -0,0 +1,73 @@
+api.issue do
+ api.id @issue.id
+ api.project(:id => @issue.project_id, :name => @issue.project.name) unless @issue.project.nil?
+ api.tracker(:id => @issue.tracker_id, :name => @issue.tracker.name) unless @issue.tracker.nil?
+ api.status(:id => @issue.status_id, :name => @issue.status.name) unless @issue.status.nil?
+ api.priority(:id => @issue.priority_id, :name => @issue.priority.name) unless @issue.priority.nil?
+ api.author(:id => @issue.author_id, :name => @issue.author.name) unless @issue.author.nil?
+ api.assigned_to(:id => @issue.assigned_to_id, :name => @issue.assigned_to.name) unless @issue.assigned_to.nil?
+ api.category(:id => @issue.category_id, :name => @issue.category.name) unless @issue.category.nil?
+ api.fixed_version(:id => @issue.fixed_version_id, :name => @issue.fixed_version.name) unless @issue.fixed_version.nil?
+ api.parent(:id => @issue.parent_id) unless @issue.parent.nil?
+
+ api.subject @issue.subject
+ api.description @issue.description
+ api.start_date @issue.start_date
+ api.due_date @issue.due_date
+ api.done_ratio @issue.done_ratio
+ api.estimated_hours @issue.estimated_hours
+ api.spent_hours(@issue.spent_hours) if User.current.allowed_to?(:view_time_entries, @project)
+
+ render_api_custom_values @issue.custom_field_values, api
+
+ api.created_on @issue.created_on
+ api.updated_on @issue.updated_on
+
+ api.array :tags do
+ @issue.issue_tags.each do |issue_tag|
+ api.tag(:id => issue_tag.tag[1..-1])
+ end
+ end
+
+ render_api_issue_children(@issue, api) if include_in_api_response?('children')
+
+ api.array :attachments do
+ @issue.attachments.each do |attachment|
+ render_api_attachment(attachment, api)
+ end
+ end if include_in_api_response?('attachments')
+
+ api.array :relations do
+ @relations.each do |relation|
+ api.relation(:id => relation.id, :issue_id => relation.issue_from_id, :issue_to_id => relation.issue_to_id, :relation_type => relation.relation_type, :delay => relation.delay)
+ end
+ end if include_in_api_response?('relations') && @relations.present?
+
+ api.array :changesets do
+ @issue.changesets.each do |changeset|
+ api.changeset :revision => changeset.revision do
+ api.user(:id => changeset.user_id, :name => changeset.user.name) unless changeset.user.nil?
+ api.comments changeset.comments
+ api.committed_on changeset.committed_on
+ end
+ end
+ end if include_in_api_response?('changesets') && User.current.allowed_to?(:view_changesets, @project)
+
+ api.array :journals do
+ @issue.journals.each do |journal|
+ api.journal :id => journal.id do
+ api.user(:id => journal.user_id, :name => journal.user.name) unless journal.user.nil?
+ api.notes journal.notes
+ api.created_on journal.created_on
+ api.array :details do
+ journal.details.each do |detail|
+ api.detail :property => detail.property, :name => detail.prop_key do
+ api.old_value detail.old_value
+ api.new_value detail.value
+ end
+ end
+ end
+ end
+ end
+ end if include_in_api_response?('journals')
+end
@@ -1,3 +0,0 @@
-if(typeof jQuery == 'undefined') {
- document.write('<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>')
-}
View
@@ -1,3 +1,3 @@
-ActionController::Routing::Routes.draw do |map|
- map.resources :issue_tags, :only => [:destroy]
+RedmineApp::Application.routes.draw do
+ resources :issue_tags, :only => [:destroy]
end
View
19 init.rb
@@ -1,25 +1,16 @@
require 'redmine'
-require 'dispatcher'
-Dispatcher.to_prepare do
- require_dependency 'tagging_plugin/tagging_patches'
- require_dependency 'tagging_plugin/tagging_query_patch'
+ActionDispatch::Callbacks.to_prepare do
+ require 'tagging_plugin/tagging_patches'
+ require 'tagging_plugin/tagging_query_patch'
+ require 'tagging_plugin/api_template_handler_patch'
if !Issue.searchable_options[:include].include? :issue_tags
Issue.searchable_options[:columns] << "#{IssueTag.table_name}.tag"
Issue.searchable_options[:include] << :issue_tags
end
if !WikiPage.searchable_options[:include].include? :wiki_page_tags
- # I now know _way_ to much about activerecord... activerecord
- # builds an SQL string, _then scans that string_ for tables to use
- # in its join constructions. I really do hope that's a temporary
- # workaround. Why it has ever worked is beyond me. Reference:
- # construct_finder_sql_for_association_limiting in
- # active_record/associations.rb
- WikiPage.searchable_options[:columns] = WikiPage.searchable_options[:columns].select{|c| c != 'text'}
- WikiPage.searchable_options[:columns] << "#{WikiContent.table_name}.text"
-
WikiPage.searchable_options[:columns] << "#{WikiPageTag.table_name}.tag"
WikiPage.searchable_options[:include] << :wiki_page_tags
end
@@ -100,7 +91,7 @@
link_to(tag, search_url)
end.join('&nbsp;')
- "<div class='tags'>#{taglinks}</div>"
+ raw("<div class='tags'>#{taglinks}</div>")
else
''
end
@@ -0,0 +1,34 @@
+module TaggingPlugin
+ module ApiTemplateHandlerPatch
+ class << self
+ def included(base)
+ base.send(:extend, ClassMethods)
+ base.class_eval do
+ class << self
+ alias_method_chain :call, :api_replacement
+ end
+ end
+ end
+ end
+
+ module ClassMethods
+ def call_with_api_replacement(template)
+ template = replace_if(template, /views\/issues\/index.api.rsb$/, "plugins/redmine_tagging/app/views/issues/index_with_tags.api.rsb")
+ template = replace_if(template, /views\/issues\/show.api.rsb$/, "plugins/redmine_tagging/app/views/issues/show_with_tags.api.rsb")
+ call_without_api_replacement(template)
+ end
+
+ def replace_if(template, regexp, new_path)
+ if template.identifier =~ regexp
+ source = File.open(new_path).read
+ identifier = template.identifier
+ handler = template.handler
+ template = ActionView::Template.new(source, identifier, handler, {})
+ end
+ template
+ end
+ end
+ end
+end
+
+Redmine::Views::ApiTemplateHandler.send(:include, TaggingPlugin::ApiTemplateHandlerPatch)
@@ -30,11 +30,9 @@ def view_layouts_base_html_head(context = {})
})
result = <<-TAGS
- #{javascript_include_tag 'jquery_loader', :plugin => 'redmine_tagging'}
<script type="text/javascript">
- var $j = jQuery.noConflict()
- $j(function() {
- $j('#sidebar').append("#{escape_javascript(tag_cloud)}")
+ $(function() {
+ $('#sidebar').append("#{escape_javascript(tag_cloud)}")
})
</script>
TAGS
@@ -93,9 +91,8 @@ def view_issues_form_details_bottom(context={ })
ac = ac.collect{|tag| "'#{escape_javascript(tag.gsub(/^#/, ''))}'"}.join(', ')
tags += <<-generatedscript
<script type="text/javascript">
- var $j = jQuery.noConflict()
- $j(document).ready(function() {
- $j('#issue_tags').tagSuggest({ tags: [#{ac}] })
+ $(document).ready(function() {
+ $('#issue_tags').tagSuggest({ tags: [#{ac}] })
})
</script>
generatedscript
@@ -188,10 +185,9 @@ def view_layouts_base_content(context = {})
tags += <<-generatedscript
<script type="text/javascript">
- var $j = jQuery.noConflict()
- $j(document).ready(function() {
- $j('#tagging_wiki_edit_block').insertAfter($j("#content_text"))
- $j('#wiki_page_tags').tagSuggest({ tags: [#{ac}] })
+ $(document).ready(function() {
+ $('#tagging_wiki_edit_block').insertAfter($("#content_text"))
+ $('#wiki_page_tags').tagSuggest({ tags: [#{ac}] })
})
</script>
generatedscript
@@ -61,6 +61,7 @@ def self.included(base) # :nodoc:
before_save :update_tags
acts_as_taggable
+
after_save :cleanup_tags
has_many :issue_tags
@@ -98,6 +99,8 @@ def update_tags
# Fix context if project changed
if project_id_changed? && !new_record?
+ @new_project_id = project_id
+
taggings.update_all(:context => project_context)
end
@@ -109,17 +112,25 @@ def update_tags
end
def cleanup_tags
- if project_id_changed?
+ if @new_project_id
context = ContextHelper.context_for(project)
- condition = ["context != ? AND taggable_id = ? AND taggable_type= ?", context, id, "Issue"]
- ActsAsTaggableOn::Tagging.delete_all(condition)
+ ActsAsTaggableOn::Tagging.where("
+ context!=? AND taggable_id=? AND taggable_type=?",
+ context, id, "Issue").delete_all
end
-
true
end
end
end
+ module TaggingHelperPatch
+ def self.included(base)
+ base.class_eval do
+ helper :tagging
+ end
+ end
+ end
+
module WikiControllerPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
@@ -147,6 +158,10 @@ def update_with_tags
WikiPage.send(:include, TaggingPlugin::WikiPagePatch) unless WikiPage.included_modules.include? TaggingPlugin::WikiPagePatch
+[IssuesController, ReportsController, WikiController, ProjectsController].each do |controller|
+ controller.send(:include, TaggingPlugin::TaggingHelperPatch) unless controller.include? TaggingPlugin::TaggingHelperPatch
+end
+
WikiController.send(:include, TaggingPlugin::WikiControllerPatch) unless WikiController.included_modules.include? TaggingPlugin::WikiControllerPatch
ProjectsHelper.send(:include, TaggingPlugin::ProjectsHelperPatch) unless ProjectsHelper.included_modules.include? TaggingPlugin::ProjectsHelperPatch
@@ -11,7 +11,8 @@ def self.included(base) # :nodoc:
alias_method_chain :available_filters, :tags
alias_method_chain :sql_for_field, :tags
- add_available_column(QueryColumn.new(:issue_tags, :caption => :tags))
+ tag_query_column = QueryColumn.new(:issue_tags, :caption => :field_tags)
+ add_available_column(tag_query_column)
end
end
@@ -34,6 +35,7 @@ def available_filters_with_tags
"tags" => {
:type => :list_optional,
:values => tags,
+ :name => l(:field_tags),
:order => 20
}
}
Oops, something went wrong.

0 comments on commit 9d999f9

Please sign in to comment.