Skip to content

Commit

Permalink
Added in-line or external tag edit as a configurable option
Browse files Browse the repository at this point in the history
  • Loading branch information
friflaj committed Sep 27, 2010
1 parent 2503419 commit 90262e4
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 8 deletions.
11 changes: 11 additions & 0 deletions README.rdoc
Expand Up @@ -43,3 +43,14 @@ You need to set up database for acts-as-taggable-on:
$ rake db:migrate_plugins

See the README of acts-as-taggable-on for details.

I've added a switch so you can choose between in-line tag editing with
{{tag(some tags here-or-there)}} or editing the tags in a separate
edit field. After you've changed the setting in Administration ->
Plugins -> Configure -> Tagging, run

$ rake redmine:tagging:reconfigure

to put tags in the body or remove them, depending on what you
configured for your installation. Not doing so will cause data (tag)
loss when moving from non-inline to inline.
4 changes: 4 additions & 0 deletions app/views/tagging/_settings.html.erb
@@ -0,0 +1,4 @@
<p>
<%= content_tag(:label, l(:tagging_inline)) %>
<%= check_box_tag("settings[inline]", "1", Setting.plugin_redmine_tagging[:inline] == "1") %>
</p>
1 change: 1 addition & 0 deletions config/locales/en.yml
@@ -1,3 +1,4 @@
# English strings go here for Rails i18n
en:
field_tags: "Tags"
tagging_inline: "Inline editing of tags"
1 change: 1 addition & 0 deletions config/locales/nl.yml
@@ -1,3 +1,4 @@
# English strings go here for Rails i18n
nl:
field_tags: "Tags"
tagging_inline: "Tags bewerking in text"
32 changes: 32 additions & 0 deletions init.rb
Expand Up @@ -33,6 +33,8 @@
description 'Wiki/issues tagging'
version '0.0.1'

settings :default => { :inline => "0" }, :partial => 'tagging/settings'

Redmine::WikiFormatting::Macros.register do
desc "Wiki/Issues tagcloud"
macro :tagcloud do |obj, args|
Expand All @@ -50,4 +52,34 @@
end
end

