]> source.dussan.org Git - redmine.git/commitdiff
Ability to save Gantt query filters (#7836).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 14 Jul 2013 13:41:30 +0000 (13:41 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 14 Jul 2013 13:41:30 +0000 (13:41 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12020 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/queries_controller.rb
app/models/issue_query.rb
app/models/query.rb
app/views/gantts/show.html.erb
app/views/queries/_form.html.erb
db/migrate/20130713111657_add_queries_options.rb [new file with mode: 0644]
public/javascripts/gantt.js
test/functional/queries_controller_test.rb

index cd1ec87a29027e8eacca0e8f41643a7804f973c3..8c53f76efa103606705f7fa4b4160e2cbba7a2c7 100644 (file)
@@ -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
index 323e46f4c4b5a8b5d6b6e7da21de2afa46bdaf12..bc2ca7abeae2da216b11eda82ba9493167a2d3be 100644 (file)
@@ -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 = []
index 641a263c678b7fa99a13ac9a4547a06769be44be..ca04f29b5051c70a000fc732f193303527147ea6 100644 (file)
@@ -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
 
index f8f25be1044daf0ae3f258b40fed3665cc5ca9de..9b138d2d7752c2c101f5c617d5a094cc6c2a6f60 100644 (file)
@@ -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>
                      :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 %>
 
   $(document).ready(drawGanttHandler);
   $(window).resize(drawGanttHandler);
   $(function() {
-    $("#draw_rels").change(drawGanttHandler);
+    $("#draw_relations").change(drawGanttHandler);
     $("#draw_progress_line").change(drawGanttHandler);
   });
 <% end %>
index 1168215299243b1a1a80582e899d2b135bd51547..c9f710ac0c632c290a8402e742189618b0d9de32 100644 (file)
@@ -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>
 
 
 <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 (file)
index 0000000..f203b11
--- /dev/null
@@ -0,0 +1,9 @@
+class AddQueriesOptions < ActiveRecord::Migration
+  def up
+    add_column :queries, :options, :text
+  end
+
+  def down
+    remove_column :queries, :options
+  end
+end
index ba0af9ebd28d17fdfccccff22b07fde7f6712b79..e5f8ab9481c19d1d1089014fea5f13d847bc91a2 100644 (file)
@@ -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();
 }
index b2bbb22fd691fb7c495d342c5add7cb982a81745..d0151398444de8c0545c0dfc29890a80cf757003 100644 (file)
@@ -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