Revision 1067:2ad2f9ab46a6 vendor/plugins

View differences:

vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_controller_patch.rb
3 3

  
4 4
module RedmineTags
5 5
  module Patches
6
    module ProjectsControllerPatch      
6
    module ProjectsControllerPatch
7 7
      def self.included(base)
8 8
        base.send(:include, InstanceMethods)
9
        base.class_eval do          
10
          unloadable 
9
        base.class_eval do
10
          unloadable
11 11
          skip_before_filter :authorize, :only => [:set_fieldset_status]
12 12
          skip_before_filter :find_project, :only => [:set_fieldset_status]
13 13
          before_filter :add_tags_to_project, :only => [:save, :update]
14 14

  
15
          helper :tags
16
          include TagsHelper
17

  
15 18
          alias :index filtered_index
16 19
        end
17 20
      end
18 21

  
19 22
      module InstanceMethods
20
                
23

  
21 24
        def add_tags_to_project
22 25

  
23 26
          if params && params[:project] && !params[:project][:tag_list].nil?
......
57 60
          else
58 61
            @myproj_status = session[:my_projects_fieldset_status]
59 62
          end
60
                    
63

  
61 64
          if session[:filters_fieldset_status].nil?
62 65
            @filter_status = "false"
63 66
          else
64 67
            @filter_status = session[:filters_fieldset_status]
65 68
          end
66
          
69

  
67 70
          if params && params[:project] && !params[:project][:tag_list].nil?
68 71
            @filter_status = "true"
69 72
          end
70
                                      
73

  
71 74
        end
72 75

  
73 76
        # Lists visible projects. Paginator is for top-level projects only
......
78 81
          get_fieldset_statuses
79 82

  
80 83
          respond_to do |format|
81
            format.html { 
84
            format.html {
82 85
              paginate_projects
83
              
84
              @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause) 
86

  
87
              @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
85 88

  
86 89
              if User.current.logged?
87 90
                # seems sort_by gives us case-sensitive ordering, which we don't want
88 91
                #          @user_projects = User.current.projects.sort_by(&:name)
89 92
                @user_projects = User.current.projects.all(:order => :name)
90 93
              end
91
              
94

  
92 95
              render :template => 'projects/index.html.erb', :layout => !request.xhr?
93 96
            }
94 97
            format.api {
......
112 115

  
113 116
        private
114 117

  
115
        def filter_projects                  
116
          @question = (params[:q] || "").strip     
118
        def filter_projects
119
          @question = (params[:q] || "").strip
117 120

  
118 121
          if params.has_key?(:project)
119 122
            @tag_list = (params[:project][:tag_list] || "").strip.split(",")
......
126 129
          else
127 130
            @projects = Project.visible_roots.find(Project.visible.search_by_question(@question))
128 131
          end
129
  
132

  
130 133
          unless @tag_list.empty?
131 134
            @tagged_projects_ids = Project.visible.tagged_with(@tag_list).collect{ |project| Project.find(project.id).root }
132 135
            @projects = @projects & @tagged_projects_ids
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)
7
        # base.send(:include, TagsHelper)
8 8
        base.class_eval do
9 9
          unloadable
10 10
        end
11 11
      end
12 12

  
13
      module InstanceMethods        
13
      module InstanceMethods
14 14
        # Renders a tree of projects that the current user does not belong
15 15
        # to, or of all projects if the current user is not logged in.  The
16 16
        # given collection may be a subset of the whole project tree
......
19 19
        # description, manager(s), creation date, last activity date,
20 20
        # general activity level, whether there is anything actually hosted
21 21
        # here for the project, etc.
22
        def render_project_table_with_filtering(projects, question)          
22
        def render_project_table_with_filtering(projects, question)
23 23
          custom_fields = ""
24 24
          s = ""
25 25
          if projects.any?
26 26
            tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields)
27
            
27

  
28 28
            s << "<div class='autoscroll'>"
29 29
            s << "<table class='list projects'>"
30 30
            s << "<thead><tr>"
31
        
31

  
32 32
            s << sort_header_tag('name', :caption => l("field_name"))
33 33
            s << "<th class='tags'>" << l("tags") << "</th>"
34 34
            s << "<th class='managers'>" << l("label_managers") << "</th>"
35 35
            s << sort_header_tag('created_on', :default_order => 'desc')
