changeset 1244:a3ed5c4d90f0 redmine-2.2-integration

The Create Project page now allows for correct search/insertion of tags. Using the new version of the redmine tags plugin.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Wed, 27 Mar 2013 14:52:16 +0000
parents b1d3bc0b7f7e
children d8e15cc24494
files plugins/redmine_tags/app/views/projects/_tags_form.html.erb plugins/redmine_tags/lib/redmine_tags/hooks/model_project_hook.rb plugins/redmine_tags/lib/redmine_tags/patches/project_patch.rb
diffstat 3 files changed, 41 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/redmine_tags/app/views/projects/_tags_form.html.erb	Tue Mar 26 16:26:50 2013 +0000
+++ b/plugins/redmine_tags/app/views/projects/_tags_form.html.erb	Wed Mar 27 14:52:16 2013 +0000
@@ -5,7 +5,23 @@
     <em class="info"><%= l(:text_tags_info).html_safe %></em>
   </p>
   <div id="project_tag_candidates" class="autocomplete"></div>
-  <%= javascript_include_tag 'tags_input', :plugin => 'redmine_tags' %>
-  <%= javascript_tag "observeProjectTagsField('#{url_for(:controller => 'auto_completes', :action => 'project_tags')}', false)" %>
+  <%= stylesheet_link_tag 'jquery.tagit.css', :plugin => 'redmine_tags' %>
+  <%= stylesheet_link_tag 'redmine_tags', :plugin => 'redmine_tags' %>
+  <%= javascript_include_tag 'tag-it', :plugin => 'redmine_tags' %>
+
+  <%= javascript_tag "$('#project_tag_list').tagit({
+            tagSource: function(search, showChoices) {
+            var that = this;
+            $.ajax({
+              url: '#{url_for(:controller => 'auto_completes', :action => 'project_tags')}',
+              data: {q: search.term},
+              success: function(choices) {
+              showChoices(that._subtractArray(jQuery.parseJSON(choices), that.assignedTags()));
+            }
+          });
+        },
+    });
+" %>
+
 </div>
 <% end -%>
--- a/plugins/redmine_tags/lib/redmine_tags/hooks/model_project_hook.rb	Tue Mar 26 16:26:50 2013 +0000
+++ b/plugins/redmine_tags/lib/redmine_tags/hooks/model_project_hook.rb	Wed Mar 27 14:52:16 2013 +0000
@@ -21,7 +21,6 @@
   module Hooks
     class ModelProjectHook < Redmine::Hook::ViewListener
       def controller_project_before_save(context={})
-        debugger
         save_tags_to_project(context, true)
       end
 
@@ -30,15 +29,12 @@
       # cleared on reload. So instead, hook in after the Issue#save to update
       # this issue's tag_list and call #save ourselves.
       def controller_projects_before_save(context={})
-        debugger
         save_tags_to_project(context, false)
         context[:project].save
       end
 
       def save_tags_to_project(context, create_journal)
         params = context[:params]
-        debugger
-        logger.error { "WORKING" }
 
    #     if params && params[:issue] && !params[:issue][:tag_list].nil?
    #       old_tags = context[:issue].tag_list.to_s
--- a/plugins/redmine_tags/lib/redmine_tags/patches/project_patch.rb	Tue Mar 26 16:26:50 2013 +0000
+++ b/plugins/redmine_tags/lib/redmine_tags/patches/project_patch.rb	Wed Mar 27 14:52:16 2013 +0000
@@ -22,6 +22,14 @@
       end
 
       module ClassMethods
+        TAGGING_IDS_LIMIT_SQL = <<-SQL
+            tag_id IN (
+                SELECT #{ActsAsTaggableOn::Tagging.table_name}.tag_id
+                FROM #{ActsAsTaggableOn::Tagging.table_name}
+                WHERE #{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN (?)
+            )
+        SQL
+
         def search_by_question(question)
           if question.length > 1
             search(RedmineProjectFiltering.calculate_tokens(question), nil, :all_words => true).first.sort_by(&:lft)
@@ -30,24 +38,26 @@
           end
         end
 
+        # Returns available project tags
+        # Does not return tags from private projects
+        # === Parameters
+        # * <i>options</i> = (optional) Options hash of
+        #   * name_like - String. Substring to filter found tags.
+        def available_tags( options = {} )
+          ids_scope = Project.visible
 
-        # Returns available project tags
-        #  does not show tags from private projects
-        def available_tags( options = {} )
+          conditions = [""]
 
-          name_like = options[:name_like]
-          options = {}
-          visible   = ARCondition.new
-
-          visible << ["#{Project.table_name}.is_public = '1'"]
-
-          if name_like
-            visible << ["#{ActsAsTaggableOn::Tag.table_name}.name LIKE ?", "%#{name_like.downcase}%"]
+          # limit to the tags matching given %name_like%
+          if options[:name_like]
+            conditions[0] << "#{ActsAsTaggableOn::Tag.table_name}.name LIKE ? AND "
+            conditions << "%#{options[:name_like].downcase}%"
           end
 
-          options[:conditions] = visible.conditions
+          conditions[0] << TAGGING_IDS_LIMIT_SQL
+          conditions << ids_scope.map{ |issue| issue.id }.push(-1)
 
-          self.all_tag_counts(options)
+          self.all_tag_counts(:conditions => conditions)
         end
       end
     end