Deleted query new/edit forms and corresponding partials/helper methods.

pull/1332/head
Richard 11 years ago
parent be3890b566
commit 600739063a
  1. 101
      app/controllers/queries_controller.rb
  2. 44
      app/helpers/queries_helper.rb
  3. 71
      app/views/queries/_columns.html.erb
  4. 101
      app/views/queries/_form.html.erb
  5. 35
      app/views/queries/edit.html.erb
  6. 35
      app/views/queries/new.html.erb
  7. 255
      test/functional/queries_controller_test.rb

@ -1,101 +0,0 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
#TODO: convert this controller and its routes to not use the catch-all-route
class QueriesController < ApplicationController
menu_item :issues
before_filter :find_query, :except => :new
before_filter :find_optional_project, :only => :new
before_filter :prepare_for_creating, :only => :new
before_filter :prepare_for_editing, :only => :edit
def new
if request.post? && params[:confirm] && @query.save
flash[:notice] = l(:notice_successful_create)
redirect_to :controller => '/work_packages', :action => 'index', :project_id => @project, :query_id => @query
return
end
render :layout => false if request.xhr?
end
def edit
if request.post?
if @query.save
flash[:notice] = l(:notice_successful_update)
redirect_to :controller => '/work_packages', :action => 'index', :project_id => @project, :query_id => @query
end
end
end
def destroy
@query.destroy if request.post?
redirect_to :controller => '/work_packages', :action => 'index', :project_id => @project, :set_filter => 1
end
private
def prepare_for_creating
@query = Query.new params[:query] ? permitted_params.query : nil
@query.project = @project unless params[:query_is_for_all]
prepare_query @query
@query.user = User.current
end
def prepare_for_editing
if request.post?
@query.update_attributes permitted_params.query
prepare_query @query
end
end
def prepare_query(query)
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
view_context.add_filter_from_params if params[:fields] || params[:f]
@query.group_by ||= params[:group_by]
@query.project = nil if params[:query_is_for_all]
@query.display_sums ||= params[:display_sums].present?
@query.column_names = params[:c] if params[:c]
@query.column_names = nil if params[:default_columns]
end
def find_query
@query = Query.find(params[:id])
@project = @query.project
render_403 unless @query.editable_by?(User.current)
rescue ActiveRecord::RecordNotFound
render_404
end
def find_optional_project
@project = Project.find(params[:project_id]) if params[:project_id]
render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true)
rescue ActiveRecord::RecordNotFound
render_404
end
end

@ -37,50 +37,6 @@ module QueriesHelper
(column.is_a? QueryCustomFieldColumn) ? column.custom_field.name_locale : nil
end
def column_header(column)
column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
:default_order => column.default_order,
:lang => column_locale(column))
: content_tag('th', h(column.caption), :lang => column_locale(column))
end
def column_content(column, issue)
value = column.value(issue)
case value.class.name
when 'String'
if column.name == :subject
link_to(h(value), work_package_path(issue))
else
h(value)
end
when 'Time'
format_time(value)
when 'Date'
format_date(value)
when 'Fixnum', 'Float'
if column.name == :done_ratio
progress_bar(value, :width => '80px')
else
h(value.to_s)
end
when 'User'
link_to_user value
when 'Project'
link_to_project value
when 'Version'
link_to(h(value), :controller => '/versions', :action => 'show', :id => value)
when 'TrueClass'
l(:general_text_Yes)
when 'FalseClass'
l(:general_text_No)
when 'Issue', 'PlanningElement'
link_to_work_package(value, :subject => false)
else
h(value)
end
end
def add_filter_from_params
@query.filters = []
@query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v])

