[phase-20]Make category index reorder

This commit is contained in:
Toru Takahashi 2018-08-14 10:15:42 +09:00 committed by TAKAHASHI,Toru
parent 9525306d13
commit 88a51b128f
4 changed files with 31 additions and 4 deletions

View File

@ -4,7 +4,7 @@ class GlossaryCategoriesController < ApplicationController
before_action :find_project_by_project_id, :authorize
def index
@categories = GlossaryCategory.where(project_id: @project.id)
@categories = GlossaryCategory.where(project_id: @project.id).sorted
end
def show
@ -28,7 +28,15 @@ class GlossaryCategoriesController < ApplicationController
def update
@category.attributes = glossary_category_params
if @category.save
redirect_to [@project, @category], notice: l(:notice_successful_update)
respond_to do |format|
format.html {
redirect_to [@project, @category],
notice: l(:notice_successful_update)
}
format.js {
head 200
}
end
end
rescue ActiveRecord::StaleObjectError
flash.now[:error] = l(:notice_locking_conflict)
@ -50,7 +58,7 @@ class GlossaryCategoriesController < ApplicationController
def glossary_category_params
params.require(:glossary_category).permit(
:name
:name, :position
)
end
end

View File

@ -1,4 +1,9 @@
class GlossaryCategory < ActiveRecord::Base
has_many :terms, class_name: 'GlossaryTerm', foreign_key: 'category_id'
belongs_to :project
acts_as_positioned
scope :sorted, lambda { order(:position) }
end

View File

@ -8,11 +8,12 @@
<%= render partial: 'glossary_terms/sidebar' %>
<table class="list">
<table class="list table-sortable">
<thead>
<tr>
<th>#</th>
<th><%=l :field_name %></th>
<th/>
</tr>
</thead>
<tbody>
@ -20,7 +21,14 @@
<tr>
<td class="id"><%= category.id %></td>
<td class="name"><%= link_to category.name, [@project, category] %></td>
<td class="buttons">
<%= reorder_handle(category, url: project_glossary_category_path(@project, category)) %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= javascript_tag do %>
$(function() { $("table.table-sortable tbody").positionedItems(); });
<% end %>

View File

@ -0,0 +1,6 @@
class AddPositionToGlossaryCategories < ActiveRecord::Migration[5.2]
def change
add_column :glossary_categories, :position, :integer, default: nil
end
end