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 @ 997:c1b8a34d3560

History | View | Annotate | Download (4.78 KB)

1 996:c43450d54787 chris
# -*- coding: utf-8 -*-
2 730:4a9bb3b8d5cd luis
require_dependency 'projects_controller'
3
4
module RedmineTags
5
  module Patches
6 767:dd33798e514d luis
    module ProjectsControllerPatch
7 730:4a9bb3b8d5cd luis
      def self.included(base)
8
        base.send(:include, InstanceMethods)
9
        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 730:4a9bb3b8d5cd luis
          before_filter :add_tags_to_project, :only => [:save, :update]
14 767:dd33798e514d luis
15
          alias :index filtered_index
16 730:4a9bb3b8d5cd luis
        end
17
      end
18
19
      module InstanceMethods
20 815:4d3ac2b4156c luis
21 752:ded6cd947ade luis
        def add_tags_to_project
22
23 731:3f87a3b61d9c luis
          if params && params[:project] && !params[:project][:tag_list].nil?
24 813:0987c3565751 luis
            old_tags = @project.tag_list.to_s.downcase
25
            new_tags = params[:project][:tag_list].to_s.downcase
26 752:ded6cd947ade luis
27 731:3f87a3b61d9c luis
            unless (old_tags == new_tags)
28 815:4d3ac2b4156c luis
              @project.tag_list = ActionController::Base.helpers.strip_tags(new_tags)
29 731:3f87a3b61d9c luis
            end
30 739:b7ac21913927 luis
          end
31 730:4a9bb3b8d5cd luis
        end
32 752:ded6cd947ade luis
33 767:dd33798e514d luis
        def paginate_projects
34
          sort_init 'name'
35
          sort_update %w(name lft created_on updated_on)
36
          @limit = per_page_option
37 769:9af86029dc90 luis
          @project_count = Project.visible_roots.find(@projects).count
38 899:5d5943de529f luis
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 776:af852d82b00b luis
        def set_fieldset_status
44
45
          # luisf. test for missing parameters………
46
          field = params[:field_id]
47
          status = params[:status]
48
49 773:c761e467a390 luis
          session[(field + "_status").to_sym] = status
50 776:af852d82b00b luis
          render :nothing => true
51 773:c761e467a390 luis
        end
52
53
        # gets the status of the collabsible fieldsets
54 776:af852d82b00b luis
        def get_fieldset_statuses
55
          if session[:my_projects_fieldset_status].nil?
56 783:b153713dc4fd luis
            @myproj_status = "true"
57 773:c761e467a390 luis
          else
58 776:af852d82b00b luis
            @myproj_status = session[:my_projects_fieldset_status]
59
          end
60
61
          if session[:filters_fieldset_status].nil?
62 783:b153713dc4fd luis
            @filter_status = "false"
63 773:c761e467a390 luis
          else
64 776:af852d82b00b luis
            @filter_status = session[:filters_fieldset_status]
65 798:829052890acb luis
          end
66
67
          if params && params[:project] && !params[:project][:tag_list].nil?
68
            @filter_status = "true"
69
          end
70
71 773:c761e467a390 luis
        end
72 767:dd33798e514d luis
73
        # Lists visible projects. Paginator is for top-level projects only
74
        # (subprojects belong to them)
75
        def filtered_index
76 752:ded6cd947ade luis
          @project = Project.new
77 767:dd33798e514d luis
          filter_projects
78 773:c761e467a390 luis
          get_fieldset_statuses
79 769:9af86029dc90 luis
80 752:ded6cd947ade luis
          respond_to do |format|
81 767:dd33798e514d luis
            format.html {
82
              paginate_projects
83 786:ae82810661da luis
84 769:9af86029dc90 luis
              @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
85 767:dd33798e514d luis
86
              if User.current.logged?
87
                # seems sort_by gives us case-sensitive ordering, which we don't want
88
                #          @user_projects = User.current.projects.sort_by(&:name)
89
                @user_projects = User.current.projects.all(:order => :name)
90
              end
91
92 919:b03f28dd9026 Chris
              render :template => 'projects/index.html.erb', :layout => !request.xhr?
93 767:dd33798e514d luis
            }
94 779:06a9d1cf5e15 luis
            format.api {
95 767:dd33798e514d luis
              @offset, @limit = api_offset_and_limit
96
              @project_count = Project.visible.count
97 769:9af86029dc90 luis
              @projects = Project.visible.find(@projects, :offset => @offset, :limit => @limit, :order => 'lft')
98 767:dd33798e514d luis
            }
99
            format.atom {
100
              projects = Project.visible.find(:all, :order => 'created_on DESC', :limit => Setting.feeds_limit.to_i)
101
              render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
102 752:ded6cd947ade luis
            }
103
            format.js {
104 779:06a9d1cf5e15 luis
              paginate_projects
105
              @projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
106 752:ded6cd947ade luis
              render :update do |page|
107
                page.replace_html 'projects', :partial => 'filtered_projects'
108
              end
109
            }
110
          end
111
        end
112
113
        private
114
115 767:dd33798e514d luis
        def filter_projects
116 752:ded6cd947ade luis
          @question = (params[:q] || "").strip
117
118
          if params.has_key?(:project)
119
            @tag_list = (params[:project][:tag_list] || "").strip.split(",")
120
          else
121
            @tag_list = []
122 739:b7ac21913927 luis
          end
123
124 786:ae82810661da luis
          if  @question == ""
125 899:5d5943de529f luis
            @projects = Project.visible_roots
126 786:ae82810661da luis
          else
127 899:5d5943de529f luis
            @projects = Project.visible_roots.find(Project.visible.search_by_question(@question))
128 786:ae82810661da luis
          end
129
130
          unless @tag_list.empty?
131 996:c43450d54787 chris
            @tagged_projects_ids = Project.visible.tagged_with(@tag_list).collect{ |project| Project.find(project.id).root }
132 786:ae82810661da luis
            @projects = @projects & @tagged_projects_ids
133 996:c43450d54787 chris
            @projects = @projects.uniq
134 786:ae82810661da luis
          end
135 752:ded6cd947ade luis
        end
136 730:4a9bb3b8d5cd luis
      end
137
    end
138
  end
139
end