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 @ 785:32d853e2e7ed

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