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 @ 1298:4f746d8966dd
History | View | Annotate | Download (3.36 KB)
| 1 | 909:cbb26bc654de | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 1295:622f24f53b42 | Chris | # Copyright (C) 2006-2013 Jean-Philippe Lang
|
| 3 | 0:513646585e45 | Chris | #
|
| 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 | 909:cbb26bc654de | Chris | #
|
| 9 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | #
|
| 14 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | 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 | 0:513646585e45 | Chris | end
|
| 34 | 909:cbb26bc654de | Chris | |
| 35 | 1295:622f24f53b42 | Chris | @query_count = IssueQuery.visible.count |
| 36 | @query_pages = Paginator.new @query_count, @limit, params['page'] |
||
| 37 | @queries = IssueQuery.visible.all(:limit => @limit, :offset => @offset, :order => "#{Query.table_name}.name") |
||
| 38 | 909:cbb26bc654de | Chris | |
| 39 | respond_to do |format|
|
||
| 40 | format.api |
||
| 41 | 0:513646585e45 | Chris | end
|
| 42 | end
|
||
| 43 | |||
| 44 | 909:cbb26bc654de | Chris | def new |
| 45 | 1295:622f24f53b42 | Chris | @query = IssueQuery.new |
| 46 | 909:cbb26bc654de | Chris | @query.user = User.current |
| 47 | @query.project = @project |
||
| 48 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
||
| 49 | 1295:622f24f53b42 | Chris | @query.build_from_params(params)
|
| 50 | 909:cbb26bc654de | Chris | end
|
| 51 | |||
| 52 | def create |
||
| 53 | 1295:622f24f53b42 | Chris | @query = IssueQuery.new(params[:query]) |
| 54 | 909:cbb26bc654de | Chris | @query.user = User.current |
| 55 | @query.project = params[:query_is_for_all] ? nil : @project |
||
| 56 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
||
| 57 | 1295:622f24f53b42 | Chris | @query.build_from_params(params)
|
| 58 | 909:cbb26bc654de | Chris | @query.column_names = nil if params[:default_columns] |
| 59 | |||
| 60 | if @query.save |
||
| 61 | flash[:notice] = l(:notice_successful_create) |
||
| 62 | 1295:622f24f53b42 | Chris | redirect_to _project_issues_path(@project, :query_id => @query) |
| 63 | 909:cbb26bc654de | Chris | else
|
| 64 | render :action => 'new', :layout => !request.xhr? |
||
| 65 | end
|
||
| 66 | end
|
||
| 67 | |||
| 68 | def edit |
||
| 69 | end
|
||
| 70 | |||
| 71 | def update |
||
| 72 | @query.attributes = params[:query] |
||
| 73 | @query.project = nil if params[:query_is_for_all] |
||
| 74 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
||
| 75 | 1295:622f24f53b42 | Chris | @query.build_from_params(params)
|
| 76 | 909:cbb26bc654de | Chris | @query.column_names = nil if params[:default_columns] |
| 77 | |||
| 78 | if @query.save |
||
| 79 | flash[:notice] = l(:notice_successful_update) |
||
| 80 | 1295:622f24f53b42 | Chris | redirect_to _project_issues_path(@project, :query_id => @query) |
| 81 | 909:cbb26bc654de | Chris | else
|
| 82 | render :action => 'edit' |
||
| 83 | end
|
||
| 84 | end
|
||
| 85 | |||
| 86 | 0:513646585e45 | Chris | def destroy |
| 87 | 909:cbb26bc654de | Chris | @query.destroy
|
| 88 | 1295:622f24f53b42 | Chris | redirect_to _project_issues_path(@project, :set_filter => 1) |
| 89 | 0:513646585e45 | Chris | end
|
| 90 | 909:cbb26bc654de | Chris | |
| 91 | 0:513646585e45 | Chris | private |
| 92 | def find_query |
||
| 93 | 1295:622f24f53b42 | Chris | @query = IssueQuery.find(params[:id]) |
| 94 | 0:513646585e45 | Chris | @project = @query.project |
| 95 | render_403 unless @query.editable_by?(User.current) |
||
| 96 | rescue ActiveRecord::RecordNotFound |
||
| 97 | render_404 |
||
| 98 | end
|
||
| 99 | 909:cbb26bc654de | Chris | |
| 100 | 0:513646585e45 | Chris | def find_optional_project |
| 101 | @project = Project.find(params[:project_id]) if params[:project_id] |
||
| 102 | render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true) |
||
| 103 | rescue ActiveRecord::RecordNotFound |
||
| 104 | render_404 |
||
| 105 | end
|
||
| 106 | end |