Skip to content
Snippets Groups Projects
Commit 85d573c6 authored by pabois's avatar pabois
Browse files

#54

parent 58f2d7dd
No related branches found
No related tags found
No related merge requests found
Showing
with 318 additions and 7 deletions
......@@ -56,6 +56,6 @@ class Admin::Education::ProgramsController < Admin::Education::ApplicationContro
params.require(:education_program)
.permit(:name, :level, :capacity, :ects, :continuing,
:prerequisites, :objectives, :duration, :registration, :pedagogy,
:evaluation, :accessibility, :pricing, :contacts, :opportunities, :other, school_ids: [])
:evaluation, :accessibility, :pricing, :contacts, :opportunities, :other, school_ids: [], teacher_ids: [])
end
end
class Admin::Education::TeachersController < Admin::Education::ApplicationController
load_and_authorize_resource class: Education::Teacher
def index
@teachers = current_university.teachers.ordered.page(params[:page])
breadcrumb
end
def show
breadcrumb
end
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
def edit
breadcrumb
add_breadcrumb t('edit')
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
if @teacher.update(teacher_params)
redirect_to admin_education_teacher_path(@teacher), notice: t('admin.successfully_updated_html', model: @teacher.to_s)
else
breadcrumb
add_breadcrumb t('edit')
render :edit, status: :unprocessable_entity
end
end
def destroy
@teacher.destroy
redirect_to admin_education_teachers_url, notice: t('admin.successfully_destroyed_html', model: @teacher.to_s)
end
protected
def breadcrumb
super
add_breadcrumb Education::Teacher.model_name.human(count: 2),
admin_education_teachers_path
breadcrumb_for @teacher
end
def teacher_params
params.require(:education_teacher)
.permit(:first_name, :last_name, :biography, :slug, :user_id)
.merge(university_id: current_university.id)
end
end
......@@ -3,7 +3,8 @@ module WithSlug
included do
validates :slug,
uniqueness: { scope: :university_id },
uniqueness: { scope: :university_id }
validates :slug,
format: { with: /\A[a-z0-9\-]+\z/, message: "ne peut contenir que des lettres minuscules, des chiffres et des traits d'union." },
allow_blank: true
end
......
......@@ -39,6 +39,11 @@ class Education::Program < ApplicationRecord
join_table: 'education_programs_schools',
foreign_key: 'education_program_id',
association_foreign_key: 'education_school_id'
has_and_belongs_to_many :teachers,
class_name: 'Education::Teacher',
join_table: 'education_programs_teachers',
foreign_key: 'education_program_id',
association_foreign_key: 'education_teacher_id'
enum level: {
bachelor: 300,
......
# == Schema Information
#
# Table name: education_teachers
#
# id :uuid not null, primary key
# first_name :string
# github_path :text
# last_name :string
# slug :string
# created_at :datetime not null
# updated_at :datetime not null
# university_id :uuid not null
# user_id :uuid
#
# Indexes
#
# index_education_teachers_on_university_id (university_id)
# index_education_teachers_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (university_id => universities.id)
# fk_rails_... (user_id => users.id)
#
class Education::Teacher < ApplicationRecord
include WithGithub
include WithSlug
has_rich_text :biography
belongs_to :university
belongs_to :user, optional: true
has_and_belongs_to_many :programs,
class_name: 'Education::Program',
join_table: 'education_programs_teachers',
foreign_key: 'education_teacher_id',
association_foreign_key: 'education_program_id'
scope :ordered, -> { order(:last_name, :first_name) }
def to_s
"#{last_name} #{first_name}"
end
def github_path_generated
"_teachers/#{slug}.html"
end
def to_jekyll
ApplicationController.render(
template: 'admin/education/teachers/jekyll',
layout: false,
assigns: { teacher: self }
)
end
end
......@@ -2,6 +2,7 @@ module University::WithEducation
extend ActiveSupport::Concern
included do
has_many :teachers, class_name: 'Education::Teacher', dependent: :destroy
has_many :education_programs, class_name: 'Education::Program', dependent: :destroy
has_many :education_schools, class_name: 'Education::School', dependent: :destroy
end
......
......@@ -9,8 +9,7 @@
<%= f.input :continuing %>
<%= f.association :schools,
as: :check_boxes,
collection: current_university.education_schools.ordered
%>
collection: current_university.education_schools.ordered %>
</div>
<div class="col-md-8">
<h2 class="h4"><%= t('education.program.useful_informations') %></h2>
......@@ -32,6 +31,9 @@
<div class="col-md-6">
<%= f.input :pedagogy, as: :rich_text_area %>
<%= f.input :evaluation, as: :rich_text_area %>
<%= f.association :teachers,
as: :check_boxes,
collection: current_university.teachers.ordered %>
</div>
</div>
<% content_for :action_bar_right do %>
......
<%= simple_form_for [:admin, teacher] do |f| %>
<div class="row">
<div class="col-md-8">
<div class="card flex-fill w-100">
<div class="card-header">
<h5 class="card-title mb-0"><%= t('content') %></h5>
</div>
<div class="card-body">
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :biography, as: :rich_text_area %>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card flex-fill w-100">
<div class="card-header">
<h5 class="card-title mb-0"><%= t('metadata') %></h5>
</div>
<div class="card-body">
<%= f.input :slug,
as: :string,
input_html: teacher.persisted? ? {} : {
class: 'js-slug-input',
data: { source: '#education_teacher_first_name, #education_teacher_last_name' }
} %>
<%= f.association :user, collection: current_university.users.ordered %>
<ul>
</ul>
</div>
</div>
</div>
</div>
<% content_for :action_bar_right do %>
<%= submit f %>
<% end %>
<% end %>
<table class="<%= table_classes %>">
<thead>
<tr>
<th><%= Education::Teacher.human_attribute_name('name') %></th>
<th></th>
</tr>
</thead>
<tbody>
<% teachers.each do |teacher| %>
<tr>
<td><%= link_to teacher, admin_education_teacher_path(teacher) %></td>
<td class="text-end">
<div class="btn-group" role="group">
<%= link_to t('edit'),
edit_admin_education_teacher_path(teacher),
class: button_classes %>
<%= link_to t('delete'),
admin_education_teacher_path(teacher),
method: :delete,
data: { confirm: t('please-confirm') },
class: button_classes_danger %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<% content_for :title, @teacher %>
<%= render 'form', teacher: @teacher %>
<% content_for :title, "#{Education::Teacher.model_name.human(count: 2)} (#{@teachers.total_count})" %>
<%= render 'admin/education/teachers/list', teachers: @teachers %>
<%= paginate @teachers, theme: 'bootstrap-5' %>
<% content_for :action_bar_right do %>
<%= create_link Education::Teacher %>
<% end %>
---
title: "<%= @author.to_s %>"
identifier: "<%= @author.id %>"
first_name: "<%= @author.first_name %>"
last_name: "<%= @author.last_name %>"
slug: "<%= @author.slug %>"
biography: >
<%= prepare_for_github @author.biography, @author.university %>
---
<%= @author.github_frontmatter.content.html_safe %>
<% content_for :title, Education::Teacher.model_name.human %>
<%= render 'form', teacher: @teacher %>
<% content_for :title, @teacher %>
<div class="row">
<div class="col-md-8">
<div class="card flex-fill w-100">
<div class="card-header">
<h2 class="card-title mb-0 h5"><%= t('content') %></h2>
</div>
<div class="card-body">
<h3 class="h5"><%= Education::Teacher.human_attribute_name('biography') %></h3>
<%= @teacher.biography %>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card flex-fill w-100">
<div class="card-header">
<h2 class="card-title mb-0 h5"><%= t('metadata') %></h2>
</div>
<table class="<%= table_classes %>">
<tbody>
<tr>
<td width="150"><%= Education::Teacher.human_attribute_name('slug') %></td>
<td><%= @teacher.slug %></td>
</tr>
<% if @teacher.user %>
<tr>
<td width="150"><%= Education::Teacher.human_attribute_name('user') %></td>
<td><%= link_to_if can?(:read, @teacher.user), @teacher.user, admin_user_path(@teacher.user) %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
<% content_for :action_bar_right do %>
<%= edit_link @teacher %>
<% end %>
......@@ -8,7 +8,7 @@ SimpleNavigation::Configuration.run do |navigation|
if can?(:read, Education::Program)
primary.item :education, Education.model_name.human, nil, { kind: :header }
primary.item :education, 'Enseignants', nil, { icon: 'user-graduate' }
primary.item :education, Education::Teacher.model_name.human(count: 2), admin_education_teachers_path, { icon: 'user-graduate' }
primary.item :education, Education::School.model_name.human(count: 2), admin_education_schools_path, { icon: 'university' } if can?(:read, Education::School)
primary.item :education_programs, Education::Program.model_name.human(count: 2), admin_education_programs_path, { icon: 'graduation-cap' } if can?(:read, Education::Program)
primary.item :education, 'Ressources éducatives', nil, { icon: 'laptop' }
......
......@@ -10,6 +10,9 @@ en:
education/school:
one: School
other: Schools
education/teacher:
one: Teacher
other: Teachers
attributes:
education/program:
accessibility: Accessibilité
......@@ -28,12 +31,21 @@ en:
prerequisites: Prérequis
pricing: Tarifs
registration: Modalités et délais d’accès
schools: Schools
teachers: Teachers
education/school:
address:: Address
address: Address
city: City
country: Country
name: Name
zipcode: Zipcode
education/teacher:
biography: Biography
first_name: First name
last_name: Last name
name: Name
slug: Slug
user: User
education:
program:
main_informations: Main informations
......
......@@ -10,6 +10,9 @@ fr:
education/school:
one: École
other: Écoles
education/teacher:
one: Enseignant·e
other: Enseignants·es
attributes:
education/program:
accessibility: Accessibilité
......@@ -28,12 +31,21 @@ fr:
prerequisites: Prérequis
pricing: Tarifs
registration: Modalités et délais d’accès
schools: Écoles
teachers: Enseignants·es
education/school:
address: Adresse
city: Ville
country: Pays
name: Nom
zipcode: Code postal
education/teacher:
biography: Biographie
first_name: Prénom
last_name: Nom de famille
name: Nom
slug: Slug
user: Utilisateur
education:
program:
main_informations: Informations essentielles
......
namespace :education do
resources :programs, :schools
resources :programs, :schools, :teachers
end
class CreateEducationTeacher < ActiveRecord::Migration[6.1]
def change
create_table :education_teachers, id: :uuid do |t|
t.references :university, null: false, foreign_key: true, type: :uuid
t.string :first_name
t.string :last_name
t.string :slug
t.text :github_path
t.references :user, null: true, foreign_key: true, type: :uuid
t.timestamps
end
end
end
class CreateJoinTableProgramsTeachers < ActiveRecord::Migration[6.1]
def change
create_join_table :education_programs, :education_teachers, column_options: {type: :uuid} do |t|
t.index [:education_program_id, :education_teacher_id], name: 'program_teacher'
t.index [:education_teacher_id, :education_program_id], name: 'teacher_program'
end
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