Revision 1078:b9e34a051f82 vendor/plugins/redmine_tags/lib/redmine_tags/patches
| vendor/plugins/redmine_tags/lib/redmine_tags/patches/project_patch.rb | ||
|---|---|---|
| 13 | 13 |
unloadable |
| 14 | 14 |
|
| 15 | 15 |
attr_accessor :tag_list |
| 16 |
|
|
| 17 | 16 |
acts_as_taggable |
| 18 | 17 |
|
| 19 | 18 |
end |
| 20 | 19 |
end |
| 21 | 20 |
|
| 22 |
def before_save_with_save_tags() |
|
| 23 |
# debugger |
|
| 24 |
logger.error { "GONNA SAVE TAG LIST" }
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
# params[:tag_list] |
|
| 28 |
|
|
| 29 |
|
|
| 30 |
# logger.error { @project.name }
|
|
| 31 |
|
|
| 32 |
# if params && params[:project] && !params[:project][:tag_list].nil? |
|
| 33 |
# old_tags = context[:project].tag_list.to_s |
|
| 34 |
# context[:project].tag_list = params[:project][:tag_list] |
|
| 35 |
# new_tags = context[:project].tag_list.to_s |
|
| 36 |
# |
|
| 37 |
# unless (old_tags == new_tags || context[:project].current_journal.blank?) |
|
| 38 |
# context[:project].current_journal.details << JournalDetail.new(:property => 'attr', |
|
| 39 |
# :prop_key => 'tag_list', |
|
| 40 |
# :old_value => old_tags, |
|
| 41 |
# :value => new_tags) |
|
| 42 |
# end |
|
| 43 |
# end |
|
| 44 |
end |
|
| 45 |
|
|
| 46 | 21 |
module InstanceMethods |
| 47 |
|
|
| 48 | 22 |
end |
| 49 | 23 |
|
| 50 | 24 |
module ClassMethods |
| ... | ... | |
| 64 | 38 |
name_like = options[:name_like] |
| 65 | 39 |
options = {}
|
| 66 | 40 |
visible = ARCondition.new |
| 67 |
|
|
| 41 |
|
|
| 68 | 42 |
visible << ["#{Project.table_name}.is_public = '1'"]
|
| 69 | 43 |
|
| 70 | 44 |
if name_like |
| ... | ... | |
| 73 | 47 |
|
| 74 | 48 |
options[:conditions] = visible.conditions |
| 75 | 49 |
|
| 76 |
self.all_tag_counts(options)
|
|
| 50 |
self.all_tag_counts(options) |
|
| 77 | 51 |
end |
| 78 | 52 |
end |
| 79 | 53 |
end |
| vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_controller_patch.rb | ||
|---|---|---|
| 1 |
# -*- coding: utf-8 -*- |
|
| 1 | 2 |
require_dependency 'projects_controller' |
| 2 | 3 |
|
| 3 | 4 |
module RedmineTags |
| 4 | 5 |
module Patches |
| 5 |
module ProjectsControllerPatch
|
|
| 6 |
module ProjectsControllerPatch |
|
| 6 | 7 |
def self.included(base) |
| 7 | 8 |
base.send(:include, InstanceMethods) |
| 8 |
base.class_eval do
|
|
| 9 |
unloadable
|
|
| 9 |
base.class_eval do |
|
| 10 |
unloadable |
|
| 10 | 11 |
skip_before_filter :authorize, :only => [:set_fieldset_status] |
| 11 | 12 |
skip_before_filter :find_project, :only => [:set_fieldset_status] |
| 12 | 13 |
before_filter :add_tags_to_project, :only => [:save, :update] |
| ... | ... | |
| 16 | 17 |
end |
| 17 | 18 |
|
| 18 | 19 |
module InstanceMethods |
| 19 |
|
|
| 20 |
|
|
| 20 | 21 |
def add_tags_to_project |
| 21 | 22 |
|
| 22 | 23 |
if params && params[:project] && !params[:project][:tag_list].nil? |
| ... | ... | |
| 56 | 57 |
else |
| 57 | 58 |
@myproj_status = session[:my_projects_fieldset_status] |
| 58 | 59 |
end |
| 59 |
|
|
| 60 |
|
|
| 60 | 61 |
if session[:filters_fieldset_status].nil? |
| 61 | 62 |
@filter_status = "false" |
| 62 | 63 |
else |
| 63 | 64 |
@filter_status = session[:filters_fieldset_status] |
| 64 | 65 |
end |
| 65 |
|
|
| 66 |
|
|
| 66 | 67 |
if params && params[:project] && !params[:project][:tag_list].nil? |
| 67 | 68 |
@filter_status = "true" |
| 68 | 69 |
end |
| 69 |
|
|
| 70 |
|
|
| 70 | 71 |
end |
| 71 | 72 |
|
| 72 | 73 |
# Lists visible projects. Paginator is for top-level projects only |
| ... | ... | |
| 77 | 78 |
get_fieldset_statuses |
| 78 | 79 |
|
| 79 | 80 |
respond_to do |format| |
| 80 |
format.html {
|
|
| 81 |
format.html {
|
|
| 81 | 82 |
paginate_projects |
| 82 |
|
|
| 83 |
@projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
|
|
| 83 |
|
|
| 84 |
@projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause) |
|
| 84 | 85 |
|
| 85 | 86 |
if User.current.logged? |
| 86 | 87 |
# seems sort_by gives us case-sensitive ordering, which we don't want |
| 87 | 88 |
# @user_projects = User.current.projects.sort_by(&:name) |
| 88 | 89 |
@user_projects = User.current.projects.all(:order => :name) |
| 89 | 90 |
end |
| 90 |
|
|
| 91 |
|
|
| 91 | 92 |
render :template => 'projects/index.html.erb', :layout => !request.xhr? |
| 92 | 93 |
} |
| 93 | 94 |
format.api {
|
| ... | ... | |
| 111 | 112 |
|
| 112 | 113 |
private |
| 113 | 114 |
|
| 114 |
def filter_projects
|
|
| 115 |
@question = (params[:q] || "").strip
|
|
| 115 |
def filter_projects |
|
| 116 |
@question = (params[:q] || "").strip |
|
| 116 | 117 |
|
| 117 | 118 |
if params.has_key?(:project) |
| 118 | 119 |
@tag_list = (params[:project][:tag_list] || "").strip.split(",")
|
| ... | ... | |
| 125 | 126 |
else |
| 126 | 127 |
@projects = Project.visible_roots.find(Project.visible.search_by_question(@question)) |
| 127 | 128 |
end |
| 128 |
|
|
| 129 |
|
|
| 129 | 130 |
unless @tag_list.empty? |
| 130 |
@tagged_projects_ids = Project.visible.tagged_with(@tag_list).collect{ |project| Project.find(project.id) }
|
|
| 131 |
@tagged_projects_ids = Project.visible.tagged_with(@tag_list).collect{ |project| Project.find(project.id).root }
|
|
| 131 | 132 |
@projects = @projects & @tagged_projects_ids |
| 133 |
@projects = @projects.uniq |
|
| 132 | 134 |
end |
| 133 |
|
|
| 134 |
@projects = @projects.collect{ |project| project.root }
|
|
| 135 |
@projects = @projects.uniq |
|
| 136 |
|
|
| 137 | 135 |
end |
| 138 | 136 |
end |
| 139 | 137 |
end |
| vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_helper_patch.rb | ||
|---|---|---|
| 4 | 4 |
|
| 5 | 5 |
def self.included(base) # :nodoc: |
| 6 | 6 |
base.send(:include, InstanceMethods) |
| 7 |
base.send(:include, TagsHelper) |
|
| 8 |
|
|
| 7 | 9 |
base.class_eval do |
| 8 | 10 |
unloadable |
| 9 | 11 |
end |
| 10 | 12 |
end |
| 11 | 13 |
|
| 12 |
module InstanceMethods
|
|
| 14 |
module InstanceMethods |
|
| 13 | 15 |
# Renders a tree of projects that the current user does not belong |
| 14 | 16 |
# to, or of all projects if the current user is not logged in. The |
| 15 | 17 |
# given collection may be a subset of the whole project tree |
| ... | ... | |
| 18 | 20 |
# description, manager(s), creation date, last activity date, |
| 19 | 21 |
# general activity level, whether there is anything actually hosted |
| 20 | 22 |
# here for the project, etc. |
| 21 |
def render_project_table_with_filtering(projects, question)
|
|
| 23 |
def render_project_table_with_filtering(projects, question) |
|
| 22 | 24 |
custom_fields = "" |
| 23 | 25 |
s = "" |
| 24 | 26 |
if projects.any? |
| 25 | 27 |
tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields) |
| 26 |
|
|
| 28 |
|
|
| 27 | 29 |
s << "<div class='autoscroll'>" |
| 28 | 30 |
s << "<table class='list projects'>" |
| 29 | 31 |
s << "<thead><tr>" |
| 30 |
|
|
| 32 |
|
|
| 31 | 33 |
s << sort_header_tag('name', :caption => l("field_name"))
|
| 32 | 34 |
s << "<th class='tags'>" << l("tags") << "</th>"
|
| 33 | 35 |
s << "<th class='managers'>" << l("label_managers") << "</th>"
|
| 34 | 36 |
s << sort_header_tag('created_on', :default_order => 'desc')
|
| 35 | 37 |
s << sort_header_tag('updated_on', :default_order => 'desc')
|
| 36 |
|
|
| 38 |
|
|
| 37 | 39 |
s << "</tr></thead><tbody>" |
| 38 |
|
|
| 40 |
|
|
| 39 | 41 |
original_project = @project |
| 40 |
|
|
| 42 |
|
|
| 41 | 43 |
projects.each do |project| |
| 42 | 44 |
s << render_project_in_table_with_filtering(project, cycle('odd', 'even'), 0, tokens)
|
| 43 | 45 |
end |
| 44 |
|
|
| 46 |
|
|
| 45 | 47 |
s << "</table>" |
| 46 | 48 |
else |
| 47 | 49 |
s << "\n" |
| ... | ... | |
| 51 | 53 |
s |
| 52 | 54 |
end |
| 53 | 55 |
|
| 54 |
def render_project_in_table_with_filtering(project, oddeven, level, tokens)
|
|
| 56 |
def render_project_in_table_with_filtering(project, oddeven, level, tokens) |
|
| 55 | 57 |
# set the project environment to please macros. |
| 56 | 58 |
@project = project |
| 57 | 59 |
|
| ... | ... | |
| 71 | 73 |
s << "<td class='tags' align=top>" << project.tag_counts.collect{ |t| render_project_tag_link(t) }.join(', ') << "</td>"
|
| 72 | 74 |
|
| 73 | 75 |
s << "<td class='managers' align=top>" |
| 74 |
|
|
| 76 |
|
|
| 75 | 77 |
u = project.users_by_role |
| 76 | 78 |
if u |
| 77 | 79 |
u.keys.each do |r| |
| ... | ... | |
| 90 | 92 |
end |
| 91 | 93 |
|
| 92 | 94 |
s << "</td>" |
| 93 |
|
|
| 95 |
|
|
| 94 | 96 |
s << "<td class='created_on' align=top>" << format_date(project.created_on) << "</td>" |
| 95 | 97 |
s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>" |
| 96 | 98 |
|
| ... | ... | |
| 104 | 106 |
|
| 105 | 107 |
s |
| 106 | 108 |
end |
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 110 | 112 |
# Renders a tree of projects as a nested set of unordered lists |
| 111 | 113 |
# The given collection may be a subset of the whole project tree |
| 112 | 114 |
# (eg. some intermediate nodes are private and can not be seen) |
| ... | ... | |
| 115 | 117 |
if projects.any? |
| 116 | 118 |
tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields) |
| 117 | 119 |
debugger |
| 118 |
|
|
| 120 |
|
|
| 119 | 121 |
|
| 120 | 122 |
ancestors = [] |
| 121 | 123 |
original_project = @project |
| ... | ... | |
| 127 | 129 |
else |
| 128 | 130 |
ancestors.pop |
| 129 | 131 |
s << "</li>" |
| 130 |
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
|
| 132 |
while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) |
|
| 131 | 133 |
ancestors.pop |
| 132 | 134 |
s << "</ul></li>" |
| 133 | 135 |
end |
| 134 | 136 |
end |
| 135 | 137 |
classes = (ancestors.empty? ? 'root' : 'child') |
| 136 | 138 |
s << "<li class='#{classes}'><div class='#{classes}'>" +
|
| 137 |
link_to( highlight_tokens(project.name, tokens),
|
|
| 139 |
link_to( highlight_tokens(project.name, tokens), |
|
| 138 | 140 |
{:controller => 'projects', :action => 'show', :id => project},
|
| 139 | 141 |
:class => "project #{User.current.member_of?(project) ? 'my-project' : nil}"
|
| 140 | 142 |
) |
| ... | ... | |
| 145 | 147 |
# value = value_model.present? ? value_model.value : nil |
| 146 | 148 |
# s << "<li><b>#{field.name.humanize}:</b> #{highlight_tokens(value, tokens)}</li>" if value.present?
|
| 147 | 149 |
# end |
| 148 |
|
|
| 150 |
|
|
| 149 | 151 |
s << "</ul>" |
| 150 | 152 |
s << "<div class='clear'></div>" |
| 151 | 153 |
unless project.description.blank? |
| ... | ... | |
| 162 | 164 |
end |
| 163 | 165 |
s.join "\n" |
| 164 | 166 |
end |
| 165 |
|
|
| 167 |
|
|
| 166 | 168 |
# Renders a tree of projects where the current user belongs |
| 167 | 169 |
# as a nested set of unordered lists |
| 168 | 170 |
# The given collection may be a subset of the whole project tree |
| ... | ... | |
| 192 | 194 |
s |
| 193 | 195 |
|
| 194 | 196 |
end |
| 195 |
|
|
| 196 |
|
|
| 197 |
|
|
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 198 | 200 |
|
| 199 | 201 |
def render_my_project_in_hierarchy_with_tags(project) |
| 200 | 202 |
|
| ... | ... | |
| 214 | 216 |
else |
| 215 | 217 |
s << " <span class='private'>" << l(:field_is_private) << "</span>" |
| 216 | 218 |
end |
| 217 |
|
|
| 219 |
|
|
| 218 | 220 |
tc = project.tag_counts |
| 219 | 221 |
if tc.empty? |
| 220 | 222 |
s << " <span class='no-tags'>" << l(:field_no_tags) << "</span>" |
| ... | ... | |
| 241 | 243 |
|
| 242 | 244 |
end |
| 243 | 245 |
|
| 244 |
|
|
| 245 |
|
|
| 246 |
|
|
| 247 |
|
|
| 246 | 248 |
private |
| 247 |
|
|
| 249 |
|
|
| 248 | 250 |
# copied from search_helper. This one doesn't escape html or limit the text length |
| 249 | 251 |
def highlight_tokens(text, tokens) |
| 250 | 252 |
return text unless text && tokens && !tokens.empty? |
| 251 | 253 |
re_tokens = tokens.collect {|t| Regexp.escape(t)}
|
| 252 |
regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE
|
|
| 254 |
regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE
|
|
| 253 | 255 |
result = '' |
| 254 | 256 |
text.split(regexp).each_with_index do |words, i| |
| 255 | 257 |
words = words.mb_chars |
| ... | ... | |
| 262 | 264 |
end |
| 263 | 265 |
result |
| 264 | 266 |
end |
| 265 |
|
|
| 267 |
|
|
| 266 | 268 |
end |
| 267 | 269 |
end |
| 268 | 270 |
end |
Also available in: Unified diff