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 @ 826:cb27dd527bd3

History | View | Annotate | Download (4.79 KB)

1 730:4a9bb3b8d5cd luis
require_dependency 'projects_controller'
2
3
module RedmineTags
4
  module Patches
5 767:dd33798e514d luis
    module ProjectsControllerPatch
6 730:4a9bb3b8d5cd luis
      def self.included(base)
7
        base.send(:include, InstanceMethods)
8
        base.class_eval do
9
          unloadable
10 776:af852d82b00b luis
          skip_before_filter :authorize, :only => [:set_fieldset_status]
11
          skip_before_filter :find_project, :only => [:set_fieldset_status]
12 730:4a9bb3b8d5cd luis
          before_filter :add_tags_to_project, :only => [:save, :update]
13 767:dd33798e514d luis
14
          alias :index filtered_index
15 730:4a9bb3b8d5cd luis
        end
16
      end
17
18
      module InstanceMethods
19 815:4d3ac2b4156c luis
20 752:ded6cd947ade luis
        def add_tags_to_project
21
22 731:3f87a3b61d9c luis
          if params && params[:project] && !params[:project][:tag_list].nil?
23 813:0987c3565751 luis
            old_tags = @project.tag_list.to_s.downcase
24
            new_tags = params[:project][:tag_list].to_s.downcase
25 752:ded6cd947ade luis
26 731:3f87a3b61d9c luis
            unless (old_tags == new_tags)
27 815:4d3ac2b4156c luis
              @project.tag_list = ActionController::Base.helpers.strip_tags(new_tags)
28 731:3f87a3b61d9c luis
            end
29 739:b7ac21913927 luis
          end
30 730:4a9bb3b8d5cd luis
        end
31 752:ded6cd947ade luis
32 767:dd33798e514d luis
        def paginate_projects
33
          sort_init 'name'
34
          sort_update %w(name lft created_on updated_on)
35
          @limit = per_page_option
36 769:9af86029dc90 luis
          @project_count = Project.visible_roots.find(@projects).count
37 767:dd33798e514d luis
          @project_pages = ActionController::Pagination::Paginator.new self, @project_count, @limit, params['page']
38 769:9af86029dc90 luis
          @offset ||= @project_pages.current.offset
39 767:dd33798e514d luis
        end
40
41 776:af852d82b00b luis
        def set_fieldset_status
42
43
          # luisf. test for missing parameters………
44
          field = params[:field_id]
45
          status = params[:status]
46
47 773:c761e467a390 luis
          session[(field + "_status").to_sym] = status
48 776:af852d82b00b luis
          render :nothing => true
49 773:c761e467a390 luis
        end
50
51
        # gets the status of the collabsible fieldsets
52 776:af852d82b00b luis
        def get_fieldset_statuses
53
          if session[:my_projects_fieldset_status].nil?
54 783:b153713dc4fd luis
            @myproj_status = "true"
55 773:c761e467a390 luis
          else
56 776:af852d82b00b luis
            @myproj_status = session[:my_projects_fieldset_status]
57
          end
58
59
          if session[:filters_fieldset_status].nil?
60 783:b153713dc4fd luis
            @filter_status = "false"
61 773:c761e467a390 luis
          else
62 776:af852d82b00b luis
            @filter_status = session[:filters_fieldset_status]
63 798:829052890acb luis
          end
64
65
          if params && params[:project] && !params[:project][:tag_list].nil?
66
            @filter_status = "true"
67
          end
68
69 773:c761e467a390 luis
        end
70 767:dd33798e514d luis
71
        # Lists visible projects. Paginator is for top-level projects only
72
        # (subprojects belong to them)
73
        def filtered_index
74 752:ded6cd947ade luis
          @project = Project.new
75 767:dd33798e514d luis
          filter_projects
76 773:c761e467a390 luis
          get_fieldset_statuses
77 769:9af86029dc90 luis
78 752:ded6cd947ade luis
          respond_to do |format|
79 767:dd33798e514d luis
            format.html {
80
              paginate_projects
81 786:ae82810661da luis
82 769:9af86029dc90 luis
              @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
83 767:dd33798e514d luis
84
              if User.current.logged?
85
                # seems sort_by gives us case-sensitive ordering, which we don't want
86
                #          @user_projects = User.current.projects.sort_by(&:name)
87
                @user_projects = User.current.projects.all(:order => :name)
88
              end
89
90
              render :template => 'projects/index.rhtml', :layout => !request.xhr?
91
            }
92 779:06a9d1cf5e15 luis
            format.api {
93 767:dd33798e514d luis
              @offset, @limit = api_offset_and_limit
94
              @project_count = Project.visible.count
95 769:9af86029dc90 luis
              @projects = Project.visible.find(@projects, :offset => @offset, :limit => @limit, :order => 'lft')
96 767:dd33798e514d luis
            }
97
            format.atom {
98
              projects = Project.visible.find(:all, :order => 'created_on DESC', :limit => Setting.feeds_limit.to_i)
99
              render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
100 752:ded6cd947ade luis
            }
101
            format.js {
102 779:06a9d1cf5e15 luis
              paginate_projects
103
              @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
104 752:ded6cd947ade luis
              render :update do |page|
105
                page.replace_html 'projects', :partial => 'filtered_projects'
106
              end
107
            }
108
          end
109
        end
110
111
        private
112
113 767:dd33798e514d luis
        def filter_projects
114 752:ded6cd947ade luis
          @question = (params[:q] || "").strip
115
116
          if params.has_key?(:project)
117
            @tag_list = (params[:project][:tag_list] || "").strip.split(",")
118
          else
119
            @tag_list = []
120 739:b7ac21913927 luis
          end
121
122 786:ae82810661da luis
          if  @question == ""
123
            @projects = Project.visible
124
          else
125
            @projects = Project.visible.search_by_question(@question)
126
          end
127
128
          unless @tag_list.empty?
129
            @tagged_projects_ids = Project.visible.tagged_with(@tag_list).collect{ |project| Project.find(project.id) }
130
            @projects = @projects & @tagged_projects_ids
131
          end
132
133
          @projects = @projects.collect{ |project| project.root }
134
          @projects = @projects.uniq
135 749:3f28aebc5fc1 luis
136 752:ded6cd947ade luis
        end
137 730:4a9bb3b8d5cd luis
      end
138
    end
139
  end
140
end