diff --git a/README.rdoc b/README.rdoc
index 76f654b..3dae6bb 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -19,11 +19,18 @@ original plugin from http://github.com/mbleigh/acts-as-taggable-on
needs patches to make it compatible with rails 2.3.5, which Redmine
uses.
+The plugin also needs rails_sql_views 0.7.0, installed by doing:
+ $ git clone git://github.com/woodchuck/rails_sql_views.git
+ $ cd rails_sql_views
+ $ rake gem
+ $ sudo gem install --local pkg/rails_sql_views-0.7.0.gem
+
= Installation
While patches to acts-as-taggable-on are not merged to upstream, you should
use a fork of it. Installation is performed with:
+ $ gem install rails_sql_views
$ script/plugin install git://github.com/rymai/acts-as-taggable-on.git
$ script/plugin install git://github.com/friflaj/redmine_tagging.git
diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb
new file mode 100644
index 0000000..26d3d71
--- /dev/null
+++ b/app/models/issue_tag.rb
@@ -0,0 +1,12 @@
+class IssueTag < ActiveRecord::Base
+ belongs_to :issue
+
+ def readonly?
+ return true
+ end
+
+ # Prevent objects from being destroyed
+ def before_destroy
+ raise ActiveRecord::ReadOnlyRecord
+ end
+end
diff --git a/app/models/wiki_page_tag.rb b/app/models/wiki_page_tag.rb
new file mode 100644
index 0000000..6cf2fb8
--- /dev/null
+++ b/app/models/wiki_page_tag.rb
@@ -0,0 +1,12 @@
+class WikiPageTag < ActiveRecord::Base
+ belongs_to :wiki_page
+
+ def readonly?
+ return true
+ end
+
+ # Prevent objects from being destroyed
+ def before_destroy
+ raise ActiveRecord::ReadOnlyRecord
+ end
+end
diff --git a/app/views/tagging/_tagcloud.erb b/app/views/tagging/_tagcloud.erb
index 0fbe3e7..7b826b4 100644
--- a/app/views/tagging/_tagcloud.erb
+++ b/app/views/tagging/_tagcloud.erb
@@ -22,8 +22,8 @@
<%= l(:tagging_tags) %>
<% tags.each_pair do |tag, count| %>
- <%= link_to("#{tag}",
- {:controller => "tagging", :action => "index", :project_id => project.identifier, :tags => tag},
+ <%= link_to("##{tag}",
+ {:controller => "search", :action => "index", :id => project, :q => tag, :wiki_pages => true, :issues => true},
{:rel => count}) %>
<% end %>
diff --git a/app/views/tagging/tagged.erb b/app/views/tagging/tagged.erb
deleted file mode 100644
index 7524622..0000000
--- a/app/views/tagging/tagged.erb
+++ /dev/null
@@ -1,47 +0,0 @@
-<%- context = @project.identifier.gsub '-', '_' -%>
-<%- content_for :header_tags do %>
- <%= stylesheet_link_tag 'tagging', :plugin => 'redmine_tagging' %>
-<% end %>
-<%= l(:tagging_selected_tags)%>: <% @tags.each do |tag| %> <%= tag %> <% end %>
-
diff --git a/db/migrate/011_create_views.rb b/db/migrate/011_create_views.rb
new file mode 100755
index 0000000..571e649
--- /dev/null
+++ b/db/migrate/011_create_views.rb
@@ -0,0 +1,14 @@
+require 'rails_sql_views'
+
+class CreateViews < ActiveRecord::Migration
+ def self.up
+ create_view :issue_tags, "select taggings.id, tags.name as tag, taggings.taggable_id as issue_id from taggings join tags on taggings.tag_id = tags.id where taggable_type = 'Issue'"
+ create_view :wiki_page_tags, "select taggings.id, tags.name as tag, taggings.taggable_id as wiki_page_id from taggings join tags on taggings.tag_id = tags.id where taggable_type = 'WikiPage'"
+ end
+
+ def self.down
+ drop_view :issue_tags
+ drop_view :wiki_page_tags
+ end
+end
+
diff --git a/init.rb b/init.rb
index 72f1357..75e60d3 100644
--- a/init.rb
+++ b/init.rb
@@ -1,13 +1,27 @@
require 'redmine'
+require 'dispatcher'
-require 'tagging_patches'
+Dispatcher.to_prepare do
+ require_dependency 'tagging_patches'
-ActionController::Dispatcher.to_prepare do
- require_dependency 'issue'
- require_dependency 'wiki_page'
+ if !Issue.searchable_options[:include].include? :issue_tags
+ Issue.searchable_options[:columns] << "#{IssueTag.table_name}.tag"
+ Issue.searchable_options[:include] << :issue_tags
+ end
- WikiPage.send(:include, WikiPagePatch) unless WikiPage.included_modules.include? WikiPagePatch
- Issue.send(:include, IssuePatch) unless Issue.included_modules.include? IssuePatch
+ 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
end
require_dependency 'tagging_hooks'
@@ -44,7 +58,7 @@
end
taglinks = tags.collect{|tag|
- link_to("##{tag}", {:controller => "tagging", :action => "index", :project_id => project.identifier, :tags => tag})
+ link_to("##{tag}", {:controller => "search", :action => "index", :id => project, :q => tag, :wiki_pages => true, :issues => true})
}.join(' ')
"#{taglinks}
"
end
diff --git a/lib/tagging_patches.rb b/lib/tagging_patches.rb
index 996c3db..a8aa537 100755
--- a/lib/tagging_patches.rb
+++ b/lib/tagging_patches.rb
@@ -1,39 +1,50 @@
require_dependency 'issue'
-
-module WikiPagePatch
- def self.included(base) # :nodoc:
- base.extend(ClassMethods)
- base.send(:include, InstanceMethods)
-
- base.class_eval do
- unloadable
-
- acts_as_taggable
+require_dependency 'wiki_page'
+
+module Tagging
+ module WikiPagePatch
+ def self.included(base) # :nodoc:
+ base.extend(ClassMethods)
+ base.send(:include, InstanceMethods)
+
+ base.class_eval do
+ unloadable
+
+ acts_as_taggable
+
+ has_many :wiki_page_tags
+ end
+ end
+
+ module ClassMethods
+ end
+
+ module InstanceMethods
end
end
-
- module ClassMethods
- end
-
- module InstanceMethods
- end
-end
-
-module IssuePatch
- def self.included(base) # :nodoc:
- base.extend(ClassMethods)
- base.send(:include, InstanceMethods)
-
- base.class_eval do
- unloadable
-
- acts_as_taggable
+
+ module IssuePatch
+ def self.included(base) # :nodoc:
+ base.extend(ClassMethods)
+ base.send(:include, InstanceMethods)
+
+ base.class_eval do
+ unloadable
+
+ acts_as_taggable
+
+ has_many :issue_tags
+ end
+ end
+
+ module ClassMethods
+ end
+
+ module InstanceMethods
end
end
+end
- module ClassMethods
- end
+Issue.send(:include, Tagging::IssuePatch) unless Issue.included_modules.include? Tagging::IssuePatch
- module InstanceMethods
- end
-end
+WikiPage.send(:include, Tagging::WikiPagePatch) unless WikiPage.included_modules.include? Tagging::WikiPagePatch