Skip to content
Snippets Groups Projects
Unverified Commit 132fa46a authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

close #147

parent 34868a29
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,10 @@ class Admin::Education::Program::Role::PeopleController < Admin::Education::Prog
include Admin::Reorderable
def reorder
super { |first_person| first_person.sync_program }
end
def new
breadcrumb
end
......
......@@ -3,6 +3,10 @@ class Admin::Education::Program::RolesController < Admin::Education::Program::Ap
include Admin::Reorderable
def reorder
super { |first_role| first_role.sync_program }
end
def show
breadcrumb
end
......
module Admin::Reorderable
extend ActiveSupport::Concern
included do
def reorder
ids = params[:ids] || []
first_object = model.find_by(id: ids.first)
ids.each.with_index do |id, index|
object = model.find_by(id: id)
object.update_column(:position, index + 1) unless object.nil?
end
first_object.sync_with_git if first_object&.respond_to?(:sync_with_git)
end
def model
self.class.to_s.remove('Admin::').remove('Controller').singularize.safe_constantize
def reorder
ids = params[:ids] || []
first_object = model.find_by(id: ids.first)
ids.each.with_index do |id, index|
object = model.find_by(id: id)
object.update_column(:position, index + 1) unless object.nil?
end
first_object.sync_with_git if first_object&.respond_to?(:sync_with_git)
yield first_object if block_given?
end
protected
def model
self.class.to_s.remove('Admin::').remove('Controller').singularize.safe_constantize
end
end
......@@ -34,13 +34,13 @@ class Education::Program::Role < ApplicationRecord
"#{title}"
end
def sync_program
program.sync_with_git
end
protected
def last_ordered_element
program.roles.ordered.last
end
def sync_program
program.sync_with_git
end
end
......@@ -32,13 +32,13 @@ class Education::Program::Role::Person < ApplicationRecord
person.to_s
end
def sync_program
program.sync_with_git
end
protected
def last_ordered_element
role.people.ordered.last
end
def sync_program
program.sync_with_git
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment