Skip to content

Commit

Permalink
Build on the redmine search infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
friflaj committed Sep 24, 2010
1 parent b9628b8 commit 3fc85f3
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 88 deletions.
7 changes: 7 additions & 0 deletions README.rdoc
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions 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
12 changes: 12 additions & 0 deletions 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
4 changes: 2 additions & 2 deletions app/views/tagging/_tagcloud.erb
Expand Up @@ -22,8 +22,8 @@
<h3><%= l(:tagging_tags) %></h3>
<div id='tagcloud'>
<% 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 %>
</div>
Expand Down
47 changes: 0 additions & 47 deletions app/views/tagging/tagged.erb

This file was deleted.

14 changes: 14 additions & 0 deletions 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

28 changes: 21 additions & 7 deletions 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'
Expand Down Expand Up @@ -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('&nbsp;')
"<div class='tags'>#{taglinks}</div>"
end
Expand Down
75 changes: 43 additions & 32 deletions 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

0 comments on commit 3fc85f3

Please sign in to comment.