To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / queries_controller.rb @ 1541:2696466256ff
History | View | Annotate | Download (3.71 KB)
| 1 |
# Redmine - project management software
|
|---|---|
| 2 |
# Copyright (C) 2006-2014 Jean-Philippe Lang
|
| 3 |
#
|
| 4 |
# This program is free software; you can redistribute it and/or
|
| 5 |
# modify it under the terms of the GNU General Public License
|
| 6 |
# as published by the Free Software Foundation; either version 2
|
| 7 |
# of the License, or (at your option) any later version.
|
| 8 |
#
|
| 9 |
# This program is distributed in the hope that it will be useful,
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
# GNU General Public License for more details.
|
| 13 |
#
|
| 14 |
# You should have received a copy of the GNU General Public License
|
| 15 |
# along with this program; if not, write to the Free Software
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 17 |
|
| 18 |
class QueriesController < ApplicationController |
| 19 |
menu_item :issues
|
| 20 |
before_filter :find_query, :except => [:new, :create, :index] |
| 21 |
before_filter :find_optional_project, :only => [:new, :create] |
| 22 |
|
| 23 |
accept_api_auth :index
|
| 24 |
|
| 25 |
include QueriesHelper
|
| 26 |
|
| 27 |
def index |
| 28 |
case params[:format] |
| 29 |
when 'xml', 'json' |
| 30 |
@offset, @limit = api_offset_and_limit |
| 31 |
else
|
| 32 |
@limit = per_page_option
|
| 33 |
end
|
| 34 |
@query_count = IssueQuery.visible.count |
| 35 |
@query_pages = Paginator.new @query_count, @limit, params['page'] |
| 36 |
@queries = IssueQuery.visible. |
| 37 |
order("#{Query.table_name}.name").
|
| 38 |
limit(@limit).
|
| 39 |
offset(@offset).
|
| 40 |
all |
| 41 |
respond_to do |format|
|
| 42 |
format.api |
| 43 |
end
|
| 44 |
end
|
| 45 |
|
| 46 |
def new |
| 47 |
@query = IssueQuery.new |
| 48 |
@query.user = User.current |
| 49 |
@query.project = @project |
| 50 |
@query.visibility = IssueQuery::VISIBILITY_PRIVATE unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
| 51 |
@query.build_from_params(params)
|
| 52 |
end
|
| 53 |
|
| 54 |
def create |
| 55 |
@query = IssueQuery.new(params[:query]) |
| 56 |
@query.user = User.current |
| 57 |
@query.project = params[:query_is_for_all] ? nil : @project |
| 58 |
@query.visibility = IssueQuery::VISIBILITY_PRIVATE unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
| 59 |
@query.build_from_params(params)
|
| 60 |
@query.column_names = nil if params[:default_columns] |
| 61 |
|
| 62 |
if @query.save |
| 63 |
flash[:notice] = l(:notice_successful_create) |
| 64 |
redirect_to_issues(:query_id => @query) |
| 65 |
else
|
| 66 |
render :action => 'new', :layout => !request.xhr? |
| 67 |
end
|
| 68 |
end
|
| 69 |
|
| 70 |
def edit |
| 71 |
end
|
| 72 |
|
| 73 |
def update |
| 74 |
@query.attributes = params[:query] |
| 75 |
@query.project = nil if params[:query_is_for_all] |
| 76 |
@query.visibility = IssueQuery::VISIBILITY_PRIVATE unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
| 77 |
@query.build_from_params(params)
|
| 78 |
@query.column_names = nil if params[:default_columns] |
| 79 |
|
| 80 |
if @query.save |
| 81 |
flash[:notice] = l(:notice_successful_update) |
| 82 |
redirect_to_issues(:query_id => @query) |
| 83 |
else
|
| 84 |
render :action => 'edit' |
| 85 |
end
|
| 86 |
end
|
| 87 |
|
| 88 |
def destroy |
| 89 |
@query.destroy
|
| 90 |
redirect_to_issues(:set_filter => 1) |
| 91 |
end
|
| 92 |
|
| 93 |
private |
| 94 |
def find_query |
| 95 |
@query = IssueQuery.find(params[:id]) |
| 96 |
@project = @query.project |
| 97 |
render_403 unless @query.editable_by?(User.current) |
| 98 |
rescue ActiveRecord::RecordNotFound |
| 99 |
render_404 |
| 100 |
end
|
| 101 |
|
| 102 |
def find_optional_project |
| 103 |
@project = Project.find(params[:project_id]) if params[:project_id] |
| 104 |
render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true) |
| 105 |
rescue ActiveRecord::RecordNotFound |
| 106 |
render_404 |
| 107 |
end
|
| 108 |
|
| 109 |
def redirect_to_issues(options) |
| 110 |
if params[:gantt] |
| 111 |
if @project |
| 112 |
redirect_to project_gantt_path(@project, options)
|
| 113 |
else
|
| 114 |
redirect_to issues_gantt_path(options) |
| 115 |
end
|
| 116 |
else
|
| 117 |
redirect_to _project_issues_path(@project, options)
|
| 118 |
end
|
| 119 |
end
|
| 120 |
end
|