From 96c67c4e736ee87552e03ec20fe4b1ab967f85bc Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Mon, 21 Mar 2022 08:41:39 +0100
Subject: [PATCH] enhancements

---
 .../stylesheets/application/layout.sass       | 17 +++++-----
 app/controllers/extranet/home_controller.rb   |  6 ++++
 app/controllers/home_controller.rb            |  5 ---
 app/helpers/application_helper.rb             | 31 +++++++++++++++++++
 .../extranet/application/_footer.html.erb     | 27 ++++++++++++++++
 app/views/extranet/application/_logo.html.erb |  5 +++
 app/views/extranet/application/_nav.html.erb  |  8 +++++
 app/views/extranet/home/index.html.erb        |  5 +++
 .../extranet/layouts/application.html.erb     |  6 ++--
 app/views/extranet/persons/show.html.erb      | 16 +++++++---
 app/views/home/index.html.erb                 |  1 -
 config/routes.rb                              |  7 ++---
 config/routes/extranet.rb                     |  1 +
 13 files changed, 110 insertions(+), 25 deletions(-)
 create mode 100644 app/controllers/extranet/home_controller.rb
 delete mode 100644 app/controllers/home_controller.rb
 create mode 100644 app/views/extranet/application/_footer.html.erb
 create mode 100644 app/views/extranet/application/_logo.html.erb
 create mode 100644 app/views/extranet/application/_nav.html.erb
 create mode 100644 app/views/extranet/home/index.html.erb
 delete mode 100644 app/views/home/index.html.erb

diff --git a/app/assets/stylesheets/application/layout.sass b/app/assets/stylesheets/application/layout.sass
index 0e14173e2..16af462e1 100644
--- a/app/assets/stylesheets/application/layout.sass
+++ b/app/assets/stylesheets/application/layout.sass
@@ -1,11 +1,3 @@
-.navbar
-    margin-bottom: 100px
-    .navbar-brand
-        img
-            max-width: 100px
-
-footer
-    margin-top: 100px
 
 .alert
     padding: .95rem
@@ -13,12 +5,21 @@ footer
         color: #82322F
 
 .extranet
+    .navbar
+        margin-bottom: 100px
+        .navbar-brand
+            img
+                max-width: 100px
     header
         border-bottom: 1px solid
         border-top: 1px solid
         min-height: 160px
         h1, p
             padding-top: 3rem
+    footer
+        margin-top: 100px
+        .logo
+            width: 100px
 
 .breadcrumb
     font-size: 14px
diff --git a/app/controllers/extranet/home_controller.rb b/app/controllers/extranet/home_controller.rb
new file mode 100644
index 000000000..6c0971380
--- /dev/null
+++ b/app/controllers/extranet/home_controller.rb
@@ -0,0 +1,6 @@
+class Extranet::HomeController < Extranet::ApplicationController
+  def index
+    redirect_to admin_root_path unless current_extranet
+    @cohorts = current_university.education_cohorts.ordered.limit(2)
+  end
+end
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
deleted file mode 100644
index 26e35e8c8..000000000
--- a/app/controllers/home_controller.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-class HomeController < ApplicationController
-  def index
-    redirect_to admin_root_path unless current_extranet
-  end
-end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index eb980caee..caddfa3c6 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -11,4 +11,35 @@ module ApplicationHelper
     classes
   end
 
+  def social_website_to_url(string)
+    string = "https://#{string}" unless string.start_with?('http')
+    string.gsub('http://', 'https://')
+  end
+
+  def social_website_to_s(string)
+    string.gsub('http://', '')
+          .gsub('https://', '')
+  end
+
+  def social_linkedin_to_url(string)
+    string.gsub('http://', 'https://')
+  end
+
+  def social_linkedin_to_s(string)
+    string.gsub('http://', 'https://')
+          .gsub('https://www.linkedin.com/in/', '')
+  end
+
+  def social_twitter_to_url(string)
+    string = "https://twitter.com/#{string}" unless 'twitter.com'.in? string
+    string = "https://#{string}" unless string.start_with?('http')
+    string.gsub('http://', 'https://')
+  end
+
+  def social_twitter_to_s(string)
+    string.gsub('http://', 'https://')
+          .gsub('twitter.com', 'https://twitter.com')
+          .gsub('https://www.twitter.com/', 'https://twitter.com/')
+          .gsub('https://twitter.com/', '')
+  end
 end
