From 4a0b8bc0d1a9a03e22bd96a0c49d6b5a6ffb1c91 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Fri, 7 Jan 2022 09:37:13 +0100
Subject: [PATCH] generate teachers and roles

---
 .../education/program/roles/_list.html.erb    | 66 ++++++++++---------
 .../education/program/teachers/_list.html.erb |  4 +-
 .../admin/education/programs/_form.html.erb   | 16 ++---
 .../admin/education/programs/show.html.erb    | 26 ++++----
 .../admin/education/programs/static.html.erb  | 26 ++++----
 5 files changed, 71 insertions(+), 67 deletions(-)

diff --git a/app/views/admin/education/program/roles/_list.html.erb b/app/views/admin/education/program/roles/_list.html.erb
index 9fbda8e94..0a152d39a 100644
--- a/app/views/admin/education/program/roles/_list.html.erb
+++ b/app/views/admin/education/program/roles/_list.html.erb
@@ -1,33 +1,35 @@
-<table class="table table-sortable">
-  <thead>
-    <tr>
-      <th><%= Education::Program::Role.model_name.human %></th>
-      <th><%= Education::Program::Role.human_attribute_name('people') %></th>
-      <th></th>
-    </tr>
-  </thead>
-  <tbody data-reorder-url="<%= reorder_admin_education_program_roles_path(program_id: @program.id) %>">
-    <% roles.each do |role| %>
-      <tr class="handle" data-id="<%= role.id %>">
-        <td>
-          <%= link_to_if  can?(:read, role),
-                          role,
-                          admin_education_program_role_path(role, { program_id: @program.id }) %>
-        </td>
-        <td><%= role.people.includes(:person).ordered.map { |person| person.person.to_s }.to_sentence %></td>
-        <td class="text-end pe-0">
-          <div class="btn-group" role="group">
-            <%= link_to t('edit'),
-                        edit_admin_education_program_role_path(role, { program_id: @program.id }),
-                        class: button_classes %>
-            <%= link_to t('delete'),
-                        admin_education_program_role_path(role, { program_id: @program.id }),
-                        method: :delete,
-                        data: { confirm: t('please_confirm') },
-                        class: button_classes_danger %>
-          </div>
-        </td>
+<% if roles.any? %>
+  <table class="table table-sortable">
+    <thead>
+      <tr>
+        <th class="ps-0"><%= Education::Program::Role.model_name.human %></th>
+        <th><%= Education::Program::Role.human_attribute_name('people') %></th>
+        <th></th>
       </tr>
-    <% end %>
-  </tbody>
-</table>
+    </thead>
+    <tbody data-reorder-url="<%= reorder_admin_education_program_roles_path(program_id: @program.id) %>">
+      <% roles.each do |role| %>
+        <tr class="handle" data-id="<%= role.id %>">
+          <td class="ps-0">
+            <%= link_to_if  can?(:read, role),
+                            role,
+                            admin_education_program_role_path(role, { program_id: @program.id }) %>
+          </td>
+          <td><%= role.people.includes(:person).ordered.map { |person| person.person.to_s }.to_sentence %></td>
+          <td class="text-end pe-0">
+            <div class="btn-group" role="group">
+              <%= link_to t('edit'),
+                          edit_admin_education_program_role_path(role, { program_id: @program.id }),
+                          class: button_classes %>
+              <%= link_to t('delete'),
+                          admin_education_program_role_path(role, { program_id: @program.id }),
+                          method: :delete,
+                          data: { confirm: t('please_confirm') },
+                          class: button_classes_danger %>
+            </div>
+          </td>
+        </tr>
+      <% end %>
+    </tbody>
+  </table>
+<% end %>
diff --git a/app/views/admin/education/program/teachers/_list.html.erb b/app/views/admin/education/program/teachers/_list.html.erb
index d60993405..5fb075887 100644
--- a/app/views/admin/education/program/teachers/_list.html.erb
+++ b/app/views/admin/education/program/teachers/_list.html.erb
@@ -2,7 +2,7 @@
   <table class="table">
     <thead>
       <tr>
-        <th><%= Education::Program::Teacher.model_name.human %></th>
+        <th class="ps-0"><%= Education::Program::Teacher.model_name.human %></th>
         <th><%= Education::Program::Teacher.human_attribute_name('description') %></th>
         <th></th>
       </tr>
@@ -10,7 +10,7 @@
     <tbody>
       <% teachers.each do |teacher| %>
         <tr>
-          <td>
+          <td class="ps-0">
             <%= link_to_if  can?(:read, teacher.person),
                             teacher.person,
                             admin_education_teacher_path(teacher.person) %>
diff --git a/app/views/admin/education/programs/_form.html.erb b/app/views/admin/education/programs/_form.html.erb
index c9574d775..f930ef9bf 100644
--- a/app/views/admin/education/programs/_form.html.erb
+++ b/app/views/admin/education/programs/_form.html.erb
@@ -28,7 +28,7 @@
         </div>
       </div>
     </div>
-    <div class="col-md-5">
+    <div class="col-md-6">
       <div class="card flex-fill w-100">
         <div class="card-header">
           <h5 class="card-title mb-0"><%= t('education.program.useful_informations') %></h5>
@@ -43,7 +43,7 @@
         </div>
       </div>
     </div>
