To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / vendor / plugins / redmine_tags / lib / redmine_tags / patches / projects_helper_patch.rb @ 800:95b78e19e586
History | View | Annotate | Download (9.08 KB)
| 1 | 739:b7ac21913927 | luis | module RedmineTags |
|---|---|---|---|
| 2 | module Patches |
||
| 3 | module ProjectsHelperPatch |
||
| 4 | |||
| 5 | def self.included(base) # :nodoc: |
||
| 6 | base.send(:include, InstanceMethods) |
||
| 7 | base.class_eval do
|
||
| 8 | unloadable |
||
| 9 | end
|
||
| 10 | end
|
||
| 11 | |||
| 12 | 753:7877f25a19d6 | luis | module InstanceMethods |
| 13 | # Renders a tree of projects that the current user does not belong
|
||
| 14 | # to, or of all projects if the current user is not logged in. The
|
||
| 15 | # given collection may be a subset of the whole project tree
|
||
| 16 | # (eg. some intermediate nodes are private and can not be seen). We
|
||
| 17 | # are potentially interested in various things: the project name,
|
||
| 18 | # description, manager(s), creation date, last activity date,
|
||
| 19 | # general activity level, whether there is anything actually hosted
|
||
| 20 | # here for the project, etc.
|
||
| 21 | 776:af852d82b00b | luis | def render_project_table_with_filtering(projects, question) |
| 22 | 753:7877f25a19d6 | luis | custom_fields = ""
|
| 23 | s = ""
|
||
| 24 | if projects.any?
|
||
| 25 | tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields)
|
||
| 26 | |||
| 27 | s << "<div class='autoscroll'>"
|
||
| 28 | s << "<table class='list projects'>"
|
||
| 29 | s << "<thead><tr>"
|
||
| 30 | |||
| 31 | s << sort_header_tag('name', :caption => l("field_name")) |
||
| 32 | s << "<th class='managers'>" << l("label_managers") << "</th>" |
||
| 33 | s << "<th class='tags'>" << l("tags") << "</th>" |
||
| 34 | s << sort_header_tag('created_on', :default_order => 'desc') |
||
| 35 | s << sort_header_tag('updated_on', :default_order => 'desc') |
||
| 36 | |||
| 37 | s << "</tr></thead><tbody>"
|
||
| 38 | |||
| 39 | original_project = @project
|
||
| 40 | |||
| 41 | projects.each do |project|
|
||
| 42 | s << render_project_in_table_with_filtering(project, cycle('odd', 'even'), 0, tokens) |
||
| 43 | end
|
||
| 44 | |||
| 45 | s << "</table>"
|
||
| 46 | else
|
||
| 47 | s << "\n"
|
||
| 48 | end
|
||
| 49 | @project = original_project
|
||
| 50 | |||
| 51 | s |
||
| 52 | end
|
||
| 53 | |||
| 54 | def render_project_in_table_with_filtering(project, oddeven, level, tokens) |
||
| 55 | # set the project environment to please macros.
|
||
| 56 | @project = project
|
||
| 57 | |||
| 58 | classes = (level == 0 ? 'root' : 'child') |
||
| 59 | |||
| 60 | s = ""
|
||
| 61 | |||
| 62 | s << "<tr class='#{oddeven} #{classes} level#{level}'>"
|
||
| 63 | s << "<td class='firstcol' align=top><div class='name hosted_here"
|
||
| 64 | s << " no_description" if project.description.blank? |
||
| 65 | s << "'>" << link_to( highlight_tokens(project.name, tokens), {:controller => 'projects', :action => 'show', :id => project}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}") |
||
| 66 | s << "</div>"
|
||
| 67 | 796:6d3ad4b3a500 | luis | s << highlight_tokens(render_project_short_description(project), tokens) |
| 68 | 753:7877f25a19d6 | luis | s << "<td class='managers' align=top>"
|
| 69 | |||
| 70 | u = project.users_by_role |
||
| 71 | if u
|
||
| 72 | u.keys.each do |r|
|
||
| 73 | if r.allowed_to?(:edit_project) |
||
| 74 | mgrs = [] |
||
| 75 | u[r].sort.each do |m|
|
||
| 76 | mgrs << link_to_user(m) |
||
| 77 | end
|
||
| 78 | if mgrs.size < 3 |
||
| 79 | s << '<nobr>' << mgrs.join(', ') << '</nobr>' |
||
| 80 | else
|
||
| 81 | s << mgrs.join(', ')
|
||
| 82 | end
|
||
| 83 | end
|
||
| 84 | end
|
||
| 85 | end
|
||
| 86 | |||
| 87 | s << "</td>"
|
||
| 88 | |||
| 89 | # taglist
|
||
| 90 | s << "<td class='tags' align=top>" << project.tag_counts.collect{ |t| render_project_tag_link(t) }.join(', ') << "</td>" |
||
| 91 | s << "<td class='created_on' align=top>" << format_date(project.created_on) << "</td>" |
||
| 92 | s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>" |
||
| 93 | |||
| 94 | s << "</tr>"
|
||
| 95 | |||
| 96 | project.children.each do |child|
|
||
| 97 | if child.is_public? or User.current.member_of?(child) |
||
| 98 | s << render_project_in_table_with_filtering(child, oddeven, level + 1, tokens)
|
||
| 99 | end
|
||
| 100 | end
|
||
| 101 | |||
| 102 | s |
||
| 103 | end
|
||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | 739:b7ac21913927 | luis | # Renders a tree of projects as a nested set of unordered lists
|
| 108 | # The given collection may be a subset of the whole project tree
|
||
| 109 | # (eg. some intermediate nodes are private and can not be seen)
|
||
| 110 | def render_project_hierarchy_with_filtering(projects,custom_fields,question) |
||
| 111 | s = [] |
||
| 112 | if projects.any?
|
||
| 113 | tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields)
|
||
| 114 | debugger |
||
| 115 | |||
| 116 | |||
| 117 | ancestors = [] |
||
| 118 | original_project = @project
|
||
| 119 | projects.each do |project|
|
||
| 120 | # set the project environment to please macros.
|
||
| 121 | @project = project
|
||
| 122 | if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
|
||
| 123 | s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>"
|
||
| 124 | else
|
||
| 125 | ancestors.pop |
||
| 126 | s << "</li>"
|
||
| 127 | while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
||
| 128 | ancestors.pop |
||
| 129 | s << "</ul></li>"
|
||
| 130 | end
|
||
| 131 | end
|
||
| 132 | classes = (ancestors.empty? ? 'root' : 'child') |
||
| 133 | s << "<li class='#{classes}'><div class='#{classes}'>" +
|
||
| 134 | link_to( highlight_tokens(project.name, tokens), |
||
| 135 | {:controller => 'projects', :action => 'show', :id => project},
|
||
| 136 | :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}" |
||
| 137 | ) |
||
| 138 | s << "<ul class='filter_fields'>"
|
||
| 139 | |||
| 140 | # CustomField.usable_for_project_filtering.each do |field|
|
||
| 141 | # value_model = project.custom_value_for(field.id)
|
||
| 142 | # value = value_model.present? ? value_model.value : nil
|
||
| 143 | # s << "<li><b>#{field.name.humanize}:</b> #{highlight_tokens(value, tokens)}</li>" if value.present?
|
||
| 144 | # end
|
||
| 145 | |||
| 146 | s << "</ul>"
|
||
| 147 | s << "<div class='clear'></div>"
|
||
| 148 | unless project.description.blank?
|
||
| 149 | s << "<div class='wiki description'>"
|
||
| 150 | s << "<b>#{ t(:field_description) }:</b>"
|
||
| 151 | s << highlight_tokens(textilizable(project.short_description, :project => project), tokens)
|
||
| 152 | s << "\n</div>"
|
||
| 153 | end
|
||
| 154 | s << "</div>"
|
||
| 155 | ancestors << project |
||
| 156 | end
|
||
| 157 | ancestors.size.times{ s << "</li></ul>" }
|
||
| 158 | @project = original_project
|
||
| 159 | end
|
||
| 160 | s.join "\n"
|
||
| 161 | end
|
||
| 162 | |||
| 163 | 800:95b78e19e586 | luis | # Renders a tree of projects where the current user belongs
|
| 164 | # as a nested set of unordered lists
|
||
| 165 | # The given collection may be a subset of the whole project tree
|
||
| 166 | # (eg. some intermediate nodes are private and can not be seen)
|
||
| 167 | def render_my_project_hierarchy_with_tags(projects) |
||
| 168 | |||
| 169 | s = ''
|
||
| 170 | |||
| 171 | original_project = @project
|
||
| 172 | |||
| 173 | projects.each do |project|
|
||
| 174 | if project.root? || !projects.include?(project.parent)
|
||
| 175 | s << render_my_project_in_hierarchy_with_tags(project) |
||
| 176 | end
|
||
| 177 | end
|
||
| 178 | |||
| 179 | @project = original_project
|
||
| 180 | |||
| 181 | if s != '' |
||
| 182 | a = ''
|
||
| 183 | a << "<ul class='projects root'>\n"
|
||
| 184 | a << s |
||
| 185 | a << "</ul>\n"
|
||
| 186 | s = a |
||
| 187 | end
|
||
| 188 | |||
| 189 | s |
||
| 190 | |||
| 191 | end
|
||
| 192 | |||
| 193 | |||
| 194 | |||
| 195 | |||
| 196 | def render_my_project_in_hierarchy_with_tags(project) |
||
| 197 | |||
| 198 | s = ''
|
||
| 199 | |||
| 200 | if User.current.member_of?(project) |
||
| 201 | |||
| 202 | # set the project environment to please macros.
|
||
| 203 | @project = project
|
||
| 204 | |||
| 205 | classes = (project.root? ? 'root' : 'child') |
||
| 206 | |||
| 207 | s << "<li class='#{classes}'><div class='#{classes}'>" +
|
||
| 208 | link_to_project(project, {}, :class => "project my-project")
|
||
| 209 | if project.is_public?
|
||
| 210 | s << " <span class='public'>" << l("field_is_public") << "</span>" |
||
| 211 | else
|
||
| 212 | s << " <span class='private'>" << l("field_is_private") << "</span>" |
||
| 213 | end
|
||
| 214 | s << render_project_short_description(project) |
||
| 215 | |||
| 216 | s << l(:tags) << ": " |
||
| 217 | s << project.tag_counts.collect{ |t| render_project_tag_link(t) }.join(', ')
|
||
| 218 | |||
| 219 | s << "</div>\n"
|
||
| 220 | |||
| 221 | cs = ''
|
||
| 222 | project.children.each do |child|
|
||
| 223 | cs << render_my_project_in_hierarchy(child) |
||
| 224 | end
|
||
| 225 | |||
| 226 | if cs != '' |
||
| 227 | s << "<ul class='projects'>\n" << cs << "</ul>\n"; |
||
| 228 | end
|
||
| 229 | |||
| 230 | end
|
||
| 231 | |||
| 232 | s |
||
| 233 | |||
| 234 | end
|
||
| 235 | |||
| 236 | |||
| 237 | |||
| 238 | 739:b7ac21913927 | luis | private |
| 239 | |||
| 240 | # copied from search_helper. This one doesn't escape html or limit the text length
|
||
| 241 | def highlight_tokens(text, tokens) |
||
| 242 | return text unless text && tokens && !tokens.empty? |
||
| 243 | re_tokens = tokens.collect {|t| Regexp.escape(t)}
|
||
| 244 | regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE |
||
| 245 | result = ''
|
||
| 246 | text.split(regexp).each_with_index do |words, i|
|
||
| 247 | words = words.mb_chars |
||
| 248 | if i.even?
|
||
| 249 | result << words |
||
| 250 | else
|
||
| 251 | t = (tokens.index(words.downcase) || 0) % 4 |
||
| 252 | result << content_tag('span', words, :class => "highlight token-#{t}") |
||
| 253 | end
|
||
| 254 | end
|
||
| 255 | result |
||
| 256 | end
|
||
| 257 | |||
| 258 | end
|
||
| 259 | end
|
||
| 260 | end
|
||
| 261 | end
|