@ -1,71 +0,0 @@
<%#-- copyright
OpenProject is a project management system.
Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 3.
OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
Copyright (C) 2006-2013 Jean-Philippe Lang
Copyright (C) 2010-2013 the ChiliProject Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See doc/COPYRIGHT.rdoc for more details.
++#%>
<table style="border-collapse: collapse; border:0;">
<tr>
<td style="padding-left:3px">
<%= label_tag "available_columns", l(:description_available_columns) %>
<br \>
<%= select_tag 'available_columns',
options_for_select((query.available_columns - query.columns).collect {|column| [column.caption, column.name]}),
:multiple => true, :size => 10, :style => "width:150px" %>
</td>
<td class="table-buttons" align="center" valign="middle">
<%= link_to icon_wrapper('icon icon-arrow-right5', l(:label_add_columns)), {},
{ title: l(:label_add_columns),
onclick: "moveOptions('available_columns', 'selected_columns'); return false;" } %>
<br />
<%= link_to icon_wrapper('icon icon-arrow-right5-1', l(:label_remove_columns)), {},
{ title: l(:label_remove_columns),
style: "margin-right: 5px",
onclick: "moveOptions('selected_columns', 'available_columns'); return false;" } %>
</td>
<td>
<%= label_tag "selected_columns", l(:description_selected_columns) %>
<br \>
<%= select_tag 'c[]',
options_for_select(query.columns.collect {|column| [column.caption, column.name]}),
:id => 'selected_columns', :multiple => true, :size => 10, :style => "width:150px" %>
</td>
<td class="table-buttons" align="center" valign="middle">
<%= link_to icon_wrapper('icon icon-arrow-right5-3', l(:label_sort_higher)), {},
{ title: l(:label_sort_higher),
onclick: "moveOptionUp('selected_columns'); return false;" } %>
<br />
<%= link_to icon_wrapper('icon icon-arrow-right5-2', l(:label_sort_lower)), {},
{ title: l(:label_sort_lower),
style: "margin-right: 3px",
onclick: "moveOptionDown('selected_columns'); return false;" } %>
</td>
</tr>
</table>
<% content_for :header_tags do %>
<%= javascript_include_tag 'select_list_move' %>
<% end %>

@ -1,101 +0,0 @@
<%#-- copyright
OpenProject is a project management system.
Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 3.
OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
Copyright (C) 2006-2013 Jean-Philippe Lang
Copyright (C) 2010-2013 the ChiliProject Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See doc/COPYRIGHT.rdoc for more details.
++#%>
<%# expects the following locals:
- @query and query: a Query object
%>
<%= error_messages_for 'query' %>
<%= hidden_field_tag 'confirm', 1 %>
<div class="box">
<div class="tabular">
<p>
<%= label :query, :name, required_field_name(Query.human_attribute_name(:name)) %>
<%= text_field 'query', 'name', size: 80 %>
</p>
<% if query.any_summable_columns? %>
<p>
<%= label :query, :display_sums %>
<%= check_box 'query', 'display_sums' %>
</p>
<% end %>
<%= call_hook(:view_query_form_top, query: query) %>
<% if User.current.admin? || User.current.allowed_to?(:manage_public_queries, @project) %>
<p>
<%= label :query, :is_public %>
<%= check_box :query, :is_public,
onchange: (User.current.admin? ? nil : 'if (this.checked) {$("query_is_for_all").checked = false; $("query_is_for_all").disabled = true;} else {$("query_is_for_all").disabled = false;}') %>
</p>
<% end %>
<p>
<%= label :query, :is_for_all %>
<%= check_box_tag 'query_is_for_all', 1, @query.project.nil?,
disabled: (!@query.new_record? && (@query.project.nil? || (@query.is_public? && !User.current.admin?))) %>
</p>
<p>
<%= label :query, :default_columns %>
<%= check_box_tag 'default_columns', 1, @query.has_default_columns?, id: 'query_default_columns',
onclick: 'if (this.checked) {Element.hide("columns")} else {Element.show("columns")}' %>
</p>
<p>
<%= label :query, :group_by %>
<%= select 'query', 'group_by', @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, include_blank: true %>
</p>
</div>
<fieldset>
<legend><%= l(:label_filter_plural) %></legend>
<%= render partial: 'queries/filters', locals: {query: query}%>
</fieldset>
<fieldset>
<legend><%= l(:label_sort) %></legend>
<% 3.times do |i| %>
<%= i+1 %>:
<%= label_tag "query_sort_criteria_attribute_" + i.to_s, l(:description_query_sort_criteria_attribute), class: 'hidden-for-sighted' %>
<%= select_tag("query[sort_criteria][#{i}][]", options_for_select([[]] + query.available_columns.select(&:sortable?).collect {|column| [column.caption, column.name.to_s]}, @query.sort_criteria_key(i)), id: "query_sort_criteria_attribute_#{i}")%>
<%= label_tag "query_sort_criteria_direction_" + i.to_s, l(:description_query_sort_criteria_direction), class: 'hidden-for-sighted' %>
<%= select_tag("query[sort_criteria][#{i}][]", options_for_select([[], [l(:label_ascending), 'asc'], [l(:label_descending), 'desc']], @query.sort_criteria_order(i)), id: "query_sort_criteria_direction_#{i}") %>
<br />
<% end %>
</fieldset>
<%= content_tag 'fieldset', id: 'columns', style: (query.has_default_columns? ? 'display:none;' : nil) do %>
<legend><%= Query.human_attribute_name(:column_names) %></legend>
<%= render partial: 'queries/columns', locals: {query: query}%>
<% end %>
</div>

