Mercurial > hg > soundsoftware-site
changeset 1067:2ad2f9ab46a6 bibplugin_cache
moved the tags helper patch from the projects helper patch to the projects controller patch
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Tue, 20 Nov 2012 16:55:13 +0000 |
parents | 5b9e5464d162 |
children | e11d8d13ebc5 |
files | vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_controller_patch.rb vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_helper_patch.rb |
diffstat | 2 files changed, 46 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_controller_patch.rb Tue Nov 20 10:36:40 2012 +0000 +++ b/vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_controller_patch.rb Tue Nov 20 16:55:13 2012 +0000 @@ -3,21 +3,24 @@ module RedmineTags module Patches - module ProjectsControllerPatch + module ProjectsControllerPatch def self.included(base) base.send(:include, InstanceMethods) - base.class_eval do - unloadable + base.class_eval do + unloadable skip_before_filter :authorize, :only => [:set_fieldset_status] skip_before_filter :find_project, :only => [:set_fieldset_status] before_filter :add_tags_to_project, :only => [:save, :update] + helper :tags + include TagsHelper + alias :index filtered_index end end module InstanceMethods - + def add_tags_to_project if params && params[:project] && !params[:project][:tag_list].nil? @@ -57,17 +60,17 @@ else @myproj_status = session[:my_projects_fieldset_status] end - + if session[:filters_fieldset_status].nil? @filter_status = "false" else @filter_status = session[:filters_fieldset_status] end - + if params && params[:project] && !params[:project][:tag_list].nil? @filter_status = "true" end - + end # Lists visible projects. Paginator is for top-level projects only @@ -78,17 +81,17 @@ get_fieldset_statuses respond_to do |format| - format.html { + format.html { paginate_projects - - @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause) + + @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause) if User.current.logged? # seems sort_by gives us case-sensitive ordering, which we don't want # @user_projects = User.current.projects.sort_by(&:name) @user_projects = User.current.projects.all(:order => :name) end - + render :template => 'projects/index.html.erb', :layout => !request.xhr? } format.api { @@ -112,8 +115,8 @@ private - def filter_projects - @question = (params[:q] || "").strip + def filter_projects + @question = (params[:q] || "").strip if params.has_key?(:project) @tag_list = (params[:project][:tag_list] || "").strip.split(",") @@ -126,7 +129,7 @@ else @projects = Project.visible_roots.find(Project.visible.search_by_question(@question)) end - + unless @tag_list.empty? @tagged_projects_ids = Project.visible.tagged_with(@tag_list).collect{ |project| Project.find(project.id).root } @projects = @projects & @tagged_projects_ids
--- a/vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_helper_patch.rb Tue Nov 20 10:36:40 2012 +0000 +++ b/vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_helper_patch.rb Tue Nov 20 16:55:13 2012 +0000 @@ -4,13 +4,13 @@ def self.included(base) # :nodoc: base.send(:include, InstanceMethods) - base.send(:include, TagsHelper) + # base.send(:include, TagsHelper) base.class_eval do unloadable end end - module InstanceMethods + module InstanceMethods # Renders a tree of projects that the current user does not belong # to, or of all projects if the current user is not logged in. The # given collection may be a subset of the whole project tree @@ -19,30 +19,30 @@ # description, manager(s), creation date, last activity date, # general activity level, whether there is anything actually hosted # here for the project, etc. - def render_project_table_with_filtering(projects, question) + def render_project_table_with_filtering(projects, question) custom_fields = "" s = "" if projects.any? tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields) - + s << "<div class='autoscroll'>" s << "<table class='list projects'>" s << "<thead><tr>" - + s << sort_header_tag('name', :caption => l("field_name")) s << "<th class='tags'>" << l("tags") << "</th>" s << "<th class='managers'>" << l("label_managers") << "</th>" s << sort_header_tag('created_on', :default_order => 'desc') s << sort_header_tag('updated_on', :default_order => 'desc') - + s << "</tr></thead><tbody>" - + original_project = @project - + projects.each do |project| s << render_project_in_table_with_filtering(project, cycle('odd', 'even'), 0, tokens) end - + s << "</table>" else s << "\n" @@ -52,7 +52,7 @@ s end - def render_project_in_table_with_filtering(project, oddeven, level, tokens) + def render_project_in_table_with_filtering(project, oddeven, level, tokens) # set the project environment to please macros. @project = project @@ -72,7 +72,7 @@ s << "<td class='tags' align=top>" << project.tag_counts.collect{ |t| render_project_tag_link(t) }.join(', ') << "</td>" s << "<td class='managers' align=top>" - + u = project.users_by_role if u u.keys.each do |r| @@ -91,7 +91,7 @@ end s << "</td>" - + s << "<td class='created_on' align=top>" << format_date(project.created_on) << "</td>" s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>" @@ -105,9 +105,9 @@ s end - - - + + + # Renders a tree of projects as a nested set of unordered lists # The given collection may be a subset of the whole project tree # (eg. some intermediate nodes are private and can not be seen) @@ -116,7 +116,7 @@ if projects.any? tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields) debugger - + ancestors = [] original_project = @project @@ -128,14 +128,14 @@ else ancestors.pop s << "</li>" - while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) + while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) ancestors.pop s << "</ul></li>" end end classes = (ancestors.empty? ? 'root' : 'child') s << "<li class='#{classes}'><div class='#{classes}'>" + - link_to( highlight_tokens(project.name, tokens), + link_to( highlight_tokens(project.name, tokens), {:controller => 'projects', :action => 'show', :id => project}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}" ) @@ -146,7 +146,7 @@ # value = value_model.present? ? value_model.value : nil # s << "<li><b>#{field.name.humanize}:</b> #{highlight_tokens(value, tokens)}</li>" if value.present? # end - + s << "</ul>" s << "<div class='clear'></div>" unless project.description.blank? @@ -163,7 +163,7 @@ end s.join "\n" end - + # Renders a tree of projects where the current user belongs # as a nested set of unordered lists # The given collection may be a subset of the whole project tree @@ -193,9 +193,9 @@ s end - - - + + + def render_my_project_in_hierarchy_with_tags(project) @@ -215,7 +215,7 @@ else s << " <span class='private'>" << l(:field_is_private) << "</span>" end - + tc = project.tag_counts if tc.empty? s << " <span class='no-tags'>" << l(:field_no_tags) << "</span>" @@ -242,15 +242,15 @@ end - - + + private - + # copied from search_helper. This one doesn't escape html or limit the text length def highlight_tokens(text, tokens) return text unless text && tokens && !tokens.empty? re_tokens = tokens.collect {|t| Regexp.escape(t)} - regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE + regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE result = '' text.split(regexp).each_with_index do |words, i| words = words.mb_chars @@ -263,7 +263,7 @@ end result end - + end end end