Patch #34426 » issue_categories_sortable.diff
| app/controllers/issue_categories_controller.rb (working copy) | ||
|---|---|---|
|
def index
|
||
|
respond_to do |format|
|
||
|
format.html {redirect_to_settings_in_projects}
|
||
|
format.api {@categories = @project.issue_categories.to_a}
|
||
|
format.api {@categories = @project.issue_categories.sorted.to_a}
|
||
|
end
|
||
|
end
|
||
| ... | ... | |
|
flash[:notice] = l(:notice_successful_update)
|
||
|
redirect_to_settings_in_projects
|
||
|
end
|
||
|
format.js {head 200}
|
||
|
format.api {render_api_ok}
|
||
|
end
|
||
|
else
|
||
|
respond_to do |format|
|
||
|
format.html {render :action => 'edit'}
|
||
|
format.api {render_validation_errors(@category)}
|
||
|
format.js {head 422}
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| app/models/issue_category.rb (working copy) | ||
|---|---|---|
|
belongs_to :project
|
||
|
belongs_to :assigned_to, :class_name => 'Principal'
|
||
|
has_many :issues, :foreign_key => 'category_id', :dependent => :nullify
|
||
|
acts_as_positioned
|
||
|
validates_presence_of :name
|
||
|
validates_uniqueness_of :name, :scope => [:project_id]
|
||
|
validates_length_of :name, :maximum => 60
|
||
|
safe_attributes 'name', 'assigned_to_id'
|
||
|
safe_attributes 'name', 'assigned_to_id', 'position'
|
||
|
scope :sorted, lambda {order(:position)}
|
||
|
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
|
||
|
alias :destroy_without_reassign :destroy
|
||
| ... | ... | |
|
end
|
||
|
def <=>(category)
|
||
|
name <=> category.name
|
||
|
position <=> category.position
|
||
|
end
|
||
|
def to_s; name end
|
||
| app/models/project.rb (working copy) | ||
|---|---|---|
|
has_many :queries, :dependent => :delete_all
|
||
|
has_many :documents, :dependent => :destroy
|
||
|
has_many :news, lambda {includes(:author)}, :dependent => :destroy
|
||
|
has_many :issue_categories, lambda {order(:name)}, :dependent => :delete_all
|
||
|
has_many :issue_categories, lambda {order(:position)}, :dependent => :delete_all
|
||
|
has_many :boards, lambda {order(:position)}, :inverse_of => :project, :dependent => :destroy
|
||
|
has_one :repository, lambda {where(:is_default => true)}
|
||
|
has_many :repositories, :dependent => :destroy
|
||
| app/views/projects/settings/_issue_categories.html.erb (working copy) | ||
|---|---|---|
|
<p><%= link_to l(:label_issue_category_new), new_project_issue_category_path(@project), :class => 'icon icon-add' if User.current.allowed_to?(:manage_categories, @project) %></p>
|
||
|
<% if @project.issue_categories.any? %>
|
||
|
<table class="list">
|
||
|
<table class="list issue_categories">
|
||
|
<thead><tr>
|
||
|
<th><%= l(:label_issue_category) %></th>
|
||
|
<th><%= l(:field_assigned_to) %></th>
|
||
| ... | ... | |
|
<td><%= category.assigned_to.name if category.assigned_to %></td>
|
||
|
<td class="buttons">
|
||
|
<% if User.current.allowed_to?(:manage_categories, @project) %>
|
||
|
<%= reorder_handle category %>
|
||
|
<%= link_to l(:button_edit), edit_issue_category_path(category), :class => 'icon icon-edit' %>
|
||
|
<%= delete_link issue_category_path(category) %>
|
||
|
<% end %>
|
||
| ... | ... | |
|
<% else %>
|
||
|
<p class="nodata"><%= l(:label_no_data) %></p>
|
||
|
<% end %>
|
||
|
<%= javascript_tag do %>
|
||
|
$(function() { $("table.issue_categories tbody").positionedItems(); });
|
||
|
<% end %>
|
||
| config/routes.rb (working copy) | ||
|---|---|---|
|
end
|
||
|
member do
|
||
|
get 'settings(/:tab)', :action => 'settings', :as => 'settings'
|
||
|
match 'settings(/:tab)', action: 'settings', as: 'settings', via: [:get, :put]
|
||
|
post 'archive'
|
||
|
post 'unarchive'
|
||
|
post 'close'
|
||
| db/migrate/20201209122301_add_issue_category_position.rb (working copy) | ||
|---|---|---|
|
class AddIssueCategoryPosition < ActiveRecord::Migration[5.2]
|
||
|
def self.up
|
||
|
add_column :issue_categories, :position, :integer, default: 1
|
||
|
IssueCategory.all.each_with_index { |category, i| category.update_attribute(:position, i + 1) }
|
||
|
end
|
||
|
def self.down
|
||
|
remove_column :issue_categories, :position
|
||
|
end
|
||
|
end
|
||
| test/fixtures/issue_categories.yml (working copy) | ||
|---|---|---|
|
name: Printing
|
||
|
project_id: 1
|
||
|
assigned_to_id: 2
|
||
|
position: 1
|
||
|
id: 1
|
||
|
issue_categories_002:
|
||
|
name: Recipes
|
||
|
project_id: 1
|
||
|
assigned_to_id:
|
||
|
assigned_to_id:
|
||
|
position: 2
|
||
|
id: 2
|
||
|
issue_categories_003:
|
||
|
name: Stock management
|
||
|
project_id: 2
|
||
|
assigned_to_id:
|
||
|
assigned_to_id:
|
||
|
position: 3
|
||
|
id: 3
|
||
|
issue_categories_004:
|
||
|
name: Printing
|
||
|
project_id: 2
|
||
|
assigned_to_id:
|
||
|
assigned_to_id:
|
||
|
position: 4
|
||
|
id: 4
|
||
| test/functional/issue_categories_controller_test.rb (working copy) | ||
|---|---|---|
|
:params => {
|
||
|
:id => 2,
|
||
|
:issue_category => {
|
||
|
:name => 'Testing'
|
||
|
:name => 'Testing',
|
||
|
:position => 3
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
end
|
||
|
assert_redirected_to '/projects/ecookbook/settings/categories'
|
||
|
assert_equal 'Testing', IssueCategory.find(2).name
|
||
|
issue_category = IssueCategory.find(2)
|
||
|
assert_equal 'Testing', issue_category.name
|
||
|
assert_equal 3, issue_category.position
|
||
|
end
|
||
|
def test_update_failure
|
||
| test/unit/issue_category_test.rb (working copy) | ||
|---|---|---|
|
assert IssueCategory.new(:project_id => 2, :name => 'New category').save
|
||
|
category = IssueCategory.order('id DESC').first
|
||
|
assert_equal 'New category', category.name
|
||
|
assert_equal 1, category.position
|
||
|
end
|
||
|
def test_create_with_group_assignment
|
||