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