@@ -17,11 +17,13 | |||
|
17 | 17 | |
|
18 | 18 | class QueriesController < ApplicationController |
|
19 | 19 | menu_item :issues |
|
20 | before_filter :find_query, :except => [:new, :index] | |
|
21 | before_filter :find_optional_project, :only => :new | |
|
20 | before_filter :find_query, :except => [:new, :create, :index] | |
|
21 | before_filter :find_optional_project, :only => [:new, :create] | |
|
22 | 22 | |
|
23 | 23 | accept_api_auth :index |
|
24 | 24 | |
|
25 | include QueriesHelper | |
|
26 | ||
|
25 | 27 | def index |
|
26 | 28 | case params[:format] |
|
27 | 29 | when 'xml', 'json' |
@@ -41,44 +43,52 class QueriesController < ApplicationController | |||
|
41 | 43 | end |
|
42 | 44 | |
|
43 | 45 | def new |
|
44 |
@query = Query.new |
|
|
45 | @query.project = params[:query_is_for_all] ? nil : @project | |
|
46 | @query = Query.new | |
|
46 | 47 | @query.user = User.current |
|
48 | @query.project = @project | |
|
47 | 49 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
|
50 | build_query_from_params | |
|
51 | end | |
|
48 | 52 | |
|
49 | @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f] | |
|
50 | @query.group_by ||= params[:group_by] | |
|
51 | @query.column_names = params[:c] if params[:c] | |
|
53 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } | |
|
54 | def create | |
|
55 | @query = Query.new(params[:query]) | |
|
56 | @query.user = User.current | |
|
57 | @query.project = params[:query_is_for_all] ? nil : @project | |
|
58 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? | |
|
59 | build_query_from_params | |
|
52 | 60 | @query.column_names = nil if params[:default_columns] |
|
53 | 61 | |
|
54 | if request.post? && params[:confirm] && @query.save | |
|
62 | if @query.save | |
|
55 | 63 | flash[:notice] = l(:notice_successful_create) |
|
56 | 64 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query |
|
57 | return | |
|
65 | else | |
|
66 | render :action => 'new', :layout => !request.xhr? | |
|
58 | 67 | end |
|
59 | render :layout => false if request.xhr? | |
|
60 | 68 | end |
|
61 | 69 | |
|
62 | 70 | def edit |
|
63 | if request.post? | |
|
64 | @query.filters = {} | |
|
65 | @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f] | |
|
66 | @query.attributes = params[:query] | |
|
67 | @query.project = nil if params[:query_is_for_all] | |
|
68 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? | |
|
69 | @query.group_by ||= params[:group_by] | |
|
70 | @query.column_names = params[:c] if params[:c] | |
|
71 | @query.column_names = nil if params[:default_columns] | |
|
71 | end | |
|
72 | 72 | |
|
73 | if @query.save | |
|
74 | flash[:notice] = l(:notice_successful_update) | |
|
75 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query | |
|
76 | end | |
|
73 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |
|
74 | def update | |
|
75 | @query.attributes = params[:query] | |
|
76 | @query.project = nil if params[:query_is_for_all] | |
|
77 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? | |
|
78 | build_query_from_params | |
|
79 | @query.column_names = nil if params[:default_columns] | |
|
80 | ||
|
81 | if @query.save | |
|
82 | flash[:notice] = l(:notice_successful_update) | |
|
83 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query | |
|
84 | else | |
|
85 | render :action => 'edit' | |
|
77 | 86 | end |
|
78 | 87 | end |
|
79 | 88 | |
|
89 | verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } | |
|
80 | 90 | def destroy |
|
81 |
@query.destroy |
|
|
91 | @query.destroy | |
|
82 | 92 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 |
|
83 | 93 | end |
|
84 | 94 |
@@ -71,30 +71,31 module QueriesHelper | |||
|
71 | 71 | cond << " OR project_id = #{@project.id}" if @project |
|
72 | 72 | @query = Query.find(params[:query_id], :conditions => cond) |
|
73 | 73 | raise ::Unauthorized unless @query.visible? |
|
74 | @query.project = @project | |
|
75 | 74 | session[:query] = {:id => @query.id, :project_id => @query.project_id} |
|
76 | 75 | sort_clear |
|
76 | elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) | |
|
77 | # Give it a name, required to be valid | |
|
78 | @query = Query.new(:name => "_") | |
|
79 | @query.project = @project | |
|
80 | build_query_from_params | |
|
81 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} | |
|
77 | 82 | else |
|
78 | if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) | |
|
79 | # Give it a name, required to be valid | |
|
80 | @query = Query.new(:name => "_") | |
|
81 | @query.project = @project | |
|
82 | if params[:fields] || params[:f] | |
|
83 | @query.filters = {} | |
|
84 | @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) | |
|
85 | else | |
|
86 | @query.available_filters.keys.each do |field| | |
|
87 | @query.add_short_filter(field, params[field]) if params[field] | |
|
88 | end | |
|
89 | end | |
|
90 | @query.group_by = params[:group_by] | |
|
91 | @query.column_names = params[:c] || (params[:query] && params[:query][:column_names]) | |
|
92 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} | |
|
93 | else | |
|
94 | @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] | |
|
95 | @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) | |
|
96 | @query.project = @project | |
|
83 | # retrieve from session | |
|
84 | @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] | |
|
85 | @query ||= Query.new(:name => "_", :project_id => session[:project_id] || @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) | |
|
86 | end | |
|
87 | end | |
|
88 | ||
|
89 | def build_query_from_params | |
|
90 | if params[:fields] || params[:f] | |
|
91 | @query.filters = {} | |
|
92 | @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) | |
|
93 | else | |
|
94 | @query.available_filters.keys.each do |field| | |
|
95 | @query.add_short_filter(field, params[field]) if params[field] | |
|
97 | 96 | end |
|
98 | 97 | end |
|
98 | @query.group_by = params[:group_by] || (params[:query] && params[:query][:group_by]) | |
|
99 | @query.column_names = params[:c] || (params[:query] && params[:query][:column_names]) | |
|
99 | 100 | end |
|
100 | 101 | end |
@@ -1,7 +1,7 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 2 | <% if !@query.new_record? && @query.editable_by?(User.current) %> |
|
3 |
<%= link_to l(:button_edit), |
|
|
4 | <%= link_to l(:button_delete), {:controller => 'queries', :action => 'destroy', :id => @query}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %> | |
|
3 | <%= link_to l(:button_edit), @query.project_id ? edit_project_query_path(:project_id => @query.project, :id => @query) : edit_query_path(@query), :class => 'icon icon-edit' %> | |
|
4 | <%= link_to l(:button_delete), @query.project_id ? project_query_path(:project_id => @query.project, :id => @query) : query_path(@query), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %> | |
|
5 | 5 | <% end %> |
|
6 | 6 | </div> |
|
7 | 7 | |
@@ -38,7 +38,7 | |||
|
38 | 38 | <%= link_to_function l(:button_apply), 'submit_query_form("query_form")', :class => 'icon icon-checked' %> |
|
39 | 39 | <%= link_to l(:button_clear), { :set_filter => 1, :project_id => @project }, :class => 'icon icon-reload' %> |
|
40 | 40 | <% if @query.new_record? && User.current.allowed_to?(:save_queries, @project, :global => true) %> |
|
41 | <%= link_to_function l(:button_save), "$('query_form').action='#{ url_for :controller => 'queries', :action => 'new', :project_id => @project }'; submit_query_form('query_form')", :class => 'icon icon-save' %> | |
|
41 | <%= link_to_function l(:button_save), "$('query_form').action='#{ @project ? new_project_query_path(@project) : new_query_path }'; submit_query_form('query_form')", :class => 'icon icon-save' %> | |
|
42 | 42 | <% end %> |
|
43 | 43 | </p> |
|
44 | 44 | <% end %> |
@@ -2,13 +2,13 | |||
|
2 | 2 | |
|
3 | 3 | <% labelled_tabular_form_for :news, @news, :url => project_news_index_path(@project), |
|
4 | 4 | :html => { :id => 'news-form' } do |f| %> |
|
5 | <%= render :partial => 'news/form', :locals => { :f => f } %> | |
|
6 | <%= submit_tag l(:button_create) %> | |
|
7 | <%= link_to_remote l(:label_preview), | |
|
8 | { :url => preview_news_path(:project_id => @project), | |
|
9 | :method => 'get', | |
|
10 | :update => 'preview', | |
|
11 | :with => "Form.serialize('news-form')" | |
|
12 | }, :accesskey => accesskey(:preview) %> | |
|
5 | <%= render :partial => 'news/form', :locals => { :f => f } %> | |
|
6 | <%= submit_tag l(:button_create) %> | |
|
7 | <%= link_to_remote l(:label_preview), | |
|
8 | { :url => preview_news_path(:project_id => @project), | |
|
9 | :method => 'get', | |
|
10 | :update => 'preview', | |
|
11 | :with => "Form.serialize('news-form')" | |
|
12 | }, :accesskey => accesskey(:preview) %> | |
|
13 | 13 | <% end %> |
|
14 | 14 | <div id="preview" class="wiki"></div> |
@@ -1,5 +1,4 | |||
|
1 | 1 | <%= error_messages_for 'query' %> |
|
2 | <%= hidden_field_tag 'confirm', 1 %> | |
|
3 | 2 | |
|
4 | 3 | <div class="box"> |
|
5 | 4 | <div class="tabular"> |
@@ -1,6 +1,6 | |||
|
1 | 1 | <h2><%= l(:label_query) %></h2> |
|
2 | 2 | |
|
3 |
<% form_tag( |
|
|
3 | <% form_tag(@query.project_id ? project_query_path(:project_id => @query.project, :id => @query) : query_path(@query), :onsubmit => 'selectAllOptions("selected_columns");', :method => :put) do %> | |
|
4 | 4 | <%= render :partial => 'form', :locals => {:query => @query} %> |
|
5 | 5 | <%= submit_tag l(:button_save) %> |
|
6 | 6 | <% end %> |
@@ -1,5 +1,5 | |||
|
1 | 1 | <div class="contextual"> |
|
2 |
<%= link_to_if_authorized l(:label_query_new), |
|
|
2 | <%= link_to_if_authorized l(:label_query_new), new_project_query_path(:project_id => @project), :class => 'icon icon-add' %> | |
|
3 | 3 | </div> |
|
4 | 4 | |
|
5 | 5 | <h2><%= l(:label_query_plural) %></h2> |
@@ -16,8 +16,8 | |||
|
16 | 16 | <td align="right"> |
|
17 | 17 | <small> |
|
18 | 18 | <% if query.editable_by?(User.current) %> |
|
19 |
<%= link_to l(:button_edit), |
|
|
20 |
<%= link_to l(:button_delete), |
|
|
19 | <%= link_to l(:button_edit), edit_query_path(query), :class => 'icon icon-edit' %> | |
|
20 | <%= link_to l(:button_delete), query_path(query), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %> | |
|
21 | 21 | </small> |
|
22 | 22 | <% end %> |
|
23 | 23 | </td> |
@@ -1,6 +1,6 | |||
|
1 | 1 | <h2><%= l(:label_query_new) %></h2> |
|
2 | 2 | |
|
3 |
<% form_tag( |
|
|
3 | <% form_tag(@project ? project_queries_path(:project_id => @project) : queries_path, :onsubmit => 'selectAllOptions("selected_columns");') do %> | |
|
4 | 4 | <%= render :partial => 'form', :locals => {:query => @query} %> |
|
5 | 5 | <%= submit_tag l(:button_save) %> |
|
6 | 6 | <% end %> |
@@ -77,7 +77,7 ActionController::Routing::Routes.draw do |map| | |||
|
77 | 77 | end |
|
78 | 78 | |
|
79 | 79 | map.resources :issue_moves, :only => [:new, :create], :path_prefix => '/issues', :as => 'move' |
|
80 |
map.resources :queries, : |
|
|
80 | map.resources :queries, :except => [:show] | |
|
81 | 81 | |
|
82 | 82 | # Misc issue routes. TODO: move into resources |
|
83 | 83 | map.auto_complete_issues '/issues/auto_complete', :controller => 'auto_completes', :action => 'issues' |
@@ -156,6 +156,7 ActionController::Routing::Routes.draw do |map| | |||
|
156 | 156 | project.resources :versions, :shallow => true, :collection => {:close_completed => :put}, :member => {:status_by => :post} |
|
157 | 157 | project.resources :news, :shallow => true |
|
158 | 158 | project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id' |
|
159 | project.resources :queries, :except => [:show] | |
|
159 | 160 | |
|
160 | 161 | project.wiki_start_page 'wiki', :controller => 'wiki', :action => 'show', :conditions => {:method => :get} |
|
161 | 162 | project.wiki_index 'wiki/index', :controller => 'wiki', :action => 'index', :conditions => {:method => :get} |
@@ -226,7 +227,6 ActionController::Routing::Routes.draw do |map| | |||
|
226 | 227 | map.resources :groups |
|
227 | 228 | |
|
228 | 229 | #left old routes at the bottom for backwards compat |
|
229 | map.connect 'projects/:project_id/queries/:action', :controller => 'queries' | |
|
230 | 230 | map.connect 'projects/:project_id/issues/:action', :controller => 'issues' |
|
231 | 231 | map.connect 'projects/:project_id/documents/:action', :controller => 'documents' |
|
232 | 232 | map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards' |
@@ -60,9 +60,8 class QueriesControllerTest < ActionController::TestCase | |||
|
60 | 60 | |
|
61 | 61 | def test_new_project_public_query |
|
62 | 62 | @request.session[:user_id] = 2 |
|
63 |
post : |
|
|
63 | post :create, | |
|
64 | 64 | :project_id => 'ecookbook', |
|
65 | :confirm => '1', | |
|
66 | 65 | :default_columns => '1', |
|
67 | 66 | :f => ["status_id", "assigned_to_id"], |
|
68 | 67 | :op => {"assigned_to_id" => "=", "status_id" => "o"}, |
@@ -78,9 +77,8 class QueriesControllerTest < ActionController::TestCase | |||
|
78 | 77 | |
|
79 | 78 | def test_new_project_private_query |
|
80 | 79 | @request.session[:user_id] = 3 |
|
81 |
post : |
|
|
80 | post :create, | |
|
82 | 81 | :project_id => 'ecookbook', |
|
83 | :confirm => '1', | |
|
84 | 82 | :default_columns => '1', |
|
85 | 83 | :fields => ["status_id", "assigned_to_id"], |
|
86 | 84 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
@@ -96,8 +94,7 class QueriesControllerTest < ActionController::TestCase | |||
|
96 | 94 | |
|
97 | 95 | def test_new_global_private_query_with_custom_columns |
|
98 | 96 | @request.session[:user_id] = 3 |
|
99 |
post : |
|
|
100 | :confirm => '1', | |
|
97 | post :create, | |
|
101 | 98 | :fields => ["status_id", "assigned_to_id"], |
|
102 | 99 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
103 | 100 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
@@ -112,10 +109,24 class QueriesControllerTest < ActionController::TestCase | |||
|
112 | 109 | assert q.valid? |
|
113 | 110 | end |
|
114 | 111 | |
|
112 | def test_new_global_query_with_custom_filters | |
|
113 | @request.session[:user_id] = 3 | |
|
114 | post :create, | |
|
115 | :fields => ["assigned_to_id"], | |
|
116 | :operators => {"assigned_to_id" => "="}, | |
|
117 | :values => { "assigned_to_id" => ["me"]}, | |
|
118 | :query => {"name" => "test_new_global_query"} | |
|
119 | ||
|
120 | q = Query.find_by_name('test_new_global_query') | |
|
121 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q | |
|
122 | assert !q.has_filter?(:status_id) | |
|
123 | assert_equal ['assigned_to_id'], q.filters.keys | |
|
124 | assert q.valid? | |
|
125 | end | |
|
126 | ||
|
115 | 127 | def test_new_with_sort |
|
116 | 128 | @request.session[:user_id] = 1 |
|
117 |
post : |
|
|
118 | :confirm => '1', | |
|
129 | post :create, | |
|
119 | 130 | :default_columns => '1', |
|
120 | 131 | :operators => {"status_id" => "o"}, |
|
121 | 132 | :values => {"status_id" => ["1"]}, |
@@ -144,9 +155,8 class QueriesControllerTest < ActionController::TestCase | |||
|
144 | 155 | |
|
145 | 156 | def test_edit_global_public_query |
|
146 | 157 | @request.session[:user_id] = 1 |
|
147 |
p |
|
|
158 | put :update, | |
|
148 | 159 | :id => 4, |
|
149 | :confirm => '1', | |
|
150 | 160 | :default_columns => '1', |
|
151 | 161 | :fields => ["status_id", "assigned_to_id"], |
|
152 | 162 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
@@ -175,9 +185,8 class QueriesControllerTest < ActionController::TestCase | |||
|
175 | 185 | |
|
176 | 186 | def test_edit_global_private_query |
|
177 | 187 | @request.session[:user_id] = 3 |
|
178 |
p |
|
|
188 | put :update, | |
|
179 | 189 | :id => 3, |
|
180 | :confirm => '1', | |
|
181 | 190 | :default_columns => '1', |
|
182 | 191 | :fields => ["status_id", "assigned_to_id"], |
|
183 | 192 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
@@ -234,7 +243,7 class QueriesControllerTest < ActionController::TestCase | |||
|
234 | 243 | |
|
235 | 244 | def test_destroy |
|
236 | 245 | @request.session[:user_id] = 2 |
|
237 |
|
|
|
246 | delete :destroy, :id => 1 | |
|
238 | 247 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil |
|
239 | 248 | assert_nil Query.find_by_id(1) |
|
240 | 249 | end |
@@ -218,8 +218,17 class RoutingTest < ActionController::IntegrationTest | |||
|
218 | 218 | should_route :get, "/queries/new", :controller => 'queries', :action => 'new' |
|
219 | 219 | should_route :get, "/projects/redmine/queries/new", :controller => 'queries', :action => 'new', :project_id => 'redmine' |
|
220 | 220 | |
|
221 |
should_route :post, "/queries |
|
|
222 |
should_route :post, "/projects/redmine/queries |
|
|
221 | should_route :post, "/queries", :controller => 'queries', :action => 'create' | |
|
222 | should_route :post, "/projects/redmine/queries", :controller => 'queries', :action => 'create', :project_id => 'redmine' | |
|
223 | ||
|
224 | should_route :get, "/queries/1/edit", :controller => 'queries', :action => 'edit', :id => '1' | |
|
225 | should_route :get, "/projects/redmine/queries/1/edit", :controller => 'queries', :action => 'edit', :id => '1', :project_id => 'redmine' | |
|
226 | ||
|
227 | should_route :put, "/queries/1", :controller => 'queries', :action => 'update', :id => '1' | |
|
228 | should_route :put, "/projects/redmine/queries/1", :controller => 'queries', :action => 'update', :id => '1', :project_id => 'redmine' | |
|
229 | ||
|
230 | should_route :delete, "/queries/1", :controller => 'queries', :action => 'destroy', :id => '1' | |
|
231 | should_route :delete, "/projects/redmine/queries/1", :controller => 'queries', :action => 'destroy', :id => '1', :project_id => 'redmine' | |
|
223 | 232 | end |
|
224 | 233 | |
|
225 | 234 | context "repositories" do |
General Comments 0
You need to be logged in to leave comments.
Login now