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 @ 1259:94a6e3687c45

History | View | Annotate | Download (4.08 KB)

1 996:c43450d54787 chris
# -*- coding: utf-8 -*-
2 730:4a9bb3b8d5cd luis
require_dependency 'projects_controller'
3
4
module RedmineTags
5
  module Patches
6 1067:2ad2f9ab46a6 luis
    module ProjectsControllerPatch
7 730:4a9bb3b8d5cd luis
      def self.included(base)
8
        base.send(:include, InstanceMethods)
9 1067:2ad2f9ab46a6 luis
        base.class_eval do
10
          unloadable
11 1254:a54ce736229d luis
          # skip_before_filter :authorize, :only => [:set_fieldset_status]
12
          # skip_before_filter :find_project, :only => [:set_fieldset_status]
13 767:dd33798e514d luis
14
          alias :index filtered_index
15 730:4a9bb3b8d5cd luis
        end
16
      end
17
18
      module InstanceMethods
19 767:dd33798e514d luis
        def paginate_projects
20
          sort_init 'name'
21
          sort_update %w(name lft created_on updated_on)
22
          @limit = per_page_option
23 1146:fa73588e9105 luis
24
          # Only top-level visible projects are counted --lf.10Jan2013
25 1254:a54ce736229d luis
          top_level_visible_projects = @projects.visible_roots
26 1146:fa73588e9105 luis
          @project_count = top_level_visible_projects.count
27
28
          # Project.visible_roots.find(@projects).count
29 899:5d5943de529f luis
30 767:dd33798e514d luis
          @project_pages = ActionController::Pagination::Paginator.new self, @project_count, @limit, params['page']
31 769:9af86029dc90 luis
          @offset ||= @project_pages.current.offset
32 767:dd33798e514d luis
        end
33
34 1254:a54ce736229d luis
        # 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 773:c761e467a390 luis
44
        # gets the status of the collabsible fieldsets
45 1254:a54ce736229d luis
        # 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 767:dd33798e514d luis
64
        # Lists visible projects. Paginator is for top-level projects only
65
        # (subprojects belong to them)
66
        def filtered_index
67 752:ded6cd947ade luis
          @project = Project.new
68 767:dd33798e514d luis
          filter_projects
69 1254:a54ce736229d luis
          # get_fieldset_statuses
70 769:9af86029dc90 luis
71 1146:fa73588e9105 luis
          sort_clause = "name"
72
73 752:ded6cd947ade luis
          respond_to do |format|
74 1067:2ad2f9ab46a6 luis
            format.html {
75 767:dd33798e514d luis
              paginate_projects
76 1067:2ad2f9ab46a6 luis
77 1146:fa73588e9105 luis
              # todo: check ordering ~luisf.14/Jan/2013
78
              @projects = @projects[@offset, @limit]
79 767:dd33798e514d luis
80 919:b03f28dd9026 Chris
              render :template => 'projects/index.html.erb', :layout => !request.xhr?
81 767:dd33798e514d luis
            }
82 779:06a9d1cf5e15 luis
            format.api {
83 767:dd33798e514d luis
              @offset, @limit = api_offset_and_limit
84
              @project_count = Project.visible.count
85 769:9af86029dc90 luis
              @projects = Project.visible.find(@projects, :offset => @offset, :limit => @limit, :order => 'lft')
86 767:dd33798e514d luis
            }
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 752:ded6cd947ade luis
            }
91
            format.js {
92 779:06a9d1cf5e15 luis
              paginate_projects
93
              @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
94 752:ded6cd947ade luis
              render :update do |page|
95
                page.replace_html 'projects', :partial => 'filtered_projects'
96
              end
97
            }
98
          end
99
        end
100
101
        private
102
103 1067:2ad2f9ab46a6 luis
        def filter_projects
104 1254:a54ce736229d luis
          # find projects like question
105
          @question = (params[:search] || "").strip
106 752:ded6cd947ade luis
107 1258:f8c5708a6fd6 luis
          if @question.empty?
108
            projects = Project.visible
109
          else
110
            projects = Project.visible.like(@question)
111
          end
112
113
          # search for tags
114 1259:94a6e3687c45 luis
          if params.has_key?(:tag_search)
115
             tag_list = (params[:tag_search] || "").strip.split(",")
116 1258:f8c5708a6fd6 luis
          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 739:b7ac21913927 luis
127 752:ded6cd947ade luis
        end
128 730:4a9bb3b8d5cd luis
      end
129
    end
130
  end
131
end