Skip to content

Commit d1b5c55

Browse files
committed
Preserve original search scopes; fixes #71, #72
1 parent 0ba04cf commit d1b5c55

File tree

8 files changed

+104
-75
lines changed

8 files changed

+104
-75
lines changed

.travis.yml

+8-7
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ gemfile:
1313
env:
1414
- REDMINE_VER=2.3.4 DB=mysql
1515
- REDMINE_VER=2.6.9 DB=mysql
16-
- REDMINE_VER=3.1.6 DB=mysql
17-
- REDMINE_VER=3.2.3 DB=mysql
18-
- REDMINE_VER=3.3.0 DB=mysql
16+
- REDMINE_VER=3.1.7 DB=mysql
17+
- REDMINE_VER=3.2.4 DB=mysql
18+
- REDMINE_VER=3.3.1 DB=mysql
1919
- REDMINE_VER=2.3.4 DB=postgresql
2020
- REDMINE_VER=2.6.9 DB=postgresql
21-
- REDMINE_VER=3.1.6 DB=postgresql
22-
- REDMINE_VER=3.2.3 DB=postgresql
23-
- REDMINE_VER=3.3.0 DB=postgresql
21+
- REDMINE_VER=3.1.7 DB=postgresql
22+
- REDMINE_VER=3.2.4 DB=postgresql
23+
- REDMINE_VER=3.3.1 DB=postgresql
2424

2525
before_install:
2626
- export PLUGIN_NAME=redmine_tagging
@@ -29,6 +29,7 @@ before_install:
2929
- ln -s $TRAVIS_BUILD_DIR $REDMINE_PATH/plugins/$PLUGIN_NAME
3030
- cp config/database-$DB-travis.yml $REDMINE_PATH/config/database.yml
3131
- cp config/configuration-travis.yml $REDMINE_PATH/config/configuration.yml
32+
- echo "config.active_record.schema_format = :sql" > $REDMINE_PATH/config/additional_environment.rb
3233
- cd $REDMINE_PATH
3334

3435
before_script:
@@ -40,5 +41,5 @@ before_script:
4041
- bundle exec rake redmine:plugins:migrate
4142

4243
script:
43-
- bundle exec rake redmine_tagging:test
44+
- bundle exec rake redmine:plugins:test
4445

Gemfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
gem 'acts-as-taggable-on', '~> 3.4.1'
2-
gem 'rails_sql_views', git: 'git://github.com/Undev/rails_sql_views.git'
1+
gem 'acts-as-taggable-on', '~> 4.0'