Redmine::WikiFormatting::Macros.register do
desc "Wiki/Issues tag"
macro :tag do |obj, args|
if Setting.plugin_redmine_tagging[:inline] == "1"
args, options = extract_macro_options(args, :parent)
tags = args.collect{|a| a.split(/[#"'\s,]+/)}.flatten.select{|tag| !tag.blank?}.collect{|tag| "##{tag}" }.uniq.sort

if obj.is_a? WikiContent
obj = obj.page
project = obj.wiki.project
else
project = obj.project
end
context = project.identifier.gsub('-', '_')

# only save if there are differences
if obj.tag_list_on(context).sort.join(',') != tags.join(',')
obj.set_tag_list_on(context, tags.join(', '))
obj.save
end

taglinks = tags.collect{|tag|
link_to("#{tag}", {:controller => "search", :action => "index", :id => project, :q => tag, :wiki_pages => true, :issues => true})
}.join('&nbsp;')
"<div class='tags'>#{taglinks}</div>"
else
''
end
end
end
end
16 changes: 14 additions & 2 deletions lib/tagging_hooks.rb
Expand Up @@ -9,6 +9,8 @@ def view_issues_sidebar_planning_bottom(context={ })
end

def view_issues_show_details_bottom(context={ })
return '' if Setting.plugin_redmine_tagging[:inline] == "1"

issue = context[:issue]
snippet = ''

Expand All @@ -24,6 +26,8 @@ def view_issues_show_details_bottom(context={ })
end

def view_issues_form_details_bottom(context={ })
return '' if Setting.plugin_redmine_tagging[:inline] == "1"

issue = context[:issue]

tag_context = issue.project.identifier.gsub('-', '_')
Expand Down Expand Up @@ -51,12 +55,14 @@ def view_issues_form_details_bottom(context={ })
end

def controller_issues_edit_after_save(context = {})
return if Setting.plugin_redmine_tagging[:inline] == "1"

return unless context[:params] && context[:params]['issue']

issue = context[:issue]
tags = context[:params]['issue']['tags'].to_s

tags = tags.split(/[\s,]+/).collect{|tag| "##{tag}"}.join(', ')
tags = tags.split(/[#"'\s,]+/).collect{|tag| "##{tag}"}.join(', ')
tag_context = issue.project.identifier.gsub('-', '_')

issue.set_tag_list_on(tag_context, tags)
Expand All @@ -65,6 +71,8 @@ def controller_issues_edit_after_save(context = {})

# wikis have no view hooks
def view_layouts_base_content(context = {})
return '' if Setting.plugin_redmine_tagging[:inline] == "1"

return '' unless context[:controller].is_a? WikiController

request = context[:request]
Expand Down Expand Up @@ -114,18 +122,22 @@ def view_layouts_base_content(context = {})
end

def controller_wiki_edit_after_save(context = {})
return if Setting.plugin_redmine_tagging[:inline] == "1"

return unless context[:params]

project = context[:page].wiki.project

tags = context[:params]['wikipage_tags'].to_s.split(/[\s,]+/).collect{|tag| "##{tag}"}.join(', ')
tags = context[:params]['wikipage_tags'].to_s.split(/[#"'\s,]+/).collect{|tag| "##{tag}"}.join(', ')
tag_context = project.identifier.gsub('-', '_')

context[:page].set_tag_list_on(tag_context, tags)
context[:page].save
end

def view_layouts_base_html_head(context = {})
return '' if Setting.plugin_redmine_tagging[:inline] == "1"

return "
<style>
span.tagMatches {
Expand Down
8 changes: 4 additions & 4 deletions lib/tagging_patches.rb
@@ -1,7 +1,7 @@
require_dependency 'issue'
require_dependency 'wiki_page'

module Tagging
module TaggingPlugin
module WikiPagePatch
def self.included(base) # :nodoc:
base.extend(ClassMethods)
Expand Down Expand Up @@ -87,8 +87,8 @@ def edit_with_save_tags
end
end

Issue.send(:include, Tagging::IssuePatch) unless Issue.included_modules.include? Tagging::IssuePatch
Issue.send(:include, TaggingPlugin::IssuePatch) unless Issue.included_modules.include? TaggingPlugin::IssuePatch

WikiPage.send(:include, Tagging::WikiPagePatch) unless WikiPage.included_modules.include? Tagging::WikiPagePatch
WikiPage.send(:include, TaggingPlugin::WikiPagePatch) unless WikiPage.included_modules.include? TaggingPlugin::WikiPagePatch

WikiController.send(:include, Tagging::WikiControllerPatch) unless WikiController.included_modules.include? Tagging::WikiControllerPatch
WikiController.send(:include, TaggingPlugin::WikiControllerPatch) unless WikiController.included_modules.include? TaggingPlugin::WikiControllerPatch
4 changes: 2 additions & 2 deletions lib/tagging_query_patch.rb
@@ -1,6 +1,6 @@
require_dependency 'query'

module Tagging
module TaggingPlugin
module QueryPatch
def self.included(base) # :nodoc:
base.extend(ClassMethods)
Expand Down Expand Up @@ -70,4 +70,4 @@ def add_available_column(column)
end
end

Query.send(:include, Tagging::QueryPatch) unless Query.included_modules.include? Tagging::QueryPatch
Query.send(:include, TaggingPlugin::QueryPatch) unless Query.included_modules.include? TaggingPlugin::QueryPatch
57 changes: 57 additions & 0 deletions lib/tasks/reconfigure.rake
@@ -0,0 +1,57 @@
namespace :redmine do
namespace :tagging do
desc "Reconfigure for inline/separate tag editing"
task :reconfigure => :environment do

if Setting.plugin_redmine_tagging[:inline] == "1"
puts "Adding inline tags"

Issue.find(:all).each {|issue|
tag_context = issue.project.identifier.gsub('-', '_')
tags = issue.tag_list_on(tag_context).collect {|tag| tag.gsub(/^#/, '') }.sort.join(', ')

next if tags.blank? && issue.description.blank?

tags = "{{tag(#{tags})}}"

issue.description = '' if issue.description.blank?
issue.description = issue.description.gsub(/[{]{2}tag[(][^)]*[)][}]{2}/i, tags)
issue.description += "\n\n#{tags}" unless issue.description =~ /[{]{2}tag[(][^)]*[)][}]{2}/i

issue.save!
}

WikiContent.find(:all).each {|content|
tag_context = content.page.wiki.project.identifier.gsub('-', '_')
tags = content.page.tag_list_on(tag_context).collect {|tag| tag.gsub(/^#/, '') }.sort.join(', ')

next if tags.blank? && content.text.blank?

tags = "{{tag(#{tags})}}"

content.text = '' if content.text.blank?
content.text = content.text.gsub(/[{]{2}tag[(][^)]*[)][}]{2}/i, tags)
content.text += "\n\n#{tags}" unless content.text =~ /[{]{2}tag[(][^)]*[)][}]{2}/i

content.save!
}
else
puts "Removing inline tags"
Issue.find(:all, :conditions => "lower(description) like '%{{tag(%'").each {|issue|
next if issue.description.blank?

issue.description = issue.description.gsub(/[{]{2}tag[(][^)]*[)][}]{2}/i, '')
issue.save!
}

WikiContent.find(:all, :conditions => "lower(text) like '%{{tag(%'").each {|content|
next if content.text.blank?

content.text = content.text.gsub(/[{]{2}tag[(][^)]*[)][}]{2}/i, '')
content.save!
}
end

end
end
end

0 comments on commit 90262e4

Please sign in to comment.