To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / vendor / plugins / redmine_tags / lib / redmine_tags / patches / projects_controller_patch.rb @ 778:c118d3389088

History | View | Annotate | Download (4.61 KB)

1
require_dependency 'projects_controller'
2

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

    
15
          alias :index filtered_index
16
        end
17
      end
18

    
19
      module InstanceMethods
20
        
21
        
22
        
23
        def add_tags_to_project
24

    
25
          if params && params[:project] && !params[:project][:tag_list].nil?
26
            old_tags = @project.tag_list.to_s
27
            new_tags = params[:project][:tag_list].to_s
28

    
29
            unless (old_tags == new_tags)
30
              @project.tag_list = new_tags
31
            end
32
          end
33
        end
34

    
35
        def paginate_projects
36
          sort_init 'name'
37
          sort_update %w(name lft created_on updated_on)
38
          @limit = per_page_option
39
          @project_count = Project.visible_roots.find(@projects).count
40
          @project_pages = ActionController::Pagination::Paginator.new self, @project_count, @limit, params['page']
41
          @offset ||= @project_pages.current.offset
42
        end
43

    
44
        def set_fieldset_status
45

    
46
          # luisf. test for missing parameters………
47
          field = params[:field_id]
48
          status = params[:status]
49

    
50
          session[(field + "_status").to_sym] = status
51
          logger.error { "SET - DEBUG-ME #{session.inspect}" }
52

    
53
          render :nothing => true
54
        end
55

    
56
        # gets the status of the collabsible fieldsets
57
        def get_fieldset_statuses
58
          if session[:my_projects_fieldset_status].nil?
59
            @myproj_status = true
60
          else
61
            @myproj_status = session[:my_projects_fieldset_status]
62
          end
63
                    
64
          if session[:filters_fieldset_status].nil?
65
            @filter_status = false
66
          else
67
            @filter_status = session[:filters_fieldset_status]
68
          end                            
69
        end
70

    
71
        # Lists visible projects. Paginator is for top-level projects only
72
        # (subprojects belong to them)
73
        def filtered_index
74
          @project = Project.new
75
          filter_projects
76
          get_fieldset_statuses
77

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

    
83
              if User.current.logged?
84
                # seems sort_by gives us case-sensitive ordering, which we don't want
85
                #          @user_projects = User.current.projects.sort_by(&:name)
86
                @user_projects = User.current.projects.all(:order => :name)
87
              end
88
              
89
              render :template => 'projects/index.rhtml', :layout => !request.xhr?
90
            }
91
            format.api  {
92
              @offset, @limit = api_offset_and_limit
93
              @project_count = Project.visible.count
94
              @projects = Project.visible.find(@projects, :offset => @offset, :limit => @limit, :order => 'lft')
95
            }
96
            format.atom {
97
              projects = Project.visible.find(:all, :order => 'created_on DESC', :limit => Setting.feeds_limit.to_i)
98
              render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
99
            }
100
            format.js {
101
              render :update do |page|
102
                paginate_projects
103
                @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
104
                page.replace_html 'projects', :partial => 'filtered_projects'
105
              end
106
            }
107
          end
108
        end
109

    
110
        private
111

    
112
        def filter_projects                  
113
          @question = (params[:q] || "").strip     
114

    
115
          if params.has_key?(:project)
116
            @tag_list = (params[:project][:tag_list] || "").strip.split(",")
117
          else
118
            @tag_list = []
119
          end
120

    
121
          @projects = Project.visible
122

    
123
          # luisf 
124
          @projects = @projects.search_by_question(@question) unless @question == ""
125
          @tagged_projects_ids = Project.tagged_with(@tag_list).collect{ |project| Project.find(project.id) } unless @tag_list.empty?
126

    
127
          # intersection of both prject groups            
128
          @projects = @projects & @tagged_projects_ids unless @tag_list.empty?
129
        end
130
      end
131
    end
132
  end
133
end