To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / plugins / redmine_tags / lib / redmine_tags / patches / projects_controller_patch.rb @ 1249:774beb9b79da
History | View | Annotate | Download (4.1 KB)
| 1 |
# -*- coding: utf-8 -*-
|
|---|---|
| 2 |
require_dependency 'projects_controller'
|
| 3 |
|
| 4 |
module RedmineTags |
| 5 |
module Patches |
| 6 |
module ProjectsControllerPatch |
| 7 |
def self.included(base) |
| 8 |
base.send(:include, InstanceMethods) |
| 9 |
base.class_eval do
|
| 10 |
unloadable |
| 11 |
skip_before_filter :authorize, :only => [:set_fieldset_status] |
| 12 |
skip_before_filter :find_project, :only => [:set_fieldset_status] |
| 13 |
|
| 14 |
alias :index filtered_index |
| 15 |
end
|
| 16 |
end
|
| 17 |
|
| 18 |
module InstanceMethods |
| 19 |
def paginate_projects |
| 20 |
sort_init 'name'
|
| 21 |
sort_update %w(name lft created_on updated_on)
|
| 22 |
@limit = per_page_option
|
| 23 |
|
| 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 |
|
| 30 |
@project_pages = ActionController::Pagination::Paginator.new self, @project_count, @limit, params['page'] |
| 31 |
@offset ||= @project_pages.current.offset |
| 32 |
end
|
| 33 |
|
| 34 |
def set_fieldset_status |
| 35 |
|
| 36 |
# luisf. test for missing parameters………
|
| 37 |
field = params[:field_id]
|
| 38 |
status = params[:status]
|
| 39 |
|
| 40 |
session[(field + "_status").to_sym] = status
|
| 41 |
render :nothing => true |
| 42 |
end
|
| 43 |
|
| 44 |
# gets the status of the collabsible fieldsets
|
| 45 |
def get_fieldset_statuses |
| 46 |
if session[:my_projects_fieldset_status].nil? |
| 47 |
@myproj_status = "true" |
| 48 |
else
|
| 49 |
@myproj_status = session[:my_projects_fieldset_status] |
| 50 |
end
|
| 51 |
|
| 52 |
if session[:filters_fieldset_status].nil? |
| 53 |
@filter_status = "false" |
| 54 |
else
|
| 55 |
@filter_status = session[:filters_fieldset_status] |
| 56 |
end
|
| 57 |
|
| 58 |
if params && params[:project] && !params[:project][:tag_list].nil? |
| 59 |
@filter_status = "true" |
| 60 |
end
|
| 61 |
|
| 62 |
end
|
| 63 |
|
| 64 |
# Lists visible projects. Paginator is for top-level projects only
|
| 65 |
# (subprojects belong to them)
|
| 66 |
def filtered_index |
| 67 |
@project = Project.new |
| 68 |
filter_projects |
| 69 |
get_fieldset_statuses |
| 70 |
|
| 71 |
sort_clause = "name"
|
| 72 |
|
| 73 |
respond_to do |format|
|
| 74 |
format.html {
|
| 75 |
paginate_projects |
| 76 |
|
| 77 |
# todo: check ordering ~luisf.14/Jan/2013
|
| 78 |
@projects = @projects[@offset, @limit] |
| 79 |
|
| 80 |
render :template => 'projects/index.html.erb', :layout => !request.xhr? |
| 81 |
} |
| 82 |
format.api {
|
| 83 |
@offset, @limit = api_offset_and_limit |
| 84 |
@project_count = Project.visible.count |
| 85 |
@projects = Project.visible.find(@projects, :offset => @offset, :limit => @limit, :order => 'lft') |
| 86 |
} |
| 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 |
} |
| 91 |
format.js {
|
| 92 |
paginate_projects |
| 93 |
@projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause) |
| 94 |
render :update do |page| |
| 95 |
page.replace_html 'projects', :partial => 'filtered_projects' |
| 96 |
end
|
| 97 |
} |
| 98 |
end
|
| 99 |
end
|
| 100 |
|
| 101 |
private |
| 102 |
|
| 103 |
def filter_projects |
| 104 |
@question = (params[:q] || "").strip |
| 105 |
|
| 106 |
if params.has_key?(:project) |
| 107 |
@tag_list = (params[:project][:tag_list] || "").strip.split(",") |
| 108 |
else
|
| 109 |
@tag_list = []
|
| 110 |
end
|
| 111 |
|
| 112 |
if @question == "" |
| 113 |
@projects = Project.visible_roots |
| 114 |
else
|
| 115 |
@projects = Project.visible_roots.find(Project.visible.search_by_question(@question)) |
| 116 |
end
|
| 117 |
|
| 118 |
unless @tag_list.empty? |
| 119 |
@tagged_projects_ids = Project.visible.tagged_with(@tag_list).collect{ |project| Project.find(project.id).root } |
| 120 |
|
| 121 |
@projects = @projects & @tagged_projects_ids |
| 122 |
@projects = @projects.uniq |
| 123 |
end
|
| 124 |
end
|
| 125 |
end
|
| 126 |
end
|
| 127 |
end
|
| 128 |
end
|