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 @ 769:9af86029dc90

History | View | Annotate | Download (3.73 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 769:9af86029dc90 luis
          @project_count = Project.visible_roots.find(@projects).count
39 767:dd33798e514d luis
          @project_pages = ActionController::Pagination::Paginator.new self, @project_count, @limit, params['page']
40 769:9af86029dc90 luis
          @offset ||= @project_pages.current.offset
41 767:dd33798e514d luis
        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 769:9af86029dc90 luis
          debugger
51
52 752:ded6cd947ade luis
          respond_to do |format|
53 767:dd33798e514d luis
            format.html {
54
              paginate_projects
55 769:9af86029dc90 luis
              @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
56 767:dd33798e514d luis
57
              if User.current.logged?
58
                # seems sort_by gives us case-sensitive ordering, which we don't want
59
                #          @user_projects = User.current.projects.sort_by(&:name)
60
                @user_projects = User.current.projects.all(:order => :name)
61
              end
62
63
              render :template => 'projects/index.rhtml', :layout => !request.xhr?
64
            }
65
            format.api  {
66
              @offset, @limit = api_offset_and_limit
67
              @project_count = Project.visible.count
68 769:9af86029dc90 luis
              @projects = Project.visible.find(@projects, :offset => @offset, :limit => @limit, :order => 'lft')
69 767:dd33798e514d luis
            }
70
            format.atom {
71
              projects = Project.visible.find(:all, :order => 'created_on DESC', :limit => Setting.feeds_limit.to_i)
72
              render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
73 752:ded6cd947ade luis
            }
74
            format.js {
75
              render :update do |page|
76 767:dd33798e514d luis
                paginate_projects
77 769:9af86029dc90 luis
                @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
78 752:ded6cd947ade luis
                page.replace_html 'projects', :partial => 'filtered_projects'
79
              end
80
            }
81
          end
82
        end
83
84
        private
85
86 767:dd33798e514d luis
        def filter_projects
87 752:ded6cd947ade luis
          @question = (params[:q] || "").strip
88
89
          if params.has_key?(:project)
90
            @tag_list = (params[:project][:tag_list] || "").strip.split(",")
91
          else
92
            @tag_list = []
93 739:b7ac21913927 luis
          end
94
95 752:ded6cd947ade luis
          @projects = Project.visible
96 749:3f28aebc5fc1 luis
97 752:ded6cd947ade luis
          @featured_projects = @projects.featured if Project.respond_to? :featured
98 739:b7ac21913927 luis
99 752:ded6cd947ade luis
          # luisf
100
          @projects = @projects.search_by_question(@question) unless @question == ""
101
          @tagged_projects_ids = Project.tagged_with(@tag_list).collect{ |project| Project.find(project.id) } unless @tag_list.empty?
102 739:b7ac21913927 luis
103 755:bde9c5bfb559 luis
          debugger
104
105 752:ded6cd947ade luis
          # intersection of both prject groups
106
          @projects = @projects && @tagged_projects_ids unless @tag_list.empty?
107
        end
108 730:4a9bb3b8d5cd luis
      end
109
    end
110
  end
111
end