diff --git a/app/views/extranet/application/_footer.html.erb b/app/views/extranet/application/_footer.html.erb
new file mode 100644
index 000000000..309bb5e8b
--- /dev/null
+++ b/app/views/extranet/application/_footer.html.erb
@@ -0,0 +1,27 @@
+<footer class="pt-5">
+  <div class="container text-center">
+    <div class="mb-5">
+      <%= render 'logo' %>
+    </div>
+    <nav class="nav justify-content-center">
+      <%= link_to t('terms_of_service'),
+                  t('terms_of_service_url'),
+                  class: 'nav-link',
+                  target: '_blank',
+                  rel: 'noreferrer' %>
+      <%= link_to t('privacy_policy'),
+                  t('privacy_policy_url'),
+                  class: 'nav-link',
+                  target: '_blank',
+                  rel: 'noreferrer' %>
+      <%= link_to t('cookies_policy'),
+                  t('cookies_policy_url'),
+                  class: 'nav-link',
+                  target: '_blank',
+                  rel: 'noreferrer' %>
+      <%= link_to t('cookies_consent_choice'),
+                  '',
+                  class: 'nav-link js-gdpr__cookie_consent__display_again' %>
+    </nav>
+  </div>
+</footer>
diff --git a/app/views/extranet/application/_logo.html.erb b/app/views/extranet/application/_logo.html.erb
new file mode 100644
index 000000000..210b23932
--- /dev/null
+++ b/app/views/extranet/application/_logo.html.erb
@@ -0,0 +1,5 @@
+<% if current_context.logo.attached? %>
+  <%= image_tag current_context.logo, width: 200, alt: current_context.to_s, class: 'logo' %>
+<% else %>
+  <%= current_context %>
+<% end %>
diff --git a/app/views/extranet/application/_nav.html.erb b/app/views/extranet/application/_nav.html.erb
new file mode 100644
index 000000000..2263f5391
--- /dev/null
+++ b/app/views/extranet/application/_nav.html.erb
@@ -0,0 +1,8 @@
+<nav class="navbar navbar-light">
+  <div class="container">
+    <a class="navbar-brand" href="/">
+      <%= render 'logo' %>
+    </a>
+    <%= render_navigation %>
+  </div>
+</nav>
diff --git a/app/views/extranet/home/index.html.erb b/app/views/extranet/home/index.html.erb
new file mode 100644
index 000000000..d2c5b6045
--- /dev/null
+++ b/app/views/extranet/home/index.html.erb
@@ -0,0 +1,5 @@
+<% content_for :title, current_context %>
+
+<h2><%= Education::Cohort.model_name.human(count: 2) %></h2>
+<p><%= link_to 'Voir toutes les promotions', education_cohorts_path %></p>
+<%= render 'extranet/cohorts/list', cohorts: @cohorts %>
diff --git a/app/views/extranet/layouts/application.html.erb b/app/views/extranet/layouts/application.html.erb
index 1d50fec29..74bf7b45c 100644
--- a/app/views/extranet/layouts/application.html.erb
+++ b/app/views/extranet/layouts/application.html.erb
@@ -11,12 +11,12 @@
     <%= favicon_link_tag 'favicon.png' %>
   </head>
   <body class="extranet <%= body_classes %>">
-    <%= render 'nav' %>
+    <%= render 'extranet/application/nav' %>
     <main class="container">
-      <%= render_breadcrumbs builder: Appstack::BreadcrumbsOnRailsBuilder %>
+      <%= render_breadcrumbs builder: Appstack::BreadcrumbsOnRailsBuilder if breadcrumbs.any? %>
       <%= yield %>
     </main>
-    <%= render 'footer' %>
+    <%= render 'extranet/application/footer' %>
     <%= render 'gdpr/cookie_consent' %>
     <%= render 'bugsnag' %>
   </body>
diff --git a/app/views/extranet/persons/show.html.erb b/app/views/extranet/persons/show.html.erb
index fe745e11e..9cedca1d9 100644
--- a/app/views/extranet/persons/show.html.erb
+++ b/app/views/extranet/persons/show.html.erb
@@ -35,17 +35,25 @@
       <% end %>
       <% if @person.url %>
         <dt><%= University::Person.human_attribute_name(:url) %></dt>
-        <dd><a href="<%= @person.url %>" target="_blank" rel="noreferrer"><%= @person.url %></a></dd>
+        <dd>
+          <a href="<%= social_website_to_url @person.url %>" target="_blank" rel="noreferrer">
+            <%= social_website_to_s @person.url %>
+          </a>
+        </dd>
       <% end %>
       <% if @person.linkedin %>
         <dt><%= University::Person.human_attribute_name(:linkedin) %></dt>
-        <dd><a href="<%= @person.linkedin %>" target="_blank" rel="noreferrer"><%= @person.linkedin %></a></dd>
+        <dd>
+          <a href="<%= social_linkedin_to_url @person.linkedin %>" target="_blank" rel="noreferrer">
+            <%= social_linkedin_to_s @person.linkedin %>
+          </a>
+        </dd>
       <% end %>
       <% if @person.twitter %>
         <dt><%= University::Person.human_attribute_name(:twitter) %></dt>
         <dd>
-          <a href="<%= @person.twitter %>" target="_blank" rel="noreferrer">
-            <%= @person.twitter.gsub('https://twitter.com/', '') %>
+          <a href="<%= social_twitter_to_url @person.twitter %>" target="_blank" rel="noreferrer">
+            <%= social_twitter_to_s @person.twitter %>
           </a>
         </dd>
       <% end %>
diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb
deleted file mode 100644
index 18a3f18dc..000000000
--- a/app/views/home/index.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-<% content_for :title, current_context %>
diff --git a/config/routes.rb b/config/routes.rb
index c6a0a9514..5f10a141b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -29,10 +29,9 @@ Rails.application.routes.draw do
     root to: 'dashboard#index'
   end
 
-  draw 'extranet'
-  draw 'api'
-
   get '/media/:signed_id/:filename_with_transformations' => 'media#show', as: :medium
 
-  root to: 'home#index'
+  draw 'api'
+  draw 'extranet'
+  # Root is in extranet
 end
diff --git a/config/routes/extranet.rb b/config/routes/extranet.rb
index 1fd34eb0f..2afd7680e 100644
--- a/config/routes/extranet.rb
+++ b/config/routes/extranet.rb
@@ -6,3 +6,4 @@ get 'persons'           => 'extranet/persons#index', as: :university_persons
 get 'persons/:id'       => 'extranet/persons#show', as: :university_person
 get 'years'             => 'extranet/academic_years#index', as: :education_academic_years
 get 'years/:id'         => 'extranet/academic_years#show', as: :education_academic_year
+root to: 'extranet/home#index'
-- 
GitLab