From: Jean-Philippe Lang Date: Sun, 14 Jul 2013 13:41:30 +0000 (+0000) Subject: Ability to save Gantt query filters (#7836). X-Git-Tag: 2.4.0~204 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=010bfc56e15f442e4e597ddc9c436361c61b1e7a;p=redmine.git Ability to save Gantt query filters (#7836). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12020 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- 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 %> +
+<% 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 %> +
+

<%= @query.new_record? ? l(:label_gantt) : h(@query.name) %>

<%= 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' %>
"> <%= l(:label_filter_plural) %>
"> @@ -20,8 +28,8 @@
<%= l(:label_related_issues) %> -
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