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 @ 1248:1b44eeb49c5a

History | View | Annotate | Download (4.1 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 776:af852d82b00b 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
          top_level_visible_projects = @projects.select{ |p| p.parent_id.nil? and p.visible? }
26
          @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 776:af852d82b00b luis
        def set_fieldset_status
35
36
          # luisf. test for missing parameters………
37
          field = params[:field_id]
38
          status = params[:status]
39
40 773:c761e467a390 luis
          session[(field + "_status").to_sym] = status
41 776:af852d82b00b luis
          render :nothing => true
42 773:c761e467a390 luis
        end
43
44
        # gets the status of the collabsible fieldsets
45 776:af852d82b00b luis
        def get_fieldset_statuses
46
          if session[:my_projects_fieldset_status].nil?
47 783:b153713dc4fd luis
            @myproj_status = "true"
48 773:c761e467a390 luis
          else
49 776:af852d82b00b luis
            @myproj_status = session[:my_projects_fieldset_status]
50
          end
51 1067:2ad2f9ab46a6 luis
52 776:af852d82b00b luis
          if session[:filters_fieldset_status].nil?
53 783:b153713dc4fd luis
            @filter_status = "false"
54 773:c761e467a390 luis
          else
55 776:af852d82b00b luis
            @filter_status = session[:filters_fieldset_status]
56 798:829052890acb luis
          end
57 1067:2ad2f9ab46a6 luis
58 798:829052890acb luis
          if params && params[:project] && !params[:project][:tag_list].nil?
59
            @filter_status = "true"
60
          end
61 1067:2ad2f9ab46a6 luis
62 773:c761e467a390 luis
        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 773:c761e467a390 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
          @question = (params[:q] || "").strip
105 752:ded6cd947ade luis
106
          if params.has_key?(:project)
107
            @tag_list = (params[:project][:tag_list] || "").strip.split(",")
108
          else
109
            @tag_list = []
110 739:b7ac21913927 luis
          end
111
112 786:ae82810661da luis
          if  @question == ""
113 899:5d5943de529f luis
            @projects = Project.visible_roots
114 786:ae82810661da luis
          else
115 899:5d5943de529f luis
            @projects = Project.visible_roots.find(Project.visible.search_by_question(@question))
116 786:ae82810661da luis
          end
117 1067:2ad2f9ab46a6 luis
118 786:ae82810661da luis
          unless @tag_list.empty?
119 996:c43450d54787 chris
            @tagged_projects_ids = Project.visible.tagged_with(@tag_list).collect{ |project| Project.find(project.id).root }
120 1146:fa73588e9105 luis
121 786:ae82810661da luis
            @projects = @projects & @tagged_projects_ids
122 996:c43450d54787 chris
            @projects = @projects.uniq
123 786:ae82810661da luis
          end
124 752:ded6cd947ade luis
        end
125 730:4a9bb3b8d5cd luis
      end
126
    end
127
  end
128
end