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 @ 767:dd33798e514d

History | View | Annotate | Download (3.81 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
          before_filter :add_tags_to_project, :only => [:save, :update]
11 767:dd33798e514d luis
#          before_filter :filter_projects, :only => :index
12
13
          alias :index filtered_index
14 730:4a9bb3b8d5cd luis
        end
15
      end
16
17
      module InstanceMethods
18 767:dd33798e514d luis
19
20
21 752:ded6cd947ade luis
        def add_tags_to_project
22
23 731:3f87a3b61d9c luis
          if params && params[:project] && !params[:project][:tag_list].nil?
24
            old_tags = @project.tag_list.to_s
25
            new_tags = params[:project][:tag_list].to_s
26 752:ded6cd947ade luis
27 731:3f87a3b61d9c luis
            unless (old_tags == new_tags)
28
              @project.tag_list = new_tags
29
            end
30 739:b7ac21913927 luis
          end
31 730:4a9bb3b8d5cd luis
        end
32 752:ded6cd947ade luis
33
34 767:dd33798e514d luis
        def paginate_projects
35
          sort_init 'name'
36
          sort_update %w(name lft created_on updated_on)
37
          @limit = per_page_option
38
          @project_count = Project.visible_roots.count
39
          @project_pages = ActionController::Pagination::Paginator.new self, @project_count, @limit, params['page']
40
          @offset ||= @project_pages.current.offset
41
        end
42
43
44
        # Lists visible projects. Paginator is for top-level projects only
45
        # (subprojects belong to them)
46
        def filtered_index
47 752:ded6cd947ade luis
          @project = Project.new
48 767:dd33798e514d luis
          filter_projects
49 752:ded6cd947ade luis
50
          respond_to do |format|
51 767:dd33798e514d luis
            format.html {
52
              paginate_projects
53
              @projects = Project.visible_roots.find(@filtered_projects, :offset => @offset, :limit => @limit, :order => sort_clause)
54
55
              if User.current.logged?
56
                # seems sort_by gives us case-sensitive ordering, which we don't want
57
                #          @user_projects = User.current.projects.sort_by(&:name)
58
                @user_projects = User.current.projects.all(:order => :name)
59
              end
60
61
              render :template => 'projects/index.rhtml', :layout => !request.xhr?
62
            }
63
            format.api  {
64
              @offset, @limit = api_offset_and_limit
65
              @project_count = Project.visible.count
66
              @projects = Project.visible.find(@filtered_projects, :offset => @offset, :limit => @limit, :order => 'lft')
67
            }
68
            format.atom {
69
              projects = Project.visible.find(:all, :order => 'created_on DESC', :limit => Setting.feeds_limit.to_i)
70
              render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
71 752:ded6cd947ade luis
            }
72
            format.js {
73
              render :update do |page|
74 767:dd33798e514d luis
                paginate_projects
75
                @projects = Project.visible_roots.find(@filtered_projects, :offset => @offset, :limit => @limit, :order => sort_clause)
76 752:ded6cd947ade luis
                page.replace_html 'projects', :partial => 'filtered_projects'
77
              end
78
            }
79
          end
80
        end
81
82
        private
83
84 767:dd33798e514d luis
        def filter_projects
85 752:ded6cd947ade luis
          @question = (params[:q] || "").strip
86
87
          if params.has_key?(:project)
88
            @tag_list = (params[:project][:tag_list] || "").strip.split(",")
89
          else
90
            @tag_list = []
91 739:b7ac21913927 luis
          end
92
93 752:ded6cd947ade luis
          @projects = Project.visible
94 749:3f28aebc5fc1 luis
95 752:ded6cd947ade luis
          @featured_projects = @projects.featured if Project.respond_to? :featured
96 739:b7ac21913927 luis
97 752:ded6cd947ade luis
          # luisf
98
          @projects = @projects.search_by_question(@question) unless @question == ""
99
          @tagged_projects_ids = Project.tagged_with(@tag_list).collect{ |project| Project.find(project.id) } unless @tag_list.empty?
100 739:b7ac21913927 luis
101 755:bde9c5bfb559 luis
          debugger
102
103 752:ded6cd947ade luis
          # intersection of both prject groups
104
          @projects = @projects && @tagged_projects_ids unless @tag_list.empty?
105 755:bde9c5bfb559 luis
106 760:b2a9e64b8283 luis
          debugger
107 755:bde9c5bfb559 luis
          @filtered_projects = @projects
108 752:ded6cd947ade luis
        end
109 730:4a9bb3b8d5cd luis
      end
110
    end
111
  end
112
end