diff --git a/app/controllers/glossary_categories_controller.rb b/app/controllers/glossary_categories_controller.rb index 78e57d9..003b0c0 100644 --- a/app/controllers/glossary_categories_controller.rb +++ b/app/controllers/glossary_categories_controller.rb @@ -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 diff --git a/app/models/glossary_category.rb b/app/models/glossary_category.rb index 43bbade..bbc237f 100644 --- a/app/models/glossary_category.rb +++ b/app/models/glossary_category.rb @@ -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 diff --git a/app/views/glossary_categories/index.html.erb b/app/views/glossary_categories/index.html.erb index 2dc9c5d..54062b7 100644 --- a/app/views/glossary_categories/index.html.erb +++ b/app/views/glossary_categories/index.html.erb @@ -8,11 +8,12 @@ <%= render partial: 'glossary_terms/sidebar' %> -
# | <%=l :field_name %> | +|
---|---|---|
<%= category.id %> | <%= link_to category.name, [@project, category] %> | ++ <%= reorder_handle(category, url: project_glossary_category_path(@project, category)) %> + |