36 36
            s << sort_header_tag('updated_on', :default_order => 'desc')
37
        
37

  
38 38
            s << "</tr></thead><tbody>"
39
        
39

  
40 40
            original_project = @project
41
        
41

  
42 42
            projects.each do |project|
43 43
              s << render_project_in_table_with_filtering(project, cycle('odd', 'even'), 0, tokens)
44 44
            end
45
        
45

  
46 46
            s << "</table>"
47 47
          else
48 48
            s << "\n"
......
52 52
          s
53 53
        end
54 54

  
55
        def render_project_in_table_with_filtering(project, oddeven, level, tokens)          
55
        def render_project_in_table_with_filtering(project, oddeven, level, tokens)
56 56
          # set the project environment to please macros.
57 57
          @project = project
58 58

  
......
72 72
          s << "<td class='tags' align=top>" << project.tag_counts.collect{ |t| render_project_tag_link(t) }.join(', ') << "</td>"
73 73

  
74 74
          s << "<td class='managers' align=top>"
75
           
75

  
76 76
          u = project.users_by_role
77 77
          if u
78 78
            u.keys.each do |r|
......
91 91
          end
92 92

  
93 93
          s << "</td>"
94
          
94

  
95 95
          s << "<td class='created_on' align=top>" << format_date(project.created_on) << "</td>"
96 96
          s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>"
97 97

  
......
105 105

  
106 106
          s
107 107
        end
108
        
109
        
110
        
108

  
109

  
110

  
111 111
        # Renders a tree of projects as a nested set of unordered lists
112 112
        # The given collection may be a subset of the whole project tree
113 113
        # (eg. some intermediate nodes are private and can not be seen)
......
116 116
          if projects.any?
117 117
            tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields)
118 118
            debugger
119
            
119

  
120 120

  
121 121
            ancestors = []
122 122
            original_project = @project
......
128 128
              else
129 129
                ancestors.pop
130 130
                s << "</li>"
131
                while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) 
131
                while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
132 132
                  ancestors.pop
133 133
                  s << "</ul></li>"
134 134
                end
135 135
              end
136 136
              classes = (ancestors.empty? ? 'root' : 'child')
137 137
              s << "<li class='#{classes}'><div class='#{classes}'>" +
138
                link_to( highlight_tokens(project.name, tokens), 
138
                link_to( highlight_tokens(project.name, tokens),
139 139
                  {:controller => 'projects', :action => 'show', :id => project},
140 140
                  :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}"
141 141
                )
......
146 146
           #    value = value_model.present? ? value_model.value : nil
147 147
           #    s << "<li><b>#{field.name.humanize}:</b> #{highlight_tokens(value, tokens)}</li>" if value.present?
148 148
           #  end
149
              
149

  
150 150
              s << "</ul>"
151 151
              s << "<div class='clear'></div>"
152 152
              unless project.description.blank?
......
163 163
          end
164 164
          s.join "\n"
165 165
        end
166
        
166

  
167 167
        # Renders a tree of projects where the current user belongs
168 168
        # as a nested set of unordered lists
169 169
        # The given collection may be a subset of the whole project tree
......
193 193
          s
194 194

  
195 195
        end
196
        
197
        
198
        
196

  
197

  
198

  
199 199

  
200 200
        def render_my_project_in_hierarchy_with_tags(project)
201 201

  
......
215 215
            else
216 216
              s << " <span class='private'>" << l(:field_is_private) << "</span>"
217 217
            end
218
           
218

  
219 219
            tc = project.tag_counts
220 220
            if tc.empty?
221 221
              s << " <span class='no-tags'>" << l(:field_no_tags) << "</span>"
......
242 242

  
243 243
        end
244 244

  
245
        
246
        
245

  
246

  
247 247
        private
248
        
248

  
249 249
        # copied from search_helper. This one doesn't escape html or limit the text length
250 250
        def highlight_tokens(text, tokens)
251 251
          return text unless text && tokens && !tokens.empty?
252 252
          re_tokens = tokens.collect {|t| Regexp.escape(t)}
253
          regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE    
253
          regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE
254 254
          result = ''
255 255
          text.split(regexp).each_with_index do |words, i|
256 256
            words = words.mb_chars
......
263 263
          end
264 264
          result
265 265
        end
266
      
266

  
267 267
      end
268 268
    end
269 269
  end

Also available in: Unified diff