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 / plugins / redmine_tags / lib / redmine_tags / patches / projects_controller_patch.rb @ 1431:303b9be118d4

History | View | Annotate | Download (4.08 KB)

1
# -*- coding: utf-8 -*-
2
require_dependency 'projects_controller'
3

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

    
14
          alias :index filtered_index
15
        end
16
      end
17

    
18
      module InstanceMethods
19
        def paginate_projects
20
          sort_init 'name'
21
          sort_update %w(name lft created_on updated_on)
22
          @limit = per_page_option
23

    
24
          # Only top-level visible projects are counted --lf.10Jan2013
25
          top_level_visible_projects = @projects.visible_roots
26
          @project_count = top_level_visible_projects.count
27

    
28
          # Project.visible_roots.find(@projects).count
29

    
30
          @project_pages = ActionController::Pagination::Paginator.new self, @project_count, @limit, params['page']
31
          @offset ||= @project_pages.current.offset
32
        end
33

    
34
        # def set_fieldset_status
35
#
36
        #   # luisf. test for missing parameters………
37
        #   field = params[:field_id]
38
        #   status = params[:status]
39
#
40
        #   session[(field + "_status").to_sym] = status
41
        #   render :nothing => true
42
        # end
43

    
44
        # gets the status of the collabsible fieldsets
45
        # def get_fieldset_statuses
46
        #   if session[:my_projects_fieldset_status].nil?
47
        #     @myproj_status = "true"
48
        #   else
49
        #     @myproj_status = session[:my_projects_fieldset_status]
50
        #   end
51
#
52
        #   if session[:filters_fieldset_status].nil?
53
        #     @filter_status = "false"
54
        #   else
55
        #     @filter_status = session[:filters_fieldset_status]
56
        #   end
57
#
58
        #   if params && params[:project] && !params[:project][:tag_list].# nil?
59
        #     @filter_status = "true"
60
        #   end
61
#
62
        # end
63

    
64
        # Lists visible projects. Paginator is for top-level projects only
65
        # (subprojects belong to them)
66
        def filtered_index
67
          @project = Project.new
68
          filter_projects
69
          # get_fieldset_statuses
70

    
71
          sort_clause = "name"
72

    
73
          respond_to do |format|
74
            format.html {
75
              paginate_projects
76

    
77
              # todo: check ordering ~luisf.14/Jan/2013
78
              @projects = @projects[@offset, @limit]
79

    
80
              render :template => 'projects/index.html.erb', :layout => !request.xhr?
81
            }
82
            format.api {
83
              @offset, @limit = api_offset_and_limit
84
              @project_count = Project.visible.count
85
              @projects = Project.visible.find(@projects, :offset => @offset, :limit => @limit, :order => 'lft')
86
            }
87
            format.atom {
88
              projects = Project.visible.find(:all, :order => 'created_on DESC', :limit => Setting.feeds_limit.to_i)
89
              render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
90
            }
91
            format.js {
92
              paginate_projects
93
              @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
94
              render :update do |page|
95
                page.replace_html 'projects', :partial => 'filtered_projects'
96
              end
97
            }
98
          end
99
        end
100

    
101
        private
102

    
103
        def filter_projects
104
          # find projects like question
105
          @question = (params[:search] || "").strip
106

    
107
          if @question.empty?
108
            projects = Project.visible
109
          else
110
            projects = Project.visible.like(@question)
111
          end
112

    
113
          # search for tags
114
          if params.has_key?(:tag_search)
115
             tag_list = (params[:tag_search] || "").strip.split(",")
116
          else
117
             tag_list = ""
118
          end
119

    
120
          unless tag_list.empty?
121
            projects = projects.tagged_with(tag_list)
122
          end
123

    
124
          ## TODO: luisf-10Apr2013 should I only return the visible_roots?
125
          @projects = projects
126

    
127
        end
128
      end
129
    end
130
  end
131
end