Revision 1077:9b5b4e7970cd vendor/plugins/redmine_tags

View differences:

vendor/plugins/redmine_tags/app/views/projects/_filter_search_tags.html.erb
6 6
      </p>
7 7
      <div id="project_tag_candidates" class="autocomplete"></div>
8 8
      <%= javascript_include_tag 'tags_input', :plugin => 'redmine_tags' -%>
9
      <%= javascript_tag "observeProjectTagsField('#{url_for(:controller => 'auto_completes', :action => 'project_search_tags', :project_id => Project.first.id)}', true)" -%>
9
      <%= javascript_tag "observeProjectTagsField('#{url_for(:controller => 'auto_completes', :action => 'project_search_tags')}', true)" -%>
10 10
    </div>
11 11
  <%- end -%>
12 12
</p>
vendor/plugins/redmine_tags/app/views/projects/_filter_tags.html.erb
7 7
      <div id="project_tag_candidates" class="autocomplete"></div>
8 8
      <%= javascript_include_tag 'tags_input', :plugin => 'redmine_tags' %>
9 9

  
10
      <%= javascript_tag "observeProjectTagsField('#{url_for(:controller => 'auto_completes', :action => 'project_tags', :project_id => Project.first.id)}')" %>
10
      <%= javascript_tag "observeProjectTagsField('#{url_for(:controller => 'auto_completes', :action => 'project_tags')}')" %>
11 11
    </div>
12 12
  <% end -%>
13 13
</p>
vendor/plugins/redmine_tags/app/views/projects/_tags_form.html.erb
6 6
  </p>
7 7
  <div id="project_tag_candidates" class="autocomplete"></div>
8 8
  <%= javascript_include_tag 'tags_input', :plugin => 'redmine_tags' %>
9
  <%= javascript_tag "observeProjectTagsField('#{url_for(:controller => 'auto_completes', :action => 'project_tags', :project_id => Project.first.id)}', false)" %>  
9
  <%= javascript_tag "observeProjectTagsField('#{url_for(:controller => 'auto_completes', :action => 'project_tags')}', false)" %>
10 10
</div>
11 11
<% end -%>
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
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]
......
17 17
      end
18 18

  
19 19
      module InstanceMethods
20
                
20

  
21 21
        def add_tags_to_project
22 22

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

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

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

  
71 71
        end
72 72

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

  
80 80
          respond_to do |format|
81
            format.html { 
81
            format.html {
82 82
              paginate_projects
83
              
84
              @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)
85 85

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

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

  
113 113
        private
114 114

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

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

  
130 130
          unless @tag_list.empty?
131 131
            @tagged_projects_ids = Project.visible.tagged_with(@tag_list).collect{ |project| Project.find(project.id).root }
132 132
            @projects = @projects & @tagged_projects_ids
vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_helper_patch.rb
5 5
      def self.included(base) # :nodoc:
6 6
        base.send(:include, InstanceMethods)
7 7
        base.send(:include, TagsHelper)
8

  
8 9
        base.class_eval do
9 10
          unloadable
10 11
        end
11 12
      end
12 13

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

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

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

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

  
40 41
            original_project = @project
41
        
42

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

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

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

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

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

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

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

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

  
......
105 106

  
106 107
          s
107 108
        end
108
        
109
        
110
        
109

  
110

  
111

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

  
120 121

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

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

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

  
195 196
        end
196
        
197
        
198
        
197

  
198

  
199

  
199 200

  
200 201
        def render_my_project_in_hierarchy_with_tags(project)
201 202

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

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

  
243 244
        end
244 245

  
245
        
246
        
246

  
247

  
247 248
        private
248
        
249

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

  
267 268
      end
268 269
    end
269 270
  end

Also available in: Unified diff