diff --git a/app/controllers/admin/education/program/teachers_controller.rb b/app/controllers/admin/education/program/teachers_controller.rb index 52d7085d53b763e28311db97fbfe040db9a152cc..c26bde871c0849f7f36c31df03eea74df56d61c4 100644 --- a/app/controllers/admin/education/program/teachers_controller.rb +++ b/app/controllers/admin/education/program/teachers_controller.rb @@ -1,7 +1,11 @@ class Admin::Education::Program::TeachersController < Admin::Education::Program::ApplicationController - load_and_authorize_resource class: Education::Program::Teacher, through: :program + load_and_authorize_resource :involvement, + class: University::Person::Involvement, + through: :program, + through_association: :university_person_involvements, + parent: false - before_action :get_teachers, except: :destroy + before_action :get_available_people, except: :destroy def new breadcrumb @@ -13,8 +17,8 @@ class Admin::Education::Program::TeachersController < Admin::Education::Program: end def create - if @teacher.save - redirect_to admin_education_program_path(@program), notice: t('admin.successfully_created_html', model: @teacher.to_s) + if @involvement.save + redirect_to admin_education_program_path(@program), notice: t('admin.successfully_created_html', model: @involvement.to_s) else breadcrumb render :new, status: :unprocessable_entity @@ -22,8 +26,8 @@ class Admin::Education::Program::TeachersController < Admin::Education::Program: end def update - if @teacher.update(teacher_params) - redirect_to admin_education_program_path(@program), notice: t('admin.successfully_updated_html', model: @teacher.to_s) + if @involvement.update(involvement_params) + redirect_to admin_education_program_path(@program), notice: t('admin.successfully_updated_html', model: @involvement.to_s) else breadcrumb render :edit, status: :unprocessable_entity @@ -32,26 +36,29 @@ class Admin::Education::Program::TeachersController < Admin::Education::Program: end def destroy - @teacher.destroy - redirect_to admin_education_program_path(@program), notice: t('admin.successfully_destroyed_html', model: @teacher.to_s) + @involvement.destroy + redirect_to admin_education_program_path(@program), notice: t('admin.successfully_destroyed_html', model: @involvement.to_s) end protected - def get_teachers - used_teacher_ids = @program.teachers.where.not(id: @teacher.id).pluck(:person_id) - @teachers = current_university.people.teachers.where.not(id: used_teacher_ids).accessible_by(current_ability).ordered + def get_available_people + used_person_ids = @program.university_person_involvements.where.not(id: @involvement.id).pluck(:person_id) + @available_people = current_university.people.teachers.where.not(id: used_person_ids).accessible_by(current_ability).ordered end def breadcrumb super - add_breadcrumb Education::Program::Teacher.model_name.human(count: 2) - breadcrumb_for @teacher + add_breadcrumb Education::Program.human_attribute_name("teachers") + if @involvement + @involvement.persisted? ? add_breadcrumb(@involvement) + : add_breadcrumb(t('create')) + end end - def teacher_params - params.require(:education_program_teacher) - .permit(:description, :person_id) - .merge(program_id: @program.id) + def involvement_params + params.require(:university_person_involvement) + .permit(:description, :position, :person_id) + .merge(university_id: @program.university_id, kind: :teacher) end end diff --git a/app/views/admin/education/program/teachers/_form.html.erb b/app/views/admin/education/program/teachers/_form.html.erb index 31950531cded62732c883007d24af5dd0f8a7685..b77505dfdb3e19597b8ccde8c8765dfaa5c4278a 100644 --- a/app/views/admin/education/program/teachers/_form.html.erb +++ b/app/views/admin/education/program/teachers/_form.html.erb @@ -1,4 +1,6 @@ -<%= simple_form_for [:admin, teacher] do |f| %> +<%= simple_form_for [:admin, involvement], + url: involvement.new_record? ? admin_education_program_teachers_path(@program) + : admin_education_program_teacher_path(involvement, { program_id: @program.id }) do |f| %> <div class="card flex-fill w-100"> <div class="card-header"> <h5 class="card-title mb-0"><%= t('admin.infos') %></h5> @@ -6,10 +8,10 @@ <div class="card-body"> <div class="row"> <div class="col-md-6"> - <%= f.association :person, collection: @teachers %> + <%= f.association :person, collection: @available_people %> </div> <div class="col-md-6"> - <%= f.input :description, as: :string %> + <%= f.input :description %> </div> </div> </div> diff --git a/app/views/admin/education/program/teachers/_list.html.erb b/app/views/admin/education/program/teachers/_list.html.erb index cc7d9c17b4e0f0bd685a4fc0525771250f30610f..638b44be03ac9918ce1ef83ffa028ca3af6452e1 100644 --- a/app/views/admin/education/program/teachers/_list.html.erb +++ b/app/views/admin/education/program/teachers/_list.html.erb @@ -1,31 +1,29 @@ -<% if teachers.any? %> - <table class="table"> +<% if involvements.any? %> + <table class="table table-sortable"> <thead> <tr> - <th class="ps-0"><%= Education::Program::Teacher.model_name.human %></th> - <th><%= Education::Program::Teacher.human_attribute_name('description') %></th> + <th class="ps-0"><%= University::Person.model_name.human %></th> + <th><%= University::Person::Involvement.human_attribute_name('description') %></th> <th></th> </tr> </thead> - <tbody> - <% teachers.each do |teacher| %> - <tr> + <tbody data-reorder-url="<%= reorder_admin_education_program_teachers_path(@program) %>"> + <% involvements.each do |involvement| %> + <tr class="handle" data-id="<%= involvement.id %>"> <td class="ps-0"> - <%= link_to_if can?(:read, teacher.person), - teacher.person, - admin_education_teacher_path(teacher.person) %> + <%= involvement %> </td> - <td><%= teacher.description %></td> + <td><%= involvement.description %></td> <td class="text-end pe-0"> <div class="btn-group" role="group"> <%= link_to t('edit'), - edit_admin_education_program_teacher_path(teacher, { program_id: @program.id }), - class: button_classes if can? :update, teacher.person %> + edit_admin_education_program_teacher_path(involvement, { program_id: @program.id }), + class: button_classes if can?(:edit, involvement) %> <%= link_to t('delete'), - admin_education_program_teacher_path(teacher, { program_id: @program.id }), + admin_education_program_teacher_path(involvement, { program_id: @program.id }), method: :delete, data: { confirm: t('please_confirm') }, - class: button_classes_danger if can? :update, teacher.person %> + class: button_classes_danger if can?(:destroy, involvement) %> </div> </td> </tr> diff --git a/app/views/admin/education/program/teachers/edit.html.erb b/app/views/admin/education/program/teachers/edit.html.erb index b3f94ca300bb5361d5c000f96b377bd2bd76eb0e..da924cd052e14cfa55c1f75b9fe56ee8d15a1b8a 100644 --- a/app/views/admin/education/program/teachers/edit.html.erb +++ b/app/views/admin/education/program/teachers/edit.html.erb @@ -1,3 +1,3 @@ -<% content_for :title, @teacher %> +<% content_for :title, @involvement %> -<%= render 'form', teacher: @teacher %> +<%= render 'form', involvement: @involvement %> diff --git a/app/views/admin/education/program/teachers/new.html.erb b/app/views/admin/education/program/teachers/new.html.erb index 1617fb343abe20477a921b1b7488d6ffaf546fa9..f07ff39c18ffb7d9e598688bb41a9361413d804f 100644 --- a/app/views/admin/education/program/teachers/new.html.erb +++ b/app/views/admin/education/program/teachers/new.html.erb @@ -1,3 +1,3 @@ -<% content_for :title, Education::Program::Teacher.model_name.human %> +<% content_for :title, University::Person.model_name.human %> -<%= render 'form', teacher: @teacher %> +<%= render 'form', involvement: @involvement %> diff --git a/app/views/admin/education/programs/show.html.erb b/app/views/admin/education/programs/show.html.erb index 5ce85ad22f01d35d6604ae27fb17d2514f91a25e..db915b04c970faa8de06d201a70476efe0df2ea2 100644 --- a/app/views/admin/education/programs/show.html.erb +++ b/app/views/admin/education/programs/show.html.erb @@ -127,7 +127,7 @@ </div> <div class="col-md-6"> <h3 class="h5"><%= Education::Program.human_attribute_name('teachers') %></h3> - <%= render 'admin/education/program/teachers/list', teachers: @program.teachers.includes(:person).ordered %> + <%= render 'admin/education/program/teachers/list', involvements: @program.university_person_involvements.includes(:person).ordered %> <%= link_to t('create'), new_admin_education_program_teacher_path(program_id: @program.id), class: button_classes %> </div> </div> diff --git a/app/views/admin/education/school/role/people/_form.html.erb b/app/views/admin/education/school/role/people/_form.html.erb index 2f982edebf0199f1ef808da874aa1cd98b28f52f..3b50a16f7f6524e37f0b0a27fe0ec25eed08fa9c 100644 --- a/app/views/admin/education/school/role/people/_form.html.erb +++ b/app/views/admin/education/school/role/people/_form.html.erb @@ -8,7 +8,6 @@ <div class="card-body"> <div class="row"> <div class="col-md-6"> - <% used_person_ids = @role.involvements.where.not(id: involvement.id).pluck(:person_id) %> <%= f.association :person, collection: @available_people %> </div> <div class="col-md-6"> diff --git a/config/routes/admin/education.rb b/config/routes/admin/education.rb index 59bfe51701f93b22bc3cd1fecaa00d554deb6f65..6dc84694f12edeccd03350568dfdf00dd07c3b35 100644 --- a/config/routes/admin/education.rb +++ b/config/routes/admin/education.rb @@ -25,7 +25,11 @@ namespace :education do post :reorder end end - resources :teachers, controller: 'program/teachers', except: [:index, :show] + resources :teachers, controller: 'program/teachers', except: [:index, :show] do + collection do + post :reorder + end + end collection do post :reorder end