From 9bd1cdfad87db4ba705e62e43e8c9d5cf174b3f0 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Thu, 1 Dec 2022 12:38:52 +0100
Subject: [PATCH] cohorts in path

---
 .../admin/education/schools_controller.rb     |  2 +-
 app/models/education/school.rb                |  1 +
 .../admin/education/schools/_form.html.erb    |  5 +++
 app/views/extranet/experiences/_list.html.erb | 32 +++++++++++++++----
 app/views/extranet/persons/_details.html.erb  |  4 ---
 app/views/extranet/persons/show.html.erb      |  6 ++--
 config/locales/extranet/en.yml                |  2 +-
 config/locales/extranet/fr.yml                |  2 +-
 8 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/app/controllers/admin/education/schools_controller.rb b/app/controllers/admin/education/schools_controller.rb
index 37ea835aa..f3322b1f8 100644
--- a/app/controllers/admin/education/schools_controller.rb
+++ b/app/controllers/admin/education/schools_controller.rb
@@ -60,6 +60,6 @@ class Admin::Education::SchoolsController < Admin::Education::ApplicationControl
 
   def school_params
     params.require(:education_school)
-          .permit(:university_id, :name, :address, :zipcode, :city, :country, :phone, program_ids: [])
+          .permit(:university_id, :name, :address, :zipcode, :city, :country, :phone, :logo, :logo_delete, program_ids: [])
   end
 end
diff --git a/app/models/education/school.rb b/app/models/education/school.rb
index 02b110ca1..0497ecea9 100644
--- a/app/models/education/school.rb
+++ b/app/models/education/school.rb
@@ -37,6 +37,7 @@ class Education::School < ApplicationRecord
               as: :about,
               dependent: :nullify
 
+  has_one_attached_deletable :logo
 
   validates :name, :address, :city, :zipcode, :country, presence: true
 
diff --git a/app/views/admin/education/schools/_form.html.erb b/app/views/admin/education/schools/_form.html.erb
index 57f400b31..605b29b3c 100644
--- a/app/views/admin/education/schools/_form.html.erb
+++ b/app/views/admin/education/schools/_form.html.erb
@@ -21,6 +21,11 @@
             </div>
           </div>
           <%= f.input :country, input_html: { class: 'form-select' } %>
+          <%= f.input :logo, 
+                      as: :single_deletable_file,
+                      input_html: { accept: '.jpg,.jpeg,.png,.svg' },
+                      preview: 200,
+                      direct_upload: true %>
         </div>
       </div>
     </div>
diff --git a/app/views/extranet/experiences/_list.html.erb b/app/views/extranet/experiences/_list.html.erb
index ae422741e..9b5ef4cd8 100644
--- a/app/views/extranet/experiences/_list.html.erb
+++ b/app/views/extranet/experiences/_list.html.erb
@@ -1,12 +1,32 @@
 <%
 edit ||= false
 %>
-<% if person&.experiences.any? %>
-  <div class="experiences mt-4">
-    <ul class="list-unstyled">
+<div class="experiences mt-4">
+  <ul class="list-unstyled">
+    <% if person&.experiences.any? %>
       <% @person.experiences.ordered.each do |experience| %>
         <%= render 'extranet/experiences/experience', experience: experience, edit: edit %>
       <% end %>
-    </ul>
-  </div>
-<% end %>
\ No newline at end of file
+    <% end %>
+    <% person&.cohorts.each do |cohort| %>
+      <li class="experiences__experience py-4 border-top">
+        <div class="row">
+          <div class="col-md-6">
+            <p class="mb-0">
+              <b><%= cohort.program %></b><br>
+              <%= cohort.program.diploma %><br>
+              <%= cohort.year %>
+            </p>
+          </div>
+          <div class="col-md-6 text-end">
+            <% if cohort.school.logo.attached? %>
+              <%= kamifusen_tag cohort.school.logo, width: 100, class: 'img-fluid experience__organization__logo' %>
+            <% else %>
+              <p class="text-end"><%= cohort.school %></p>
+            <% end %>
+          </div>
+        </div>
+      </li>
+    <% end %>
+  </ul>
+</div>
\ No newline at end of file
diff --git a/app/views/extranet/persons/_details.html.erb b/app/views/extranet/persons/_details.html.erb
index 525ff0506..3347918fa 100644
--- a/app/views/extranet/persons/_details.html.erb
+++ b/app/views/extranet/persons/_details.html.erb
@@ -1,8 +1,4 @@
 <dl>
-  <% person.cohorts.each do |cohort| %>
-    <dt><%= cohort.program %></dt>
-    <dd><%= link_to cohort.academic_year, cohort %></dd>
-  <% end %>
   <% [:phone_mobile, :phone_personal, :phone_professional].each do |attribute_name| %>
     <% next if person.public_send(attribute_name).blank? %>
     <dt><%= University::Person.human_attribute_name(attribute_name) %> :</dt>
diff --git a/app/views/extranet/persons/show.html.erb b/app/views/extranet/persons/show.html.erb
index 538746476..a296fd502 100644
--- a/app/views/extranet/persons/show.html.erb
+++ b/app/views/extranet/persons/show.html.erb
@@ -9,10 +9,8 @@
         </div>
       </div>
     </div>
-    <% if @person.experiences.any? %>
-      <p class="mb-4"><%= t('extranet.experiences.title') %></p>
-      <%= render 'extranet/experiences/list', person: @person %>
-    <% end %> 
+    <p class="mb-4"><%= t('extranet.experiences.title') %></p>
+    <%= render 'extranet/experiences/list', person: @person %>
   </div>
   <div class="offset-md-1 col-md-3 order-1 order-md-2">
     <%= kamifusen_tag @person.best_picture, width: 400, class: 'img-fluid person__portrait' if @person.best_picture.attached? %>
diff --git a/config/locales/extranet/en.yml b/config/locales/extranet/en.yml
index bd6694da2..c56a2abc9 100644
--- a/config/locales/extranet/en.yml
+++ b/config/locales/extranet/en.yml
@@ -12,7 +12,7 @@ en:
       email_not_allowed_with_contact: is not authorized to access this extranet. Contact %{contact} for more information.
     experiences:
       new: Add experience
-      title: Professional path
+      title: Path
     home:
       recent_cohorts: Recent cohorts
       recent_experiences: Recent experiences
diff --git a/config/locales/extranet/fr.yml b/config/locales/extranet/fr.yml
index 8b94b1539..453c69e96 100644
--- a/config/locales/extranet/fr.yml
+++ b/config/locales/extranet/fr.yml
@@ -13,7 +13,7 @@ fr:
     experiences:
       new: Ajouter une expérience
       search_organization: Rechercher par nom ou SIREN
-      title: Parcours professionnel
+      title: Parcours
     home:
       recent_cohorts: Promotions récentes
       recent_experiences: Mouvements récents
-- 
GitLab