-    <div class="col-md-4">
+    <div class="col-md-3">
       <div class="card flex-fill w-100">
         <div class="card-header">
           <h5 class="card-title mb-0"><%= t('activerecord.attributes.education/program.featured_image') %></h5>
@@ -75,18 +75,16 @@
     </div>
     <div class="card-body">
       <div class="row">
-        <div class="col-md-4">
+        <div class="col-md-6">
           <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :objectives %>
           <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :content %>
-        </div>
-        <div class="col-md-4">
-          <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :opportunities %>
           <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :prerequisites %>
-          <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :results %>
         </div>
-        <div class="col-md-4">
-          <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :evaluation %>
+        <div class="col-md-6">
           <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :pedagogy %>
+          <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :evaluation %>
+          <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :opportunities %>
+          <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :results %>
         </div>
       </div>
     </div>
diff --git a/app/views/admin/education/programs/show.html.erb b/app/views/admin/education/programs/show.html.erb
index 1a9291834..e3263475a 100644
--- a/app/views/admin/education/programs/show.html.erb
+++ b/app/views/admin/education/programs/show.html.erb
@@ -55,8 +55,6 @@
               :duration,
               :contacts,
               :accessibility,
-              :content,
-              :results,
               :other
             ].each_with_index do |prop, index| %>
           <%
@@ -87,7 +85,7 @@
     <div class="row">
       <div class="col-md-6">
         <% i = 0 %>
-        <% ['prerequisites', 'objectives', 'opportunities'].each do |prop| %>
+        <% [:prerequisites, :objectives, :opportunities, :results].each do |prop| %>
           <% next if @program.public_send(prop).blank? %>
           <h3 class="h5 <%= 'mt-4' if i > 0 %>"><%= Education::Program.human_attribute_name(prop) %></h3>
           <%= @program.public_send prop %>
@@ -96,16 +94,12 @@
       </div>
       <div class="col-md-6">
         <% i = 0 %>
-        <% ['pedagogy', 'evaluation'].each do |prop| %>
+        <% ['pedagogy', 'evaluation', 'content'].each do |prop| %>
           <% next if @program.public_send(prop).blank? %>
           <h3 class="h5 <%= 'mt-4' if i > 0 %>"><%= Education::Program.human_attribute_name(prop) %></h3>
           <%= @program.public_send prop %>
           <% i += 1 %>
         <% end %>
-
-        <h3 class="h5 <%= 'mt-4' if i > 0 %>"><%= Education::Program.human_attribute_name('teachers') %></h3>
-        <p><%= link_to t('create'), new_admin_education_program_teacher_path(program_id: @program.id), class: 'btn btn-primary' %></p>
-        <%= render 'admin/education/program/teachers/list', teachers: @program.teachers.includes(:person).ordered %>
       </div>
     </div>
   </div>
@@ -113,11 +107,21 @@
 
 <div class="card flex-fill w-100">
   <div class="card-header">
-    <h5 class="card-title mb-0"><%= Education::Program.human_attribute_name('roles') %></h5>
+    <h5 class="card-title mb-0"><%= Education::Program.human_attribute_name('team') %></h5>
   </div>
   <div class="card-body">
-    <p><%= link_to t('create'), new_admin_education_program_role_path(program_id: @program.id), class: 'btn btn-primary' %></p>
-    <%= render 'admin/education/program/roles/list', roles: @program.roles.ordered %>
+    <div class="row">
+      <div class="col-md-6">
+        <h3 class="h5"><%= Education::Program.human_attribute_name('roles') %></h3>
+        <%= render 'admin/education/program/roles/list', roles: @program.roles.ordered %>
+        <%= link_to t('create'), new_admin_education_program_role_path(program_id: @program.id), class: button_classes %>
+      </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 %>
+        <%= link_to t('create'), new_admin_education_program_teacher_path(program_id: @program.id), class: button_classes %>
+      </div>
+    </div>
   </div>
 </div>
 
diff --git a/app/views/admin/education/programs/static.html.erb b/app/views/admin/education/programs/static.html.erb
index de6e82c0c..4fc644710 100644
--- a/app/views/admin/education/programs/static.html.erb
+++ b/app/views/admin/education/programs/static.html.erb
@@ -11,20 +11,20 @@ image_alt: "<%= @program.featured_image_alt %>"
 <% end %>
 category: "<%= @website.categories.find_by(program_id: @program.id)&.id %>"
 teachers:
-  - "marlene-dulaurans"
-  - "arnaud-levy"
-administrators:
-  - "quentin-bessiere"
-contact_list:
-  - title: "Cheffe de département"
-    persons:
-      - "marlene-dulaurans"
-  - title: "Directeur des études"
-    persons:
-      - "arnaud-levy"
-  - title: "Secrétariat"
+<% @program.teachers.includes(:person).ordered.each do |teacher| %>
+  - person: "<%= teacher.person.slug %>"
+    description: >
+      <%= teacher.description %>
+<% end %>
+roles:
+<% @program.roles.ordered.each do |role| %>
+  - title: >
+      <%= role.to_s %>
     persons:
-      - "quentin-bessiere"
+    <% role.people.includes(:person).ordered.each do |role_person| %>
+      - "<%= role_person.person.slug %>"
+    <% end %>
+<% end %>
 continuing: <%= @program.continuing %>
 level: <%= @program.level %>
 ects: <%= @program.ects %>
-- 
GitLab