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 @ 1072:872db7098cb9

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