プロジェクト

全般

プロフィール

« | » 

リビジョン 88a51b12

高徹 高橋 徹 さんが約6年前に追加

[phase-20]Make category index reorder

差分を表示:

app/controllers/glossary_categories_controller.rb
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
......
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)
......
def glossary_category_params
params.require(:glossary_category).permit(
:name
:name, :position
)
end
end
app/models/glossary_category.rb
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
app/views/glossary_categories/index.html.erb
<%= 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>
......
<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 %>
db/migrate/006_add_position_to_glossary_categories.rb
class AddPositionToGlossaryCategories < ActiveRecord::Migration[5.2]
def change
add_column :glossary_categories, :position, :integer, default: nil
end
end

他の形式にエクスポート: Unified diff