README.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ The initial authors of the plugin are [Emiliano Heyns](mailto:emiliano.heyns@gma
3333

3434
2. Update the Gemfile.lock file by running the following commands:
3535

36-
rm Gemfile.lock
37-
bundle install
36+
bundle install
3837
3938
3. Run the migrations generator to create tables for tags and associations:
4039

@@ -49,6 +48,21 @@ The initial authors of the plugin are [Emiliano Heyns](mailto:emiliano.heyns@gma
4948

5049
Now you should be able to see the plugin in **Administration > Plugins**.
5150

51+
### For MySql users
52+
You can circumvent at any time the problem of special characters [issue 623](https://github.com/mbleigh/acts-as-taggable-on/issues/623) by setting in an initializer file:
53+
54+
```ruby
55+
ActsAsTaggableOn.force_binary_collation = true
56+
```
57+
58+
Or by running this rake task:
59+
60+
```shell
61+
bundle exec rake acts_as_taggable_on_engine:tag_names:collate_bin
62+
```
63+
64+
See the [configuration](https://github.com/mbleigh/acts-as-taggable-on#configuration) section in acts-as-taggable-on gem for more details.
65+
5266
## Usage
5367

5468
The plugin enables you to add tags to wiki and issue pages using either the **Tags** field or inline tags. To switch between these two modes, you should enable or disable the corresponding check boxes in the plugin settings.
@@ -93,4 +107,8 @@ Tags can be used to search for issues and create issue filters:
93107

94108
## Maintainers
95109

96-
Danil Tashkinov, [github.com/nodecarter](https://github.com/nodecarter)
110+
Danil Tashkinov, [github.com/nodecarter](https://github.com/nodecarter)
111+
112+
## Thanks to
113+
114+
* https://github.com/jkraemer

init.rb

+1-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name 'Redmine Tagging Plugin'
55
author 'Restream'
66
description 'This plugin adds tagging features to Redmine.'
7-
version '0.1.4'
7+
version '0.1.5'
88

99
settings default: {
1010
dynamic_font_size: '1',
@@ -98,28 +98,6 @@
9898
require 'redmine_tagging'
9999
require File.expand_path('../app/helpers/tagging_helper', __FILE__)
100100
ActionView::Base.send :include, TaggingHelper
101-
102-
unless Issue.searchable_options[:include] && Issue.searchable_options[:include].include?(:issue_tags)
103-
Issue.searchable_options[:columns] << "#{IssueTag.table_name}.tag"
104-
105-
# For redmine < 3
106-
Issue.searchable_options[:include] ||= []
107-
Issue.searchable_options[:include] << :issue_tags
108-
109-
# For redmine > 3
110-
Issue.searchable_options[:scope] = proc { Issue.includes(:issue_tags) }
111-
end
112-
113-
unless WikiPage.searchable_options[:include] && WikiPage.searchable_options[:include].include?(:wiki_page_tags)
114-
WikiPage.searchable_options[:columns] << "#{WikiPageTag.table_name}.tag"
115-
116-
# For redmine < 3
117-
WikiPage.searchable_options[:include] ||= []
118-
WikiPage.searchable_options[:include] << :wiki_page_tags
119-
120-
# For redmine > 3
121-
WikiPage.searchable_options[:scope] = proc { WikiPage.includes(:wiki_page_tags) }
122-
end
123101
end
124102

125103
require_dependency 'tagging_plugin/tagging_hooks'

lib/redmine_tagging.rb

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ module RedmineTagging
44
require 'redmine_tagging/patches/issue_patch'
55
require 'redmine_tagging/patches/project_patch'
66
require 'redmine_tagging/patches/query_patch'
7+
require 'redmine_tagging/patches/wiki_page_patch'
78
require 'redmine_tagging/patches/queries_helper_patch'
89
require 'redmine_tagging/patches/application_controller_patch'

lib/redmine_tagging/patches/issue_patch.rb

+22-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,30 @@ module RedmineTagging::Patches::IssuePatch
1818
alias_method_chain :create_journal, :tags
1919
alias_method_chain :init_journal, :tags
2020
alias_method_chain :copy_from, :tags
21+
22+
if Redmine::VERSION::MAJOR < 3
23+
searchable_options[:columns] << "#{IssueTag.table_name}.tag"
24+
searchable_options[:include] ||= []
25+
searchable_options[:include] << :issue_tags
26+
else
27+
searchable_options[:columns] << "#{IssueTag.table_name}.tag"
28+
29+
original_scope = searchable_options[:scope] || self
30+
31+
searchable_options[:scope] = ->(*args) {
32+
(original_scope.respond_to?(:call) ?
33+
original_scope.call(*args) :
34+
original_scope
35+
).includes :issue_tags
36+
}
37+
end
2138
end
2239

2340
def create_journal_with_tags
2441
if @current_journal
2542
tag_context = TaggingPlugin::ContextHelper.context_for(project)
26-
before = @issue_tags_before_change
27-
after = TaggingPlugin::TagsHelper.to_string(tag_list_on(tag_context))
43+
before = @issue_tags_before_change
44+
after = TaggingPlugin::TagsHelper.to_string(tag_list_on(tag_context))
2845
unless before == after
2946
@current_journal.details << JournalDetail.new(
3047
property: 'attr',
@@ -38,7 +55,7 @@ def create_journal_with_tags
3855

3956
def init_journal_with_tags(user, notes = "")
4057
unless project.nil?
41-
tag_context = TaggingPlugin::ContextHelper.context_for(project)
58+
tag_context = TaggingPlugin::ContextHelper.context_for(project)
4259
@issue_tags_before_change = TaggingPlugin::TagsHelper.to_string(tag_list_on(tag_context))
4360
end
4461
init_journal_without_tags(user, notes)
@@ -50,7 +67,7 @@ def tags
5067

5168
def copy_from_with_tags(arg, options = {})
5269
copy_from_without_tags(arg, options)
53-
issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
70+
issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
5471
self.tag_list_ctx = issue.tag_list_ctx
5572
self
5673
end
@@ -88,7 +105,7 @@ def cleanup_tags
88105
if @new_project_id
89106
context = TaggingPlugin::ContextHelper.context_for(project)
90107
ActsAsTaggableOn::Tagging.where(
91-
'context != ? AND taggable_id = ? AND taggable_type = ?', context, id, 'Issue'
108+
'context != ? AND taggable_id = ? AND taggable_type = ?', context, id, 'Issue'
92109
).delete_all
93110
end
94111
true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
require_dependency 'wiki_page'
2+
3+
module RedmineTagging::Patches::WikiPagePatch
4+
extend ActiveSupport::Concern
5+
6+
included do
7+
unloadable
8+
9+
attr_writer :tags_to_update
10+
11+
has_many :wiki_page_tags
12+
13+
acts_as_taggable
14+
15+
before_save :update_tags
16+
17+
if Redmine::VERSION::MAJOR < 3
18+
searchable_options[:columns] << "#{WikiPageTag.table_name}.tag"
19+
searchable_options[:include] ||= []
20+
searchable_options[:include] << :wiki_page_tags
21+
else
22+
searchable_options[:columns] << "#{WikiPageTag.table_name}.tag"
23+
24+
original_scope = searchable_options[:scope] || self
25+
26+
searchable_options[:scope] = ->(*args) {
27+
(original_scope.respond_to?(:call) ?
28+
original_scope.call(*args) :
29+
original_scope
30+
).includes :wiki_page_tags
31+
}
32+
end
33+
end
34+
35+
private
36+
37+
def update_tags
38+
if @tags_to_update
39+
project_context = TaggingPlugin::ContextHelper.context_for(project)
40+
set_tag_list_on(project_context, @tags_to_update)
41+
end
42+
43+
true
44+
end
45+
46+
end
47+
48+
unless WikiPage.included_modules.include? RedmineTagging::Patches::WikiPagePatch
49+
WikiPage.send :include, RedmineTagging::Patches::WikiPagePatch
50+
end

lib/tagging_plugin/tagging_patches.rb

-35
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
require_dependency 'issue'
2-
require_dependency 'wiki_page'
3-
41
module TaggingPlugin
52

63
module ProjectsHelperPatch
@@ -21,35 +18,6 @@ def project_settings_tabs_with_tags_tab
2118
end
2219
end
2320

24-
module WikiPagePatch
25-
def self.included(base) # :nodoc:
26-
base.send(:include, InstanceMethods)
27-
28-
base.class_eval do
29-
unloadable
30-
31-
attr_writer :tags_to_update
32-
33-
before_save :update_tags
34-
acts_as_taggable
35-
36-
has_many :wiki_page_tags
37-
end
38-
end
39-
40-
module InstanceMethods
41-
private
42-
def update_tags
43-
if @tags_to_update
44-
project_context = ContextHelper.context_for(project)
45-
set_tag_list_on(project_context, @tags_to_update)
46-
end
47-
48-
true
49-
end
50-
end
51-
end
52-
5321
module WikiControllerPatch
5422
def self.included(base) # :nodoc:
5523
base.send(:include, InstanceMethods)
@@ -75,8 +43,5 @@ def update_with_tags
7543
end
7644
end
7745

78-
WikiPage.send(:include, TaggingPlugin::WikiPagePatch) unless WikiPage.included_modules.include? TaggingPlugin::WikiPagePatch
79-
8046
WikiController.send(:include, TaggingPlugin::WikiControllerPatch) unless WikiController.included_modules.include? TaggingPlugin::WikiControllerPatch
81-
8247
ProjectsHelper.send(:include, TaggingPlugin::ProjectsHelperPatch) unless ProjectsHelper.included_modules.include? TaggingPlugin::ProjectsHelperPatch

0 commit comments

Comments
 (0)