From b6cb2ef1002cd8af5947e2be8e4e4ff771662d7e Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Thu, 1 Dec 2022 10:17:20 +0100
Subject: [PATCH] data

---
 app/controllers/extranet/pages_controller.rb  | 23 +++++++++++++++++--
 app/models/communication/extranet.rb          |  9 ++++++++
 .../extranet/application/_footer.html.erb     |  6 +++--
 app/views/extranet/pages/data.html.erb        | 13 +++++++++++
 ...rms_of_service.html.erb => terms.html.erb} |  0
 config/locales/extranet/en.yml                |  3 ++-
 config/locales/extranet/fr.yml                |  3 ++-
 config/routes/extranet.rb                     |  3 ++-
 8 files changed, 53 insertions(+), 7 deletions(-)
 create mode 100644 app/views/extranet/pages/data.html.erb
 rename app/views/extranet/pages/{terms_of_service.html.erb => terms.html.erb} (100%)

diff --git a/app/controllers/extranet/pages_controller.rb b/app/controllers/extranet/pages_controller.rb
index 90cfe247f..1cb2242cc 100644
--- a/app/controllers/extranet/pages_controller.rb
+++ b/app/controllers/extranet/pages_controller.rb
@@ -1,12 +1,31 @@
 class Extranet::PagesController < Extranet::ApplicationController
   skip_before_action :authenticate_user!, :authorize_extranet_access!
 
-  def termes_of_use
+  def terms
+    breadcrumb
+    add_breadcrumb Communication::Extranet.human_attribute_name('terms')
   end
 
-  def cookie_policy
+  def cookies_policy
+    breadcrumb
+    add_breadcrumb Communication::Extranet.human_attribute_name('cookies_policy')
   end
 
   def privacy_policy
+    breadcrumb
+    add_breadcrumb Communication::Extranet.human_attribute_name('privacy_policy')
+  end
+
+  def data
+    @metrics = [
+      { value: current_extranet.alumni.count, name: University::Person::Alumnus.model_name.human(count: 2) },
+      { value: current_extranet.users.count, name: User.model_name.human(count: 2) },
+      { value: current_extranet.experiences.count, name: University::Person::Experience.model_name.human(count: 2) },
+      { value: current_extranet.academic_years.count, name: Education::AcademicYear.model_name.human(count: 2) },
+      { value: current_extranet.cohorts.count, name: Education::Cohort.model_name.human(count: 2) },
+      { value: current_extranet.organizations.count, name: University::Organization.model_name.human(count: 2) },
+    ]
+    breadcrumb
+    add_breadcrumb t('extranet.data')
   end
 end
diff --git a/app/models/communication/extranet.rb b/app/models/communication/extranet.rb
index f87f08024..71e23cb66 100644
--- a/app/models/communication/extranet.rb
+++ b/app/models/communication/extranet.rb
@@ -68,6 +68,10 @@ class Communication::Extranet < ApplicationRecord
     about&.university_person_alumni
   end
 
+  def users
+    university.users.where(person: alumni)
+  end
+
   def cohorts
     about&.cohorts
   end
@@ -75,11 +79,16 @@ class Communication::Extranet < ApplicationRecord
   def years
     about&.academic_years
   end
+  alias academic_years years
 
   def organizations
     about&.alumni_organizations
   end
 
+  def experiences
+    about&.alumni_experiences
+  end
+
   def url
     @url ||= Rails.env.development? ? "http://#{host}:3000" : "https://#{host}"
   end
diff --git a/app/views/extranet/application/_footer.html.erb b/app/views/extranet/application/_footer.html.erb
index 9a834c258..3768ffa80 100644
--- a/app/views/extranet/application/_footer.html.erb
+++ b/app/views/extranet/application/_footer.html.erb
@@ -23,12 +23,11 @@
             <span itemprop="name"><%= current_extranet.about.name %></span>
           </div>
         <% end %>
-        <p class="my-5"><%= t 'extranet.osuny_html' %></p>
       </div>
 
       <nav class="text-md-end col-md-6">
         <%= link_to t('terms_of_service'),
-                    terms_of_service_path,
+                    terms_path,
                     target: '_blank',
                     rel: 'noreferrer' if current_extranet.has_terms? %>
         <%= link_to t('privacy_policy'),
