summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-10-01 10:44:45 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-10-01 10:44:45 +0000
commit96b4ac12cbc9a89a6e29d50764ed668102c3c93a (patch)
tree9e2fff63ce11ee5f678a35e3f20d99dac05deb3e /app
parente5f5671d66295100d719d4712a03015268d65e02 (diff)
downloadredmine-96b4ac12cbc9a89a6e29d50764ed668102c3c93a.tar.gz
redmine-96b4ac12cbc9a89a6e29d50764ed668102c3c93a.zip
Added a checkbox on custom query form to explicitly say if the query uses default columns or not.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@783 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/queries_controller.rb4
-rw-r--r--app/models/query.rb11
-rw-r--r--app/views/queries/_columns.rhtml7
-rw-r--r--app/views/queries/_form.rhtml10
4 files changed, 21 insertions, 11 deletions
diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb
index fce001cd8..7c8460dd7 100644
--- a/app/controllers/queries_controller.rb
+++ b/app/controllers/queries_controller.rb
@@ -31,6 +31,7 @@ class QueriesController < ApplicationController
@query.user = logged_in_user
@query.executed_by = logged_in_user
@query.is_public = false unless current_role.allowed_to?(:manage_public_queries)
+ @query.column_names = nil if params[:default_columns]
params[:fields].each do |field|
@query.add_filter(field, params[:operators][field], params[:values][field])
@@ -52,7 +53,8 @@ class QueriesController < ApplicationController
end if params[:fields]
@query.attributes = params[:query]
@query.is_public = false unless current_role.allowed_to?(:manage_public_queries)
-
+ @query.column_names = nil if params[:default_columns]
+
if @query.save
flash[:notice] = l(:notice_successful_update)
redirect_to :controller => 'projects', :action => 'list_issues', :id => @project, :query_id => @query
diff --git a/app/models/query.rb b/app/models/query.rb
index c3d9d56e3..400572eb2 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -208,11 +208,10 @@ class Query < ActiveRecord::Base
end
def columns
- if column_names && !column_names.empty?
- available_columns.select {|c| column_names.include?(c.name) }
- else
- # default columns
+ if has_default_columns?
available_columns.select {|c| c.default? }
+ else
+ available_columns.select {|c| column_names.include?(c.name) }
end
end
@@ -225,6 +224,10 @@ class Query < ActiveRecord::Base
def has_column?(column)
column_names && column_names.include?(column.name)
end
+
+ def has_default_columns?
+ column_names.nil? || column_names.empty?
+ end
def statement
# project/subprojects clause
diff --git a/app/views/queries/_columns.rhtml b/app/views/queries/_columns.rhtml
new file mode 100644
index 000000000..f233f8ef6
--- /dev/null
+++ b/app/views/queries/_columns.rhtml
@@ -0,0 +1,7 @@
+<% content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %>
+<legend><%= l(:field_column_names) %></legend>
+<% query.available_columns.each do |column| %>
+<label><%= check_box_tag 'query[column_names][]', column.name, query.has_column?(column) %> <%= l("field_#{column.name}") %></label><br />
+<% end %>
+<%= hidden_field_tag 'query[column_names][]', '' %>
+<% end %>
diff --git a/app/views/queries/_form.rhtml b/app/views/queries/_form.rhtml
index b4a4987cd..a6b5a496c 100644
--- a/app/views/queries/_form.rhtml
+++ b/app/views/queries/_form.rhtml
@@ -10,13 +10,11 @@
<%= check_box 'query', 'is_public' %></p>
<% end %>
-<p><label for="query_column_names"><%=l(:field_column_names)%></label>
-<% @query.available_columns.each do |column| %>
-<%= check_box_tag 'query[column_names][]', column.name, @query.has_column?(column) %> <%= l("field_#{column.name}") %><br />
-<% end %>
-<%= hidden_field_tag 'query[column_names][]', '' %>
-</p>
+<p><label for="query_default_columns"><%=l(:label_default_columns)%></label>
+<%= check_box_tag 'default_columns', 1, @query.has_default_columns?, :id => 'query_default_columns',
+ :onchange => 'if (this.checked) {Element.hide("columns")} else {Element.show("columns")}' %></p>
</div>
+<%= render :partial => 'queries/columns', :locals => {:query => query}%>
<%= render :partial => 'queries/filters', :locals => {:query => query}%>
</div>