From 63f9650870db1a85a6ed4f49fe2df30b92cc3853 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Wed, 27 Apr 2022 11:59:37 +0200
Subject: [PATCH] home

---
 app/controllers/extranet/home_controller.rb   |  5 ++--
 app/models/education/program.rb               |  6 +++++
 app/models/education/school.rb                |  2 ++
 app/models/university/with_communication.rb   | 17 +++++++++++---
 app/models/university/with_education.rb       | 23 +++++++++++++++----
 .../with_people_and_organizations.rb          | 16 +++++++++----
 app/views/extranet/home/index.html.erb        | 11 ++++++++-
 7 files changed, 66 insertions(+), 14 deletions(-)

diff --git a/app/controllers/extranet/home_controller.rb b/app/controllers/extranet/home_controller.rb
index ec6a69a8e..6f189dd8b 100644
--- a/app/controllers/extranet/home_controller.rb
+++ b/app/controllers/extranet/home_controller.rb
@@ -1,7 +1,8 @@
 class Extranet::HomeController < Extranet::ApplicationController
   def index
     return redirect_to admin_root_path unless current_extranet
-    @cohorts = current_extranet.about&.cohorts || current_university.education_cohorts
-    @cohorts = @cohorts.ordered.limit(5)
+    @about = current_extranet.about || current_university
+    @cohorts = @about&.cohorts.ordered.limit(5)
+    @experiences = @about&.experiences.ordered.limit(10)
   end
 end
diff --git a/app/models/education/program.rb b/app/models/education/program.rb
index da883ad45..ef9465eac 100644
--- a/app/models/education/program.rb
+++ b/app/models/education/program.rb
@@ -110,21 +110,27 @@ class Education::Program < ApplicationRecord
   has_many   :websites,
              -> { distinct },
              through: :schools
+
   has_many   :cohorts,
              class_name: 'Education::Cohort'
+
   has_many   :alumni,
              through: :cohorts,
              source: :people
+
   has_many   :alumni_experiences,
              -> { distinct },
              class_name: 'University::Person::Experience',
              through: :alumni,
              source: :experiences
+  alias_attribute :experiences, :alumni_experiences
+
   has_many   :alumni_organizations,
              -> { distinct },
              class_name: 'University::Organization',
              through: :alumni_experiences,
              source: :organization
+
   has_many   :academic_years,
              through: :cohorts
 
diff --git a/app/models/education/school.rb b/app/models/education/school.rb
index 714451661..7149a637c 100644
--- a/app/models/education/school.rb
+++ b/app/models/education/school.rb
@@ -74,6 +74,8 @@ class Education::School < ApplicationRecord
               class_name: 'University::Person::Experience',
               through: :alumni,
               source: :experiences
+  alias_attribute :experiences, :alumni_experiences
+
   has_many    :alumni_organizations,
               -> { distinct },
               class_name: 'University::Organization',
diff --git a/app/models/university/with_communication.rb b/app/models/university/with_communication.rb
index ccf765d5e..c43441eb8 100644
--- a/app/models/university/with_communication.rb
+++ b/app/models/university/with_communication.rb
@@ -2,8 +2,19 @@ module University::WithCommunication
   extend ActiveSupport::Concern
 
   included do
-    has_many :communication_extranets, class_name: 'Communication::Extranet', dependent: :destroy
-    has_many :communication_websites, class_name: 'Communication::Website', dependent: :destroy
-    has_many :communication_blocks, class_name: 'Communication::Block', dependent: :destroy
+    has_many  :communication_extranets,
+              class_name: 'Communication::Extranet',
+              dependent: :destroy
+    alias_attribute :extranets, :communication_extranets
+
+    has_many  :communication_websites,
+              class_name: 'Communication::Website',
+              dependent: :destroy
+    alias_attribute :websites, :communication_websites
+
+    has_many  :communication_blocks,
+              class_name: 'Communication::Block',
+              dependent: :destroy
+    alias_attribute :blocks, :communication_blocks
   end
 end
diff --git a/app/models/university/with_education.rb b/app/models/university/with_education.rb
index eab20006b..95b2d605b 100644
--- a/app/models/university/with_education.rb
+++ b/app/models/university/with_education.rb
@@ -2,9 +2,24 @@ module University::WithEducation
   extend ActiveSupport::Concern
 
   included do
-    has_many :education_cohorts, class_name: 'Education::Cohort', dependent: :destroy
-    has_many :education_programs, class_name: 'Education::Program', dependent: :destroy
-    has_many :education_schools, class_name: 'Education::School', dependent: :destroy
-    has_many :academic_years, class_name: 'Education::AcademicYear', dependent: :destroy
+    has_many  :education_cohorts,
+              class_name: 'Education::Cohort',
+              dependent: :destroy
+    alias_attribute :cohorts, :education_cohorts
+
+    has_many  :education_programs,
+              class_name: 'Education::Program',
+              dependent: :destroy
+    alias_attribute :programs, :education_programs
+
+    has_many  :education_schools,
+              class_name: 'Education::School',
+              dependent: :destroy
+    alias_attribute :schools, :education_schools
+
+    has_many  :education_academic_years,
+              class_name: 'Education::AcademicYear',
+              dependent: :destroy
+    alias_attribute :academic_years, :education_academic_years
   end
 end
diff --git a/app/models/university/with_people_and_organizations.rb b/app/models/university/with_people_and_organizations.rb
index ad270f63a..ad18670f9 100644
--- a/app/models/university/with_people_and_organizations.rb
+++ b/app/models/university/with_people_and_organizations.rb
@@ -2,17 +2,25 @@ module University::WithPeopleAndOrganizations
   extend ActiveSupport::Concern
 
   included do
-    has_many  :people,
+    has_many  :university_people,
               class_name: 'University::Person',
               dependent: :destroy
-    has_many  :organizations,
+    alias_attribute :people, :university_people
+
+    has_many  :university_organizations,
               class_name: 'University::Organization',
               dependent: :destroy
-    has_many  :organization_imports,
+    alias_attribute :organizations, :university_organizations
+
+    has_many  :university_organization_imports,
               class_name: 'University::Organization::Import',
               dependent: :destroy
-    has_many :person_alumnus_imports,
+    alias_attribute :organization_imports, :university_organization_imports
+
+    has_many :university_person_alumnus_imports,
               class_name: 'University::Person::Alumnus::Import',
               dependent: :destroy
+    alias_attribute :person_alumnus_imports, :university_person_alumnus_imports
+    alias_attribute :alumnus_imports, :university_person_alumnus_imports
   end
 end
diff --git a/app/views/extranet/home/index.html.erb b/app/views/extranet/home/index.html.erb
index 3a6a045cb..aa3714a7a 100644
--- a/app/views/extranet/home/index.html.erb
+++ b/app/views/extranet/home/index.html.erb
@@ -2,7 +2,16 @@
 
 <div class="row">
   <div class="col-md-8">
-
+    <h2>Mouvements récents</h2>
+    <% @experiences.each do |experience| %>
+      <article>
+        <%= link_to experience.person, experience.person %>
+        <%= experience.description %>
+        <%= experience.from_year %>
+        <%= experience.to_year %>
+        <%= link_to experience.organization, experience.organization %>
+      </article>
+    <% end %>
   </div>
   <div class="col-md-4">
     <h2>Promotions actuelles</h2>
-- 
GitLab