@ -1,35 +0,0 @@
<%#-- copyright
OpenProject is a project management system.
Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 3.
OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
Copyright (C) 2006-2013 Jean-Philippe Lang
Copyright (C) 2010-2013 the ChiliProject Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See doc/COPYRIGHT.rdoc for more details.
++#%>
<h2><%= Query.model_name.human %></h2>
<%= form_tag({:action => 'edit', :id => @query}, :onsubmit => 'selectAllOptions("selected_columns");') do %>
<%= render :partial => 'form', :locals => {:query => @query} %>
<%= submit_tag l(:button_save) %>
<% end %>

@ -1,35 +0,0 @@
<%#-- copyright
OpenProject is a project management system.
Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 3.
OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
Copyright (C) 2006-2013 Jean-Philippe Lang
Copyright (C) 2010-2013 the ChiliProject Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See doc/COPYRIGHT.rdoc for more details.
++#%>
<h2><%= l(:label_query_new) %></h2>
<%= form_tag({:action => 'new', :project_id => @query.project}, :onsubmit => 'selectAllOptions("selected_columns");') do %>
<%= render :partial => 'form', :locals => {:query => @query} %>
<%= submit_tag l(:button_save) %>
<% end %>

@ -1,255 +0,0 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require File.expand_path('../../test_helper', __FILE__)
require 'queries_controller'
# Re-raise errors caught by the controller.
class QueriesController; def rescue_action(e) raise e end; end
class QueriesControllerTest < ActionController::TestCase
fixtures :all
def setup
super
@controller = QueriesController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
User.current = nil
end
def test_get_new_project_query
@request.session[:user_id] = 2
get :new, :project_id => 1
assert_response :success
assert_template 'new'
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
:name => 'query[is_public]',
:checked => nil }
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
:name => 'query_is_for_all',
:checked => nil,
:disabled => nil }
end
def test_get_new_global_query
@request.session[:user_id] = 2
get :new
assert_response :success
assert_template 'new'
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
:name => 'query[is_public]' }
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
:name => 'query_is_for_all',
:checked => 'checked',
:disabled => nil }
end
def test_new_project_public_query
@request.session[:user_id] = 2
post :new,
:project_id => 'ecookbook',
:confirm => '1',
:default_columns => '1',
:f => ["status_id", "assigned_to_id"],
:op => {"assigned_to_id" => "=", "status_id" => "o"},
:v => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
:query => {"name" => "test_new_project_public_query", "is_public" => "1"}
q = Query.find_by_name('test_new_project_public_query')
assert_redirected_to :controller => 'work_packages', :action => 'index', :project_id => 'ecookbook', :query_id => q
assert q.is_public?
assert q.has_default_columns?
assert q.valid?
end
def test_new_project_private_query
@request.session[:user_id] = 3
post :new,
:project_id => 'ecookbook',
:confirm => '1',
:default_columns => '1',
:fields => ["status_id", "assigned_to_id"],
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
:values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
:query => {"name" => "test_new_project_private_query", "is_public" => "1"}
q = Query.find_by_name('test_new_project_private_query')
assert_redirected_to :controller => 'work_packages', :action => 'index', :project_id => 'ecookbook', :query_id => q
assert !q.is_public?
assert q.has_default_columns?
assert q.valid?
end
def test_new_global_private_query_with_custom_columns
@request.session[:user_id] = 3
post :new,
:confirm => '1',
:fields => ["status_id", "assigned_to_id"],
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
:values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
:query => {"name" => "test_new_global_private_query", "is_public" => "1"},
:c => ["", "type", "subject", "priority", "category"]
q = Query.find_by_name('test_new_global_private_query')
assert_redirected_to :controller => 'work_packages', :action => 'index', :project_id => nil, :query_id => q
assert !q.is_public?
assert !q.has_default_columns?
assert_equal [:type, :subject, :priority, :category], q.columns.collect {|c| c.name}
assert q.valid?
end
def test_new_with_sort
@request.session[:user_id] = 1
post :new,
confirm: '1',
default_columns: '1',
operators: {"status_id" => "o"},
values: {"status_id" => ["1"]},
query: {name: "test_new_with_sort",
is_public: "1",
sort_criteria: {"0" => ["due_date", "desc"], "1" => ["type", ""]}},
f: ["status_id", ""],
op: {"status_id" => "o"}
query = Query.find_by_name("test_new_with_sort")
assert_not_nil query
assert_equal [['due_date', 'desc'], ['type', 'asc']], query.sort_criteria
end
def test_get_edit_global_public_query
@request.session[:user_id] = 1
get :edit, :id => 4
assert_response :success
assert_template 'edit'
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
:name => 'query[is_public]',
:checked => 'checked' }
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
:name => 'query_is_for_all',
:checked => 'checked',
:disabled => 'disabled' }
end
def test_edit_global_public_query
@request.session[:user_id] = 1
post :edit,
:id => 4,
:confirm => '1',
:default_columns => '1',
:fields => ["status_id", "assigned_to_id"],
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
:values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
:query => {"name" => "test_edit_global_public_query", "is_public" => "1"}
assert_redirected_to :controller => 'work_packages', :action => 'index', :query_id => 4
q = Query.find_by_name('test_edit_global_public_query')
assert q.is_public?
assert q.has_default_columns?
assert q.valid?
end
def test_get_edit_global_private_query
@request.session[:user_id] = 3
get :edit, :id => 3
assert_response :success
assert_template 'edit'
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
:name => 'query[is_public]' }
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
:name => 'query_is_for_all',
:checked => 'checked',
:disabled => 'disabled' }
end
def test_edit_global_private_query
@request.session[:user_id] = 3
post :edit,
:id => 3,
:confirm => '1',
:default_columns => '1',
:fields => ["status_id", "assigned_to_id"],
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
:values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
:query => {"name" => "test_edit_global_private_query", "is_public" => "1"}
assert_redirected_to :controller => 'work_packages', :action => 'index', :query_id => 3
q = Query.find_by_name('test_edit_global_private_query')
assert !q.is_public?
assert q.has_default_columns?
assert q.valid?
end
def test_get_edit_project_private_query
@request.session[:user_id] = 3
get :edit, :id => 2
assert_response :success
assert_template 'edit'
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
:name => 'query[is_public]' }
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
:name => 'query_is_for_all',
:checked => nil,
:disabled => nil }
end
def test_get_edit_project_public_query
@request.session[:user_id] = 2
get :edit, :id => 1
assert_response :success
assert_template 'edit'
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
:name => 'query[is_public]',
:checked => 'checked'
}
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
:name => 'query_is_for_all',
:checked => nil,
:disabled => 'disabled' }
end
def test_get_edit_sort_criteria
@request.session[:user_id] = 1
get :edit, :id => 5
assert_response :success
assert_template 'edit'
assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
:child => { :tag => 'option', :attributes => { :value => 'priority',
:selected => 'selected' } }
assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
:child => { :tag => 'option', :attributes => { :value => 'desc',
:selected => 'selected' } }
end
def test_destroy
@request.session[:user_id] = 2
post :destroy, :id => 1
assert_redirected_to :controller => 'work_packages', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil
assert_nil Query.find_by_id(1)
end
end
Loading…
Cancel
Save