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

teacher

parent 5e1b2bac
No related branches found
No related tags found
No related merge requests found
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
<%= 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>
......
<% 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>
......
<% content_for :title, @teacher %>
<% content_for :title, @involvement %>
<%= render 'form', teacher: @teacher %>
<%= render 'form', involvement: @involvement %>
<% 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 %>
......@@ -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>
......
......@@ -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">
......
......@@ -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
......
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