From 544eebd11381501ec5d9f31fbeff080f564bf023 Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Wed, 15 Dec 2021 14:35:49 +0100 Subject: [PATCH] wip teachers --- .../admin/education/teachers_controller.rb | 39 +++--------- app/models/administration/member.rb | 6 ++ app/models/education/program.rb | 2 +- app/models/university/with_education.rb | 1 - app/models/university/with_research.rb | 1 - .../members/_main_infos.html.erb | 8 +++ .../administration/members/show.html.erb | 31 +--------- .../admin/education/programs/_form.html.erb | 2 +- .../admin/education/programs/_list.html.erb | 27 +++++++++ .../admin/education/programs/show.html.erb | 6 +- .../admin/education/teachers/_form.html.erb | 60 ++++--------------- .../admin/education/teachers/_list.html.erb | 5 -- .../admin/education/teachers/index.html.erb | 6 +- .../admin/education/teachers/new.html.erb | 3 - .../admin/education/teachers/show.html.erb | 51 +++++----------- .../admin/research/researchers/show.html.erb | 2 +- config/locales/administration/en.yml | 3 + config/locales/administration/fr.yml | 3 + config/locales/education/en.yml | 2 + config/locales/education/fr.yml | 3 + config/routes/admin/education.rb | 3 +- ...nge_index_on_education_program_teachers.rb | 6 ++ db/schema.rb | 3 +- 23 files changed, 106 insertions(+), 167 deletions(-) create mode 100644 app/views/admin/education/programs/_list.html.erb delete mode 100644 app/views/admin/education/teachers/new.html.erb create mode 100644 db/migrate/20211215110752_change_index_on_education_program_teachers.rb diff --git a/app/controllers/admin/education/teachers_controller.rb b/app/controllers/admin/education/teachers_controller.rb index 727280efe..d0df5079c 100644 --- a/app/controllers/admin/education/teachers_controller.rb +++ b/app/controllers/admin/education/teachers_controller.rb @@ -1,24 +1,14 @@ class Admin::Education::TeachersController < Admin::Education::ApplicationController - load_and_authorize_resource class: Education::Teacher, - through: :current_university, - through_association: :education_teachers + before_action :get_teacher, except: :index def index - @teachers = @teachers.ordered.page(params[:page]) + @teachers = current_university.members.teachers.accessible_by(current_ability).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 + @programs = @teacher.education_programs.ordered.page(params[:page]) end def edit @@ -26,15 +16,6 @@ class Admin::Education::TeachersController < Admin::Education::ApplicationContro 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) @@ -45,13 +26,12 @@ class Admin::Education::TeachersController < Admin::Education::ApplicationContro 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 get_teacher + @teacher = current_university.members.teachers.accessible_by(current_ability).find(params[:id]) + end + def breadcrumb super add_breadcrumb Education::Teacher.model_name.human(count: 2), @@ -60,8 +40,7 @@ class Admin::Education::TeachersController < Admin::Education::ApplicationContro end def teacher_params - params.require(:education_teacher) - .permit(:first_name, :last_name, :biography, :slug, :user_id) - .merge(university_id: current_university.id) + params.require(:administration_member) + .permit(education_program_ids: []) end end diff --git a/app/models/administration/member.rb b/app/models/administration/member.rb index d32c64468..997040ab3 100644 --- a/app/models/administration/member.rb +++ b/app/models/administration/member.rb @@ -46,6 +46,12 @@ class Administration::Member < ApplicationRecord join_table: :research_journal_articles_researchers, 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_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? diff --git a/app/models/education/program.rb b/app/models/education/program.rb index f0ae123ab..a74327634 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -58,7 +58,7 @@ class Education::Program < ApplicationRecord foreign_key: 'education_program_id', association_foreign_key: 'education_school_id' has_and_belongs_to_many :teachers, - class_name: 'Education::Teacher', + class_name: 'Administration::Member', join_table: 'education_programs_teachers', foreign_key: 'education_program_id', association_foreign_key: 'education_teacher_id' diff --git a/app/models/university/with_education.rb b/app/models/university/with_education.rb index 897398899..16be46c1b 100644 --- a/app/models/university/with_education.rb +++ b/app/models/university/with_education.rb @@ -2,7 +2,6 @@ module University::WithEducation extend ActiveSupport::Concern 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_schools, class_name: 'Education::School', dependent: :destroy diff --git a/app/models/university/with_research.rb b/app/models/university/with_research.rb index 9f624e185..67cef2638 100644 --- a/app/models/university/with_research.rb +++ b/app/models/university/with_research.rb @@ -2,7 +2,6 @@ module University::WithResearch extend ActiveSupport::Concern included do - has_many :research_researchers, class_name: 'Research::Researcher', dependent: :destroy has_many :research_journals, class_name: 'Research::Journal', dependent: :destroy end end diff --git a/app/views/admin/administration/members/_main_infos.html.erb b/app/views/admin/administration/members/_main_infos.html.erb index 0bc1dc6e9..67dfa3934 100644 --- a/app/views/admin/administration/members/_main_infos.html.erb +++ b/app/views/admin/administration/members/_main_infos.html.erb @@ -5,6 +5,14 @@ <h2 class="card-title mb-0 h5"><%= t('content') %></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> <%= member.biography %> </div> diff --git a/app/views/admin/administration/members/show.html.erb b/app/views/admin/administration/members/show.html.erb index fd1391872..5e204e537 100644 --- a/app/views/admin/administration/members/show.html.erb +++ b/app/views/admin/administration/members/show.html.erb @@ -1,35 +1,6 @@ <% content_for :title, @member %> -<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('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> - +<%= render 'main_infos', member: @member %> <% content_for :action_bar_right do %> <%= edit_link @member %> diff --git a/app/views/admin/education/programs/_form.html.erb b/app/views/admin/education/programs/_form.html.erb index 595a8b4ab..d52e8ae27 100644 --- a/app/views/admin/education/programs/_form.html.erb +++ b/app/views/admin/education/programs/_form.html.erb @@ -56,7 +56,7 @@ <%= f.input :evaluation, as: :rich_text_area %> <%= f.association :teachers, as: :check_boxes, - collection: current_university.education_teachers.ordered %> + collection: current_university.members.teachers.ordered %> </div> </div> </div> diff --git a/app/views/admin/education/programs/_list.html.erb b/app/views/admin/education/programs/_list.html.erb new file mode 100644 index 000000000..9dc1c1600 --- /dev/null +++ b/app/views/admin/education/programs/_list.html.erb @@ -0,0 +1,27 @@ +<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> diff --git a/app/views/admin/education/programs/show.html.erb b/app/views/admin/education/programs/show.html.erb index 2a0a8f4cb..8c1d71ce9 100644 --- a/app/views/admin/education/programs/show.html.erb +++ b/app/views/admin/education/programs/show.html.erb @@ -74,7 +74,7 @@ <h3 class="h5 <%= 'mt-4' if i > 0 %>"><%= Education::Program.human_attribute_name('teachers') %></h3> <ul class="list-unstyled"> <% @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 %> </ul> <% end %> @@ -83,10 +83,6 @@ </div> </div> - - - - <% content_for :action_bar_right do %> <%= edit_link @program %> <% end %> diff --git a/app/views/admin/education/teachers/_form.html.erb b/app/views/admin/education/teachers/_form.html.erb index 36c664ab1..dd685aeac 100644 --- a/app/views/admin/education/teachers/_form.html.erb +++ b/app/views/admin/education/teachers/_form.html.erb @@ -1,54 +1,18 @@ -<%= simple_form_for [:admin, teacher] do |f| %> - <div class="row"> - <div class="col-md-6"> - <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"> - <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> +<%= simple_form_for teacher, url: admin_education_teacher_path(teacher) do |f| %> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= Education::Program.model_name.human(count: 2) %></h5> </div> - <div class="col-md-6"> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= Education::Program.model_name.human(count: 2) %></h5> - </div> - <div class="card-body"> - <%= f.association :programs, - 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 class="card-body"> + <%= f.association :education_programs, + as: :check_boxes, + legend_tag: false, + collection: current_university.list_of_programs, + label_method: ->(p) { sanitize p[:label] }, + value_method: ->(p) { p[:id] } %> </div> </div> + <% content_for :action_bar_right do %> <%= submit f %> <% end %> diff --git a/app/views/admin/education/teachers/_list.html.erb b/app/views/admin/education/teachers/_list.html.erb index 87e1befee..dd77f1248 100644 --- a/app/views/admin/education/teachers/_list.html.erb +++ b/app/views/admin/education/teachers/_list.html.erb @@ -14,11 +14,6 @@ <%= 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> diff --git a/app/views/admin/education/teachers/index.html.erb b/app/views/admin/education/teachers/index.html.erb index 44ce68d4d..a539fb883 100644 --- a/app/views/admin/education/teachers/index.html.erb +++ b/app/views/admin/education/teachers/index.html.erb @@ -1,9 +1,11 @@ <% 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' %> +<% if @teachers.total_pages > 1 %> + <%= paginate @teachers, theme: 'bootstrap-5' %> +<% end %> <% 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 %> diff --git a/app/views/admin/education/teachers/new.html.erb b/app/views/admin/education/teachers/new.html.erb deleted file mode 100644 index 9d2a7e6cf..000000000 --- a/app/views/admin/education/teachers/new.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<% content_for :title, Education::Teacher.model_name.human %> - -<%= render 'form', teacher: @teacher %> diff --git a/app/views/admin/education/teachers/show.html.erb b/app/views/admin/education/teachers/show.html.erb index 5cd610004..c5fd6e562 100644 --- a/app/views/admin/education/teachers/show.html.erb +++ b/app/views/admin/education/teachers/show.html.erb @@ -1,45 +1,22 @@ <% 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? %> - <div class="col-md-4"> - <div class="card flex-fill w-100"> - <div class="card-header"> - <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> +<% if @programs.total_count > 0 %> + <div class="card"> + <div class="card-header"> + <h2 class="card-title mb-0 h5"><%= "#{Education::Program.model_name.human(count: 2)} (#{@programs.total_count})" %></h2> </div> - <% end %> - -</div> - + <%= render 'admin/education/programs/list', programs: @programs %> + <% if @programs.total_pages > 1 %> + <div class="card-footer"> + <%= paginate @programs, theme: 'bootstrap-5' %> + </div> + <% end %> + </div> +<% end %> <% 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 %> diff --git a/app/views/admin/research/researchers/show.html.erb b/app/views/admin/research/researchers/show.html.erb index 1a6d84fac..7c58ad5f8 100644 --- a/app/views/admin/research/researchers/show.html.erb +++ b/app/views/admin/research/researchers/show.html.erb @@ -5,7 +5,7 @@ <% if @articles.total_count > 0 %> <div class="card"> <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> <%= render 'admin/research/journal/articles/list', articles: @articles %> <% if @articles.total_pages > 1 %> diff --git a/config/locales/administration/en.yml b/config/locales/administration/en.yml index 848225863..a5dd96be0 100644 --- a/config/locales/administration/en.yml +++ b/config/locales/administration/en.yml @@ -17,6 +17,8 @@ en: administration/member: abilities: Abilities biography: Biography + communication_website_posts: Posts + education_programs: Programs email: Email first_name: First name is_administrative: Administrative staff @@ -26,6 +28,7 @@ en: last_name: Last name name: Name phone: Phone + research_journal_articles: Articles slug: Slug user: User administration/qualiopi/criterion: diff --git a/config/locales/administration/fr.yml b/config/locales/administration/fr.yml index 84adfce3e..5c62bd090 100644 --- a/config/locales/administration/fr.yml +++ b/config/locales/administration/fr.yml @@ -17,6 +17,8 @@ fr: administration/member: abilities: Responsabilités biography: Biographie + communication_website_posts: Actualités + education_programs: Formations email: Email first_name: Prénom is_administrative: Personnel administratif @@ -26,6 +28,7 @@ fr: last_name: Nom de famille name: Nom phone: Téléphone + research_journal_articles: Articles slug: Slug user: Utilisateur administration/qualiopi/criterion: diff --git a/config/locales/education/en.yml b/config/locales/education/en.yml index 759a29b7d..6489af098 100644 --- a/config/locales/education/en.yml +++ b/config/locales/education/en.yml @@ -51,6 +51,8 @@ en: slug: Slug user: User education: + manage_teachers: Manage teachers + number_of_programs: Number of programs program: educational_informations: Educational informations main_informations: Main informations diff --git a/config/locales/education/fr.yml b/config/locales/education/fr.yml index 2a0d3172a..36bd3a02a 100644 --- a/config/locales/education/fr.yml +++ b/config/locales/education/fr.yml @@ -51,10 +51,13 @@ fr: slug: Slug user: Utilisateur education: + manage_teachers: Gérer les Enseignants·es + number_of_programs: Nombre de formations program: educational_informations: Informations pédagogiques main_informations: Informations essentielles useful_informations: Informations pratiques + enums: education/program: level: diff --git a/config/routes/admin/education.rb b/config/routes/admin/education.rb index 0a11f525c..8d4ae678f 100644 --- a/config/routes/admin/education.rb +++ b/config/routes/admin/education.rb @@ -1,5 +1,6 @@ namespace :education do - resources :teachers, :schools + resources :teachers, except: [:create, :destroy] + resources :schools resources :programs do collection do post :reorder diff --git a/db/migrate/20211215110752_change_index_on_education_program_teachers.rb b/db/migrate/20211215110752_change_index_on_education_program_teachers.rb new file mode 100644 index 000000000..d3772bfbc --- /dev/null +++ b/db/migrate/20211215110752_change_index_on_education_program_teachers.rb @@ -0,0 +1,6 @@ +class ChangeIndexOnEducationProgramTeachers < ActiveRecord::Migration[6.1] + def change + add_foreign_key :education_programs_teachers, :administration_members, column: :education_teacher_id + + end +end diff --git a/db/schema.rb b/db/schema.rb index 3e68dc191..9de4c35f0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_12_15_104346) do +ActiveRecord::Schema.define(version: 2021_12_15_110752) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -612,6 +612,7 @@ ActiveRecord::Schema.define(version: 2021_12_15_104346) do add_foreign_key "communication_websites", "universities" add_foreign_key "education_programs", "education_programs", column: "parent_id" add_foreign_key "education_programs", "universities" + add_foreign_key "education_programs_teachers", "administration_members", column: "education_teacher_id" add_foreign_key "education_schools", "universities" add_foreign_key "education_teachers", "universities" add_foreign_key "education_teachers", "users" -- GitLab