[phase-20]Make category index reorder
This commit is contained in:
parent
9525306d13
commit
88a51b128f
@ -4,7 +4,7 @@ class GlossaryCategoriesController < ApplicationController
|
|||||||
before_action :find_project_by_project_id, :authorize
|
before_action :find_project_by_project_id, :authorize
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@categories = GlossaryCategory.where(project_id: @project.id)
|
@categories = GlossaryCategory.where(project_id: @project.id).sorted
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@ -28,7 +28,15 @@ class GlossaryCategoriesController < ApplicationController
|
|||||||
def update
|
def update
|
||||||
@category.attributes = glossary_category_params
|
@category.attributes = glossary_category_params
|
||||||
if @category.save
|
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
|
end
|
||||||
rescue ActiveRecord::StaleObjectError
|
rescue ActiveRecord::StaleObjectError
|
||||||
flash.now[:error] = l(:notice_locking_conflict)
|
flash.now[:error] = l(:notice_locking_conflict)
|
||||||
@ -50,7 +58,7 @@ class GlossaryCategoriesController < ApplicationController
|
|||||||
|
|
||||||
def glossary_category_params
|
def glossary_category_params
|
||||||
params.require(:glossary_category).permit(
|
params.require(:glossary_category).permit(
|
||||||
:name
|
:name, :position
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
class GlossaryCategory < ActiveRecord::Base
|
class GlossaryCategory < ActiveRecord::Base
|
||||||
has_many :terms, class_name: 'GlossaryTerm', foreign_key: 'category_id'
|
has_many :terms, class_name: 'GlossaryTerm', foreign_key: 'category_id'
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
|
||||||
|
acts_as_positioned
|
||||||
|
|
||||||
|
scope :sorted, lambda { order(:position) }
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -8,11 +8,12 @@
|
|||||||
|
|
||||||
<%= render partial: 'glossary_terms/sidebar' %>
|
<%= render partial: 'glossary_terms/sidebar' %>
|
||||||
|
|
||||||
<table class="list">
|
<table class="list table-sortable">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th><%=l :field_name %></th>
|
<th><%=l :field_name %></th>
|
||||||
|
<th/>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -20,7 +21,14 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="id"><%= category.id %></td>
|
<td class="id"><%= category.id %></td>
|
||||||
<td class="name"><%= link_to category.name, [@project, category] %></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>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<%= javascript_tag do %>
|
||||||
|
$(function() { $("table.table-sortable tbody").positionedItems(); });
|
||||||
|
<% end %>
|
||||||
|
6
db/migrate/006_add_position_to_glossary_categories.rb
Normal file
6
db/migrate/006_add_position_to_glossary_categories.rb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class AddPositionToGlossaryCategories < ActiveRecord::Migration[5.2]
|
||||||
|
|
||||||
|
def change
|
||||||
|
add_column :glossary_categories, :position, :integer, default: nil
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user