@@ -39,9 +38,12 @@
                     cookies_policy_path,
                     target: '_blank',
                     rel: 'noreferrer' if current_extranet.has_cookies_policy? %>
+        <%= link_to t('extranet.data'), data_path %>
         <%= link_to t('cookies_consent_choice'),
                     '',
                     class: 'js-gdpr__cookie_consent__display_again' %>
+                  
+        <%= t 'extranet.osuny_html' %>
       </nav>
     </div>
 
diff --git a/app/views/extranet/pages/data.html.erb b/app/views/extranet/pages/data.html.erb
new file mode 100644
index 000000000..9829d185e
--- /dev/null
+++ b/app/views/extranet/pages/data.html.erb
@@ -0,0 +1,13 @@
+<% content_for :title, t('extranet.data') %>
+<% content_for :header do %>
+  <h1><%= t('extranet.data') %></h1>
+<% end %>
+
+<div class="row">
+  <% @metrics.each do |metric| %>
+  <div class="col-md-3">
+    <p class="h1 mb-0"><%= metric[:value] %></p>
+    <p><%= metric[:name] %></p>
+  </div>
+  <% end %>
+</div>
\ No newline at end of file
diff --git a/app/views/extranet/pages/terms_of_service.html.erb b/app/views/extranet/pages/terms.html.erb
similarity index 100%
rename from app/views/extranet/pages/terms_of_service.html.erb
rename to app/views/extranet/pages/terms.html.erb
diff --git a/config/locales/extranet/en.yml b/config/locales/extranet/en.yml
index d8597928c..bd6694da2 100644
--- a/config/locales/extranet/en.yml
+++ b/config/locales/extranet/en.yml
@@ -6,6 +6,7 @@ en:
       edit_personal_data: Edit profile
       updated: Updated
       logout: Log out
+    data: Data
     errors:
       email_not_allowed: is not authorized to access this extranet.
       email_not_allowed_with_contact: is not authorized to access this extranet. Contact %{contact} for more information.
@@ -19,7 +20,7 @@ en:
     organization:
       experiences: Alumni in this organization (%{count})
     osuny_html:
-      Crafted with <a href="https://www.osuny.org" target="_blank" rel="noreferer">Osuny</a>
+      <a href="https://www.osuny.org" target="_blank" rel="noreferer">Crafted with ♥ and with Osuny</a>
     personal_data:
       title: My personal data
       updated: Your personal data has been updated!
diff --git a/config/locales/extranet/fr.yml b/config/locales/extranet/fr.yml
index 68565aeed..8b94b1539 100644
--- a/config/locales/extranet/fr.yml
+++ b/config/locales/extranet/fr.yml
@@ -6,6 +6,7 @@ fr:
       edit_personal_data: Modifier mon profil
       updated: Mise à jour effectuée
       logout: Déconnexion
+    data: Informations
     errors:
       email_not_allowed: n'est pas autorisé à accéder à cet extranet.
       email_not_allowed_with_contact: n'est pas autorisé à accéder à cet extranet. Contactez %{contact} pour en savoir plus.
@@ -20,7 +21,7 @@ fr:
     organization:
       experiences: Alumni dans cette organisation (%{count})
     osuny_html:
-      Développé avec <a href="https://www.osuny.org" target="_blank" rel="noreferer">Osuny</a>
+      <a href="https://www.osuny.org" target="_blank" rel="noreferer">Développé avec ♥ et avec Osuny</a>
     personal_data:
       edit: Modifier
       title: Mes données personnelles
diff --git a/config/routes/extranet.rb b/config/routes/extranet.rb
index 3d5d9c7c7..7ee4169e1 100644
--- a/config/routes/extranet.rb
+++ b/config/routes/extranet.rb
@@ -15,7 +15,8 @@ scope :account do
   get 'personal_data' => 'extranet/personal_data#edit', as: :edit_personal_data
   patch 'personal_data' => 'extranet/personal_data#update', as: :personal_data
 end
-get 'terms-of-service' => 'extranet/pages#terms_of_service', as: :terms_of_service
+get 'terms' => 'extranet/pages#terms', as: :terms
 get 'privacy-policy' => 'extranet/pages#privacy_policy', as: :privacy_policy
 get 'cookies-policy' => 'extranet/pages#cookies_policy', as: :cookies_policy
+get 'data' => 'extranet/pages#data', as: :data
 root to: 'extranet/home#index'
-- 
GitLab