Skip to content
Snippets Groups Projects
Commit 544eebd1 authored by pabois's avatar pabois
Browse files

wip teachers

parent 199c450b
No related branches found
No related tags found
No related merge requests found
Showing
with 96 additions and 165 deletions
class Admin::Education::TeachersController < Admin::Education::ApplicationController class Admin::Education::TeachersController < Admin::Education::ApplicationController
load_and_authorize_resource class: Education::Teacher, before_action :get_teacher, except: :index
through: :current_university,
through_association: :education_teachers
def index def index
@teachers = @teachers.ordered.page(params[:page]) @teachers = current_university.members.teachers.accessible_by(current_ability).ordered.page(params[:page])
breadcrumb breadcrumb
end end
def show def show
breadcrumb breadcrumb
end @programs = @teacher.education_programs.ordered.page(params[:page])
def publish
@teacher.force_publish!
redirect_to admin_education_teacher_path(@teacher), notice: t('admin.will_be_published_html', model: @teacher.to_s)
end
def new
breadcrumb
end end
def edit def edit
...@@ -26,15 +16,6 @@ class Admin::Education::TeachersController < Admin::Education::ApplicationContro ...@@ -26,15 +16,6 @@ class Admin::Education::TeachersController < Admin::Education::ApplicationContro
add_breadcrumb t('edit') add_breadcrumb t('edit')
end end
def create
if @teacher.save
redirect_to admin_education_teacher_path(@teacher), notice: t('admin.successfully_created_html', model: @teacher.to_s)
else
breadcrumb
render :new, status: :unprocessable_entity
end
end
def update def update
if @teacher.update(teacher_params) if @teacher.update(teacher_params)
redirect_to admin_education_teacher_path(@teacher), notice: t('admin.successfully_updated_html', model: @teacher.to_s) redirect_to admin_education_teacher_path(@teacher), notice: t('admin.successfully_updated_html', model: @teacher.to_s)
...@@ -45,13 +26,12 @@ class Admin::Education::TeachersController < Admin::Education::ApplicationContro ...@@ -45,13 +26,12 @@ class Admin::Education::TeachersController < Admin::Education::ApplicationContro
end end
end end
def destroy
@teacher.destroy
redirect_to admin_education_teachers_url, notice: t('admin.successfully_destroyed_html', model: @teacher.to_s)
end
protected protected
def get_teacher
@teacher = current_university.members.teachers.accessible_by(current_ability).find(params[:id])
end
def breadcrumb def breadcrumb
super super
add_breadcrumb Education::Teacher.model_name.human(count: 2), add_breadcrumb Education::Teacher.model_name.human(count: 2),
...@@ -60,8 +40,7 @@ class Admin::Education::TeachersController < Admin::Education::ApplicationContro ...@@ -60,8 +40,7 @@ class Admin::Education::TeachersController < Admin::Education::ApplicationContro
end end
def teacher_params def teacher_params
params.require(:education_teacher) params.require(:administration_member)
.permit(:first_name, :last_name, :biography, :slug, :user_id) .permit(education_program_ids: [])
.merge(university_id: current_university.id)
end end
end end
...@@ -46,6 +46,12 @@ class Administration::Member < ApplicationRecord ...@@ -46,6 +46,12 @@ class Administration::Member < ApplicationRecord
join_table: :research_journal_articles_researchers, join_table: :research_journal_articles_researchers,
foreign_key: :researcher_id foreign_key: :researcher_id
has_and_belongs_to_many :education_programs,
class_name: 'Education::Program',
join_table: :education_programs_teachers,
foreign_key: :education_teacher_id,
association_foreign_key: :education_program_id
validates_presence_of :first_name, :last_name validates_presence_of :first_name, :last_name
validates_uniqueness_of :email, scope: :university_id, allow_blank: true, if: :will_save_change_to_email? validates_uniqueness_of :email, scope: :university_id, allow_blank: true, if: :will_save_change_to_email?
validates_format_of :email, with: Devise::email_regexp, allow_blank: true, if: :will_save_change_to_email? validates_format_of :email, with: Devise::email_regexp, allow_blank: true, if: :will_save_change_to_email?
......
...@@ -58,7 +58,7 @@ class Education::Program < ApplicationRecord ...@@ -58,7 +58,7 @@ class Education::Program < ApplicationRecord
foreign_key: 'education_program_id', foreign_key: 'education_program_id',
association_foreign_key: 'education_school_id' association_foreign_key: 'education_school_id'
has_and_belongs_to_many :teachers, has_and_belongs_to_many :teachers,
class_name: 'Education::Teacher', class_name: 'Administration::Member',
join_table: 'education_programs_teachers', join_table: 'education_programs_teachers',
foreign_key: 'education_program_id', foreign_key: 'education_program_id',
association_foreign_key: 'education_teacher_id' association_foreign_key: 'education_teacher_id'
......
...@@ -2,7 +2,6 @@ module University::WithEducation ...@@ -2,7 +2,6 @@ module University::WithEducation
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
has_many :education_teachers, class_name: 'Education::Teacher', dependent: :destroy
has_many :education_programs, class_name: 'Education::Program', dependent: :destroy has_many :education_programs, class_name: 'Education::Program', dependent: :destroy
has_many :education_schools, class_name: 'Education::School', dependent: :destroy has_many :education_schools, class_name: 'Education::School', dependent: :destroy
......
...@@ -2,7 +2,6 @@ module University::WithResearch ...@@ -2,7 +2,6 @@ module University::WithResearch
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
has_many :research_researchers, class_name: 'Research::Researcher', dependent: :destroy
has_many :research_journals, class_name: 'Research::Journal', dependent: :destroy has_many :research_journals, class_name: 'Research::Journal', dependent: :destroy
end end
end end
...@@ -5,6 +5,14 @@ ...@@ -5,6 +5,14 @@
<h2 class="card-title mb-0 h5"><%= t('content') %></h2> <h2 class="card-title mb-0 h5"><%= t('content') %></h2>
</div> </div>
<div class="card-body"> <div class="card-body">
<% unless member.email.blank? %>
<h3 class="h5"><%= Administration::Member.human_attribute_name('email') %></h3>
<p><%= link_to member.email, "mailto:#{member.email}", target: '_blank' %></p>
<% end %>
<% unless member.phone.blank? %>
<h3 class="h5"><%= Administration::Member.human_attribute_name('phone') %></h3>
<p><%= link_to member.phone, "tel:#{member.phone}", target: '_blank' %></p>
<% end %>
<h3 class="h5"><%= Administration::Member.human_attribute_name('biography') %></h3> <h3 class="h5"><%= Administration::Member.human_attribute_name('biography') %></h3>
<%= member.biography %> <%= member.biography %>
</div> </div>
......
<% content_for :title, @member %> <% content_for :title, @member %>
<div class="row"> <%= render 'main_infos', member: @member %>
<div class="col-md-8">
<div class="card flex-fill w-100">
<div class="card-header">
<h2 class="card-title mb-0 h5"><%= t('metadata') %></h2>
</div>
<div class="card-body">
<% unless @member.email.blank? %>
<h3 class="h5"><%= Administration::Member.human_attribute_name('email') %></h3>
<p><%= link_to @member.email, "mailto:#{@member.email}", target: '_blank' %></p>
<% end %>
<% unless @member.phone.blank? %>
<h3 class="h5"><%= Administration::Member.human_attribute_name('phone') %></h3>
<p><%= link_to @member.phone, "tel:#{@member.phone}", target: '_blank' %></p>
<% end %>
<h3 class="h5"><%= Administration::Member.human_attribute_name('biography') %></h3>
<p><%= @member.biography %></p>
<h3 class="h5"><%= Administration::Member.human_attribute_name('slug') %></h3>
<p><%= @member.slug %></p>
<% if @member.user %>
<h3 class="h5"><%= Administration::Member.human_attribute_name('user') %></h3>
<p><%= link_to_if can?(:read, @member.user), @member.user, admin_user_path(@member.user) %></p>
<% end %>
</div>
</div>
</div>
</div>
<% content_for :action_bar_right do %> <% content_for :action_bar_right do %>
<%= edit_link @member %> <%= edit_link @member %>
......
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<%= f.input :evaluation, as: :rich_text_area %> <%= f.input :evaluation, as: :rich_text_area %>
<%= f.association :teachers, <%= f.association :teachers,
as: :check_boxes, as: :check_boxes,
collection: current_university.education_teachers.ordered %> collection: current_university.members.teachers.ordered %>
</div> </div>
</div> </div>
</div> </div>
......
<table class="table">
<thead>
<tr>
<th><%= Education::Program.model_name.human %></th>
<th></th>
</tr>
</thead>
<tbody>
<% programs.each do |program| %>
<tr>
<td><%= link_to_if can?(:read, program), program, [:admin, program] %></td>
<td class="text-end">
<div class="btn-group" role="group">
<%= link_to t('edit'),
edit_admin_education_program_path(program),
class: button_classes %>
<%= link_to t('delete'),
admin_research_journal_article_path(program),
method: :delete,
data: { confirm: t('please-confirm') },
class: button_classes_danger %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
<h3 class="h5 <%= 'mt-4' if i > 0 %>"><%= Education::Program.human_attribute_name('teachers') %></h3> <h3 class="h5 <%= 'mt-4' if i > 0 %>"><%= Education::Program.human_attribute_name('teachers') %></h3>
<ul class="list-unstyled"> <ul class="list-unstyled">
<% @program.teachers.ordered.each do |teacher| %> <% @program.teachers.ordered.each do |teacher| %>
<li><%= link_to_if can?(:read, teacher), teacher, [:admin, teacher] %></li> <li><%= link_to_if can?(:read, teacher), teacher, admin_education_teacher_path(teacher) %></li>
<% end %> <% end %>
</ul> </ul>
<% end %> <% end %>
...@@ -83,10 +83,6 @@ ...@@ -83,10 +83,6 @@
</div> </div>
</div> </div>
<% content_for :action_bar_right do %> <% content_for :action_bar_right do %>
<%= edit_link @program %> <%= edit_link @program %>
<% end %> <% end %>
<%= simple_form_for [:admin, teacher] do |f| %> <%= simple_form_for teacher, url: admin_education_teacher_path(teacher) do |f| %>
<div class="row"> <div class="card flex-fill w-100">
<div class="col-md-6"> <div class="card-header">
<div class="card flex-fill w-100"> <h5 class="card-title mb-0"><%= Education::Program.model_name.human(count: 2) %></h5>
<div class="card-header">
<h5 class="card-title mb-0"><%= t('metadata') %></h5>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<%= f.input :first_name %>
</div>
<div class="col-md-6">
<%= f.input :last_name %>
</div>
</div>
<div class="row">
<div class="col-md-6">
<%= f.input :slug,
as: :string,
input_html: teacher.persisted? ? {} : {
class: 'js-slug-input',
data: { source: '#education_teacher_first_name, #education_teacher_last_name' }
} %>
</div>
<div class="col-md-6">
<%= f.association :user, collection: current_university.users.ordered %>
</div>
</div>
<%= f.input :biography, as: :rich_text_area %>
</div>
</div>
</div> </div>
<div class="col-md-6"> <div class="card-body">
<div class="card flex-fill w-100"> <%= f.association :education_programs,
<div class="card-header"> as: :check_boxes,
<h5 class="card-title mb-0"><%= Education::Program.model_name.human(count: 2) %></h5> legend_tag: false,
</div> collection: current_university.list_of_programs,
<div class="card-body"> label_method: ->(p) { sanitize p[:label] },
<%= f.association :programs, value_method: ->(p) { p[:id] } %>
as: :check_boxes,
collection: current_university.list_of_programs,
label_method: ->(p) { sanitize p[:label] },
value_method: ->(p) { p[:id] } %>
<ul>
</ul>
</div>
</div>
</div> </div>
</div> </div>
<% content_for :action_bar_right do %> <% content_for :action_bar_right do %>
<%= submit f %> <%= submit f %>
<% end %> <% end %>
......
...@@ -14,11 +14,6 @@ ...@@ -14,11 +14,6 @@
<%= link_to t('edit'), <%= link_to t('edit'),
edit_admin_education_teacher_path(teacher), edit_admin_education_teacher_path(teacher),
class: button_classes %> class: button_classes %>
<%= link_to t('delete'),
admin_education_teacher_path(teacher),
method: :delete,
data: { confirm: t('please-confirm') },
class: button_classes_danger %>
</div> </div>
</td> </td>
</tr> </tr>
......
<% content_for :title, "#{Education::Teacher.model_name.human(count: 2)} (#{@teachers.total_count})" %> <% content_for :title, "#{Education::Teacher.model_name.human(count: 2)} (#{@teachers.total_count})" %>
<%= render 'admin/education/teachers/list', teachers: @teachers %> <%= render 'admin/education/teachers/list', teachers: @teachers %>
<%= paginate @teachers, theme: 'bootstrap-5' %>
<% if @teachers.total_pages > 1 %>
<%= paginate @teachers, theme: 'bootstrap-5' %>
<% end %>
<% content_for :action_bar_right do %> <% content_for :action_bar_right do %>
<%= create_link Education::Teacher %> <%= link_to t('education.manage_teachers'), admin_administration_members_path, class: button_classes if can?(:read, Administration::Member) %>
<% end %> <% end %>
<% content_for :title, Education::Teacher.model_name.human %>
<%= render 'form', teacher: @teacher %>
<% content_for :title, @teacher %> <% content_for :title, @teacher %>
<div class="row"> <%= render 'admin/administration/members/main_infos', member: @teacher %>
<div class="col-md-8">
<div class="card flex-fill w-100">
<div class="card-header">
<h2 class="card-title mb-0 h5"><%= t('metadata') %></h2>
</div>
<div class="card-body">
<h3 class="h5"><%= Education::Teacher.human_attribute_name('biography') %></h3>
<p><%= @teacher.biography %></p>
<h3 class="h5"><%= Education::Teacher.human_attribute_name('slug') %></h3>
<p><%= @teacher.slug %></p>
<% if @teacher.user %>
<h3 class="h5"><%= Education::Teacher.human_attribute_name('user') %></h3>
<p><%= link_to_if can?(:read, @teacher.user), @teacher.user, admin_user_path(@teacher.user) %></p>
<% end %>
</div>
</div>
</div>
<% if @teacher.programs.any? %> <% if @programs.total_count > 0 %>
<div class="col-md-4"> <div class="card">
<div class="card flex-fill w-100"> <div class="card-header">
<div class="card-header"> <h2 class="card-title mb-0 h5"><%= "#{Education::Program.model_name.human(count: 2)} (#{@programs.total_count})" %></h2>
<h2 class="card-title mb-0 h5"><%= Education::Teacher.human_attribute_name('programs') %></h2>
</div>
<div class="card-body">
<ul class="list-unstyled">
<% @teacher.programs.ordered.each do |program| %>
<li><%= link_to_if can?(:read, program), program, [:admin, program] %></li>
<% end %>
</ul>
</div>
</div>
</div> </div>
<% end %> <%= render 'admin/education/programs/list', programs: @programs %>
<% if @programs.total_pages > 1 %>
</div> <div class="card-footer">
<%= paginate @programs, theme: 'bootstrap-5' %>
</div>
<% end %>
</div>
<% end %>
<% content_for :action_bar_right do %> <% content_for :action_bar_right do %>
<%= edit_link @teacher %> <%= link_to t('edit'), edit_admin_education_teacher_path(@teacher), class: button_classes if can?(:edit, Education::Program) %>
<% end %> <% end %>
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<% if @articles.total_count > 0 %> <% if @articles.total_count > 0 %>
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<h5><%= "#{Research::Journal::Article.model_name.human(count: 2)} (#{@articles.total_count})" %></h5> <h2 class="card-title mb-0 h5"><%= "#{Research::Journal::Article.model_name.human(count: 2)} (#{@articles.total_count})" %></h2>
</div> </div>
<%= render 'admin/research/journal/articles/list', articles: @articles %> <%= render 'admin/research/journal/articles/list', articles: @articles %>
<% if @articles.total_pages > 1 %> <% if @articles.total_pages > 1 %>
......
...@@ -17,6 +17,8 @@ en: ...@@ -17,6 +17,8 @@ en:
administration/member: administration/member:
abilities: Abilities abilities: Abilities
biography: Biography biography: Biography
communication_website_posts: Posts
education_programs: Programs
email: Email email: Email
first_name: First name first_name: First name
is_administrative: Administrative staff is_administrative: Administrative staff
...@@ -26,6 +28,7 @@ en: ...@@ -26,6 +28,7 @@ en:
last_name: Last name last_name: Last name
name: Name name: Name
phone: Phone phone: Phone
research_journal_articles: Articles
slug: Slug slug: Slug
user: User user: User
administration/qualiopi/criterion: administration/qualiopi/criterion:
......
...@@ -17,6 +17,8 @@ fr: ...@@ -17,6 +17,8 @@ fr:
administration/member: administration/member:
abilities: Responsabilités abilities: Responsabilités
biography: Biographie biography: Biographie
communication_website_posts: Actualités
education_programs: Formations
email: Email email: Email
first_name: Prénom first_name: Prénom
is_administrative: Personnel administratif is_administrative: Personnel administratif
...@@ -26,6 +28,7 @@ fr: ...@@ -26,6 +28,7 @@ fr:
last_name: Nom de famille last_name: Nom de famille
name: Nom name: Nom
phone: Téléphone phone: Téléphone
research_journal_articles: Articles
slug: Slug slug: Slug
user: Utilisateur user: Utilisateur
administration/qualiopi/criterion: administration/qualiopi/criterion:
......
...@@ -51,6 +51,8 @@ en: ...@@ -51,6 +51,8 @@ en:
slug: Slug slug: Slug
user: User user: User
education: education:
manage_teachers: Manage teachers
number_of_programs: Number of programs
program: program:
educational_informations: Educational informations educational_informations: Educational informations
main_informations: Main informations main_informations: Main informations
......
...@@ -51,10 +51,13 @@ fr: ...@@ -51,10 +51,13 @@ fr:
slug: Slug slug: Slug
user: Utilisateur user: Utilisateur
education: education:
manage_teachers: Gérer les Enseignants·es
number_of_programs: Nombre de formations
program: program:
educational_informations: Informations pédagogiques educational_informations: Informations pédagogiques
main_informations: Informations essentielles main_informations: Informations essentielles
useful_informations: Informations pratiques useful_informations: Informations pratiques
enums: enums:
education/program: education/program:
level: level:
......
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