Commit bc4c202d authored by jplang's avatar jplang

Enable filtering versions on Project -> Settings -> Versions (#22608).

git-svn-id: https://svn.redmine.org/redmine/trunk@15759 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 1265bf5c
......@@ -155,6 +155,10 @@ class ProjectsController < ApplicationController
@issue_category ||= IssueCategory.new
@member ||= @project.members.new
@trackers = Tracker.sorted.to_a
@version_status = params[:version_status] || 'open'
@version_name = params[:version_name]
@versions = @project.shared_versions.status(@version_status).like(@version_name)
@wiki ||= @project.wiki || Wiki.new(:project => @project)
end
......
......@@ -22,7 +22,8 @@ module ProjectsHelper
tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
{:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
{:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
{:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
{:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural,
:url => {:tab => 'versions', :version_status => params[:version_status], :version_name => params[:version_name]}},
{:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
{:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
{:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural},
......
......@@ -41,7 +41,18 @@ class Version < ActiveRecord::Base
attr_protected :id
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
scope :like, lambda {|arg|
if arg.present?
pattern = "%#{arg.to_s.strip}%"
where("LOWER(#{Version.table_name}.name) LIKE :p", :p => pattern)
end
}
scope :open, lambda { where(:status => 'open') }
scope :status, lambda {|status|
if status.present?
where(:status => status.to_s)
end
}
scope :visible, lambda {|*args|
joins(:project).
where(Project.allowed_to_condition(args.first || User.current, :view_issues))
......
<div class="tabs">
<ul>
<% tabs.each do |tab| -%>
<li><%= link_to l(tab[:label]), { :tab => tab[:name] },
<li><%= link_to l(tab[:label]), (tab[:url] || { :tab => tab[:name] }),
:id => "tab-#{tab[:name]}",
:class => (tab[:name] != selected_tab ? nil : 'selected'),
:onclick => "showTab('#{tab[:name]}', this.href); this.blur(); return false;" %></li>
......
<% if @project.shared_versions.any? %>
<%= form_tag(settings_project_path(@project, :tab => 'versions'), :method => :get) do %>
<fieldset><legend><%= l(:label_filter_plural) %></legend>
<label for='status'><%= l(:field_status) %> :</label>
<%= select_tag 'version_status', options_for_select([[l(:label_all), '']] + Version::VERSION_STATUSES.collect {|s| [l("version_status_#{s}"), s]}, @version_status), :onchange => "this.form.submit(); return false;" %>
<label for='name'><%= l(:label_version) %>:</label>
<%= text_field_tag 'version_name', @version_name, :size => 30 %>
<%= submit_tag l(:button_apply), :name => nil %>
<%= link_to l(:button_clear), settings_project_path(@project, :tab => 'versions'), :class => 'icon icon-reload' %>
</fieldset>
<% end %>
<% if @versions.present? %>
<table class="list versions">
<thead><tr>
<th><%= l(:label_version) %></th>
......@@ -10,7 +21,7 @@
<th style="width:15%"></th>
</tr></thead>
<tbody>
<% for version in @project.shared_versions.sort %>
<% @versions.sort.each do |version| %>
<tr class="version <%= cycle 'odd', 'even' %> <%=h version.status %> <%= 'shared' if version.project != @project %>">
<td class="name"><%= link_to_version version %></td>
<td class="date"><%= format_date(version.effective_date) %></td>
......@@ -33,7 +44,7 @@
<% end %>
<div class="contextual">
<% if @project.versions.any? %>
<% if @versions.any? %>
<%= link_to l(:label_close_versions), close_completed_project_versions_path(@project), :method => :put %>
<% end %>
</div>
......
......@@ -491,6 +491,36 @@ class ProjectsControllerTest < Redmine::ControllerTest
end
end
def test_settings_should_accept_version_status_filter
@request.session[:user_id] = 2
get :settings, :id => 'ecookbook', :tab => 'versions', :version_status => 'locked'
assert_response :success
assert_select 'select[name=version_status]' do
assert_select 'option[value=locked][selected=selected]'
end
assert_select 'table.versions tbody' do
assert_select 'tr', 1
assert_select 'td.name', :text => '1.0'
end
assert_select 'a#tab-versions[href=?]', '/projects/ecookbook/settings/versions?version_status=locked'
end
def test_settings_should_accept_version_name_filter
@request.session[:user_id] = 2
get :settings, :id => 'ecookbook', :tab => 'versions', :version_status => '', :version_name => '.1'
assert_response :success
assert_select 'input[name=version_name][value=?]', '.1'
assert_select 'table.versions tbody' do
assert_select 'tr', 1
assert_select 'td.name', :text => '0.1'
end
assert_select 'a#tab-versions[href=?]', '/projects/ecookbook/settings/versions?version_name=.1&version_status='
end
def test_update
@request.session[:user_id] = 2 # manager
post :update, :id => 1, :project => {:name => 'Test changed name',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment