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 @ 814:03d855015db8

History | View | Annotate | Download (4.8 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
          render :nothing => true
52
        end
53

    
54
        # gets the status of the collabsible fieldsets
55
        def get_fieldset_statuses
56
          if session[:my_projects_fieldset_status].nil?
57
            @myproj_status = "true"
58
          else
59
            @myproj_status = session[:my_projects_fieldset_status]
60
          end
61
                    
62
          if session[:filters_fieldset_status].nil?
63
            @filter_status = "false"
64
          else
65
            @filter_status = session[:filters_fieldset_status]
66
          end
67
          
68
          if params && params[:project] && !params[:project][:tag_list].nil?
69
            @filter_status = "true"
70
          end
71
                                      
72
        end
73

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

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

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

    
114
        private
115

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

    
119
          if params.has_key?(:project)
120
            @tag_list = (params[:project][:tag_list] || "").strip.split(",")
121
          else
122
            @tag_list = []
123
          end
124

    
125
          if  @question == ""
126
            @projects = Project.visible
127
          else
128
            @projects = Project.visible.search_by_question(@question)
129
          end
130
  
131
          unless @tag_list.empty?
132
            @tagged_projects_ids = Project.visible.tagged_with(@tag_list).collect{ |project| Project.find(project.id) }
133
            @projects = @projects & @tagged_projects_ids
134
          end
135
          
136
          @projects = @projects.collect{ |project| project.root }
137
          @projects = @projects.uniq
138

    
139
        end
140
      end
141
    end
142
  end
143
end