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 @ 919:b03f28dd9026

History | View | Annotate | Download (4.85 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 899:5d5943de529f luis
38 767:dd33798e514d luis
          @project_pages = ActionController::Pagination::Paginator.new self, @project_count, @limit, params['page']
39 769:9af86029dc90 luis
          @offset ||= @project_pages.current.offset
40 767:dd33798e514d luis
        end
41
42 776:af852d82b00b luis
        def set_fieldset_status
43
44
          # luisf. test for missing parameters………
45
          field = params[:field_id]
46
          status = params[:status]
47
48 773:c761e467a390 luis
          session[(field + "_status").to_sym] = status
49 776:af852d82b00b luis
          render :nothing => true
50 773:c761e467a390 luis
        end
51
52
        # gets the status of the collabsible fieldsets
53 776:af852d82b00b luis
        def get_fieldset_statuses
54
          if session[:my_projects_fieldset_status].nil?
55 783:b153713dc4fd luis
            @myproj_status = "true"
56 773:c761e467a390 luis
          else
57 776:af852d82b00b luis
            @myproj_status = session[:my_projects_fieldset_status]
58
          end
59
60
          if session[:filters_fieldset_status].nil?
61 783:b153713dc4fd luis
            @filter_status = "false"
62 773:c761e467a390 luis
          else
63 776:af852d82b00b luis
            @filter_status = session[:filters_fieldset_status]
64 798:829052890acb luis
          end
65
66
          if params && params[:project] && !params[:project][:tag_list].nil?
67
            @filter_status = "true"
68
          end
69
70 773:c761e467a390 luis
        end
71 767:dd33798e514d luis
72
        # Lists visible projects. Paginator is for top-level projects only
73
        # (subprojects belong to them)
74
        def filtered_index
75 752:ded6cd947ade luis
          @project = Project.new
76 767:dd33798e514d luis
          filter_projects
77 773:c761e467a390 luis
          get_fieldset_statuses
78 769:9af86029dc90 luis
79 752:ded6cd947ade luis
          respond_to do |format|
80 767:dd33798e514d luis
            format.html {
81
              paginate_projects
82 786:ae82810661da luis
83 769:9af86029dc90 luis
              @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
84 767:dd33798e514d luis
85
              if User.current.logged?
86
                # seems sort_by gives us case-sensitive ordering, which we don't want
87
                #          @user_projects = User.current.projects.sort_by(&:name)
88
                @user_projects = User.current.projects.all(:order => :name)
89
              end
90
91 919:b03f28dd9026 Chris
              render :template => 'projects/index.html.erb', :layout => !request.xhr?
92 767:dd33798e514d luis
            }
93 779:06a9d1cf5e15 luis
            format.api {
94 767:dd33798e514d luis
              @offset, @limit = api_offset_and_limit
95
              @project_count = Project.visible.count
96 769:9af86029dc90 luis
              @projects = Project.visible.find(@projects, :offset => @offset, :limit => @limit, :order => 'lft')
97 767:dd33798e514d luis
            }
98
            format.atom {
99
              projects = Project.visible.find(:all, :order => 'created_on DESC', :limit => Setting.feeds_limit.to_i)
100
              render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
101 752:ded6cd947ade luis
            }
102
            format.js {
103 779:06a9d1cf5e15 luis
              paginate_projects
104
              @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
105 752:ded6cd947ade luis
              render :update do |page|
106
                page.replace_html 'projects', :partial => 'filtered_projects'
107
              end
108
            }
109
          end
110
        end
111
112
        private
113
114 767:dd33798e514d luis
        def filter_projects
115 752:ded6cd947ade luis
          @question = (params[:q] || "").strip
116
117
          if params.has_key?(:project)
118
            @tag_list = (params[:project][:tag_list] || "").strip.split(",")
119
          else
120
            @tag_list = []
121 739:b7ac21913927 luis
          end
122
123 786:ae82810661da luis
          if  @question == ""
124 899:5d5943de529f luis
            @projects = Project.visible_roots
125 786:ae82810661da luis
          else
126 899:5d5943de529f luis
            @projects = Project.visible_roots.find(Project.visible.search_by_question(@question))
127 786:ae82810661da luis
          end
128
129
          unless @tag_list.empty?
130
            @tagged_projects_ids = Project.visible.tagged_with(@tag_list).collect{ |project| Project.find(project.id) }
131
            @projects = @projects & @tagged_projects_ids
132
          end
133
134
          @projects = @projects.collect{ |project| project.root }
135
          @projects = @projects.uniq
136 899:5d5943de529f luis
137 752:ded6cd947ade luis
        end
138 730:4a9bb3b8d5cd luis
      end
139
    end
140
  end
141
end