summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-07-14 13:41:30 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-07-14 13:41:30 +0000
commit010bfc56e15f442e4e597ddc9c436361c61b1e7a (patch)
tree498f9a9cea5fac71c0f63c1a2f92ad02ed6f6470
parent3c9263221d3d914b3e6b5f0b8c66ebd859d75403 (diff)
downloadredmine-010bfc56e15f442e4e597ddc9c436361c61b1e7a.tar.gz
redmine-010bfc56e15f442e4e597ddc9c436361c61b1e7a.zip
Ability to save Gantt query filters (#7836).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12020 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/queries_controller.rb18
-rw-r--r--app/models/issue_query.rb25
-rw-r--r--app/models/query.rb1
-rw-r--r--app/views/gantts/show.html.erb23
-rw-r--r--app/views/queries/_form.html.erb9
-rw-r--r--db/migrate/20130713111657_add_queries_options.rb9
-rw-r--r--public/javascripts/gantt.js2
-rw-r--r--test/functional/queries_controller_test.rb37
8 files changed, 115 insertions, 9 deletions
diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb
index cd1ec87a2..8c53f76ef 100644
--- a/app/controllers/queries_controller.rb
+++ b/app/controllers/queries_controller.rb
@@ -59,7 +59,7 @@ class QueriesController < ApplicationController
if @query.save
flash[:notice] = l(:notice_successful_create)
- redirect_to _project_issues_path(@project, :query_id => @query)
+ redirect_to_issues(:query_id => @query)
else
render :action => 'new', :layout => !request.xhr?
end
@@ -77,7 +77,7 @@ class QueriesController < ApplicationController
if @query.save
flash[:notice] = l(:notice_successful_update)
- redirect_to _project_issues_path(@project, :query_id => @query)
+ redirect_to_issues(:query_id => @query)
else
render :action => 'edit'
end
@@ -85,7 +85,7 @@ class QueriesController < ApplicationController
def destroy
@query.destroy
- redirect_to _project_issues_path(@project, :set_filter => 1)
+ redirect_to_issues(:set_filter => 1)
end
private
@@ -103,4 +103,16 @@ private
rescue ActiveRecord::RecordNotFound
render_404
end
+
+ def redirect_to_issues(options)
+ if params[:gantt]
+ if @project
+ redirect_to project_gantt_path(@project, options)
+ else
+ redirect_to issues_gantt_path(options)
+ end
+ else
+ redirect_to _project_issues_path(@project, options)
+ end
+ end
end
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb
index 323e46f4c..bc2ca7abe 100644
--- a/app/models/issue_query.rb
+++ b/app/models/issue_query.rb
@@ -97,6 +97,31 @@ class IssueQuery < Query
!is_private?
end
+ def draw_relations
+ r = options[:draw_relations]
+ r.nil? || r == '1'
+ end
+
+ def draw_relations=(arg)
+ options[:draw_relations] = (arg == '0' ? '0' : nil)
+ end
+
+ def draw_progress_line
+ r = options[:draw_progress_line]
+ r == '1'
+ end
+
+ def draw_progress_line=(arg)
+ options[:draw_progress_line] = (arg == '1' ? '1' : nil)
+ end
+
+ def build_from_params(params)
+ super
+ self.draw_relations = params[:draw_relations] || (params[:query] && params[:query][:draw_relations])
+ self.draw_progress_line = params[:draw_progress_line] || (params[:query] && params[:query][:draw_progress_line])
+ self
+ end
+
def initialize_available_filters
principals = []
subprojects = []
diff --git a/app/models/query.rb b/app/models/query.rb
index 641a263c6..ca04f29b5 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -130,6 +130,7 @@ class Query < ActiveRecord::Base
serialize :filters
serialize :column_names
serialize :sort_criteria, Array
+ serialize :options, Hash
attr_protected :project_id, :user_id
diff --git a/app/views/gantts/show.html.erb b/app/views/gantts/show.html.erb
index f8f25be10..9b138d2d7 100644
--- a/app/views/gantts/show.html.erb
+++ b/app/views/gantts/show.html.erb
@@ -1,4 +1,11 @@
<% @gantt.view = self %>
+<div class="contextual">
+<% if !@query.new_record? && @query.editable_by?(User.current) %>
+ <%= link_to l(:button_edit), edit_query_path(@query, :gantt => 1), :class => 'icon icon-edit' %>
+ <%= delete_link query_path(@query, :gantt => 1) %>
+<% end %>
+</div>
+
<h2><%= @query.new_record? ? l(:label_gantt) : h(@query.name) %></h2>
<%= form_tag({:controller => 'gantts', :action => 'show',
@@ -6,6 +13,7 @@
:year => params[:year], :months => params[:months]},
:method => :get, :id => 'query_form') do %>
<%= hidden_field_tag 'set_filter', '1' %>
+<%= hidden_field_tag 'gantt', '1' %>
<fieldset id="filters" class="collapsible <%= @query.new_record? ? "" : "collapsed" %>">
<legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend>
<div style="<%= @query.new_record? ? "" : "display: none;" %>">
@@ -20,8 +28,8 @@
<td>
<fieldset>
<legend><%= l(:label_related_issues) %></legend>
- <label>
- <%= check_box_tag "draw_rels", params["draw_rels"], params[:set_filter].blank? || params[:draw_rels] %>
+ <label for="draw_relations">
+ <%= check_box 'query', 'draw_relations', :id => 'draw_relations' %>
<% rels = [IssueRelation::TYPE_BLOCKS, IssueRelation::TYPE_PRECEDES] %>
<% rels.each do |rel| %>
<% color = Redmine::Helpers::Gantt::DRAW_TYPES[rel][:color] %>
@@ -35,8 +43,8 @@
<td>
<fieldset>
<legend><%= l(:label_gantt_progress_line) %></legend>
- <label>
- <%= check_box_tag "draw_progress_line", params[:draw_progress_line], params[:draw_progress_line] %>
+ <label for="draw_progress_line">
+ <%= check_box 'query', 'draw_progress_line', :id => 'draw_progress_line' %>
<%= l(:label_display) %>
</label>
</fieldset>
@@ -62,6 +70,11 @@
:class => 'icon icon-checked' %>
<%= link_to l(:button_clear), { :project_id => @project, :set_filter => 1 },
:class => 'icon icon-reload' %>
+<% if @query.new_record? && User.current.allowed_to?(:save_queries, @project, :global => true) %>
+ <%= link_to_function l(:button_save),
+ "$('#query_form').attr('action', '#{ @project ? new_project_query_path(@project) : new_query_path }').submit();",
+ :class => 'icon icon-save' %>
+<% end %>
</p>
<% end %>
@@ -313,7 +326,7 @@
$(document).ready(drawGanttHandler);
$(window).resize(drawGanttHandler);
$(function() {
- $("#draw_rels").change(drawGanttHandler);
+ $("#draw_relations").change(drawGanttHandler);
$("#draw_progress_line").change(drawGanttHandler);
});
<% end %>
diff --git a/app/views/queries/_form.html.erb b/app/views/queries/_form.html.erb
index 116821529..c9f710ac0 100644
--- a/app/views/queries/_form.html.erb
+++ b/app/views/queries/_form.html.erb
@@ -2,6 +2,8 @@
<div class="box">
<div class="tabular">
+<%= hidden_field_tag 'gantt', '1' if params[:gantt] %>
+
<p><label for="query_name"><%=l(:field_name)%></label>
<%= text_field 'query', 'name', :size => 80 %></p>
@@ -31,6 +33,13 @@
<p><label><%= l(:button_show) %></label>
<%= available_block_columns_tags(@query) %></p>
+
+<% if params[:gantt] %>
+ <p><label><%= l(:label_gantt) %></label>
+ <label class="inline"><%= check_box_tag "query[draw_relations]", "1", @query.draw_relations %> <%= l(:label_related_issues) %></label>
+ <label class="inline"><%= check_box_tag "query[draw_progress_line]", "1", @query.draw_progress_line %> <%= l(:label_gantt_progress_line) %></label>
+ </p>
+<% end %>
</fieldset>
</div>
diff --git a/db/migrate/20130713111657_add_queries_options.rb b/db/migrate/20130713111657_add_queries_options.rb
new file mode 100644
index 000000000..f203b11c4
--- /dev/null
+++ b/db/migrate/20130713111657_add_queries_options.rb
@@ -0,0 +1,9 @@
+class AddQueriesOptions < ActiveRecord::Migration
+ def up
+ add_column :queries, :options, :text
+ end
+
+ def down
+ remove_column :queries, :options
+ end
+end
diff --git a/public/javascripts/gantt.js b/public/javascripts/gantt.js
index ba0af9ebd..e5f8ab948 100644
--- a/public/javascripts/gantt.js
+++ b/public/javascripts/gantt.js
@@ -167,6 +167,6 @@ function drawGanttHandler() {
setDrawArea();
if ($("#draw_progress_line").attr('checked'))
drawGanttProgressLines();
- if ($("#draw_rels").attr('checked'))
+ if ($("#draw_relations").attr('checked'))
drawRelations();
}
diff --git a/test/functional/queries_controller_test.rb b/test/functional/queries_controller_test.rb
index b2bbb22fd..d01513984 100644
--- a/test/functional/queries_controller_test.rb
+++ b/test/functional/queries_controller_test.rb
@@ -155,6 +155,43 @@ class QueriesControllerTest < ActionController::TestCase
assert_select 'input[name=?]', 'query[name]'
end
+ def test_create_global_query_from_gantt
+ @request.session[:user_id] = 1
+ assert_difference 'IssueQuery.count' do
+ post :create,
+ :gantt => 1,
+ :operators => {"status_id" => "o"},
+ :values => {"status_id" => ["1"]},
+ :query => {:name => "test_create_from_gantt",
+ :draw_relations => '1',
+ :draw_progress_line => '1'}
+ assert_response 302
+ end
+ query = IssueQuery.order('id DESC').first
+ assert_redirected_to "/issues/gantt?query_id=#{query.id}"
+ assert_equal true, query.draw_relations
+ assert_equal true, query.draw_progress_line
+ end
+
+ def test_create_project_query_from_gantt
+ @request.session[:user_id] = 1
+ assert_difference 'IssueQuery.count' do
+ post :create,
+ :project_id => 'ecookbook',
+ :gantt => 1,
+ :operators => {"status_id" => "o"},
+ :values => {"status_id" => ["1"]},
+ :query => {:name => "test_create_from_gantt",
+ :draw_relations => '0',
+ :draw_progress_line => '0'}
+ assert_response 302
+ end
+ query = IssueQuery.order('id DESC').first
+ assert_redirected_to "/projects/ecookbook/issues/gantt?query_id=#{query.id}"
+ assert_equal false, query.draw_relations
+ assert_equal false, query.draw_progress_line
+ end
+
def test_edit_global_public_query
@request.session[:user_id] = 1
get :edit, :id => 4