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
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
def destroy
@query.destroy
- redirect_to _project_issues_path(@project, :set_filter => 1)
+ redirect_to_issues(:set_filter => 1)
end
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
!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 = []
serialize :filters
serialize :column_names
serialize :sort_criteria, Array
+ serialize :options, Hash
attr_protected :project_id, :user_id
<% @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',
: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;" %>">
<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] %>
<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 %>
<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>
--- /dev/null
+class AddQueriesOptions < ActiveRecord::Migration
+ def up
+ add_column :queries, :options, :text
+ end
+
+ def down
+ remove_column :queries, :options
+ end
+end
setDrawArea();
if ($("#draw_progress_line").attr('checked'))
drawGanttProgressLines();
- if ($("#draw_rels").attr('checked'))
+ if ($("#draw_relations").attr('checked'))
drawRelations();
}
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