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