From 6d56afc0da5c4f8caff9971c0d81326dd21fa0ea Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Wed, 11 Aug 2021 15:54:56 +0200
Subject: [PATCH] clean

---
 .../application_controller/with_context.rb           |  8 ++++++--
 app/helpers/admin/application_helper.rb              |  8 ++++----
 app/views/adminserver/universities/index.html.erb    |  2 +-
 app/views/application/_footer.html.erb               |  5 +++++
 app/views/application/_nav.html.erb                  | 11 +++++++++++
 app/views/layouts/application.html.erb               | 12 +++---------
 config/locales/fr.yml                                |  2 ++
 7 files changed, 32 insertions(+), 16 deletions(-)
 create mode 100644 app/views/application/_footer.html.erb
 create mode 100644 app/views/application/_nav.html.erb

diff --git a/app/controllers/application_controller/with_context.rb b/app/controllers/application_controller/with_context.rb
index 160385d90..869b62661 100644
--- a/app/controllers/application_controller/with_context.rb
+++ b/app/controllers/application_controller/with_context.rb
@@ -4,12 +4,16 @@ module ApplicationController::WithContext
   included do
 
     def current_university
-        @current_university ||= University.with_host(request.host)
+      unless @current_university
+        @current_university = current_website ? current_website.university
+                                              : University.with_host(request.host)
+      end
+      @current_university
     end
     helper_method :current_university
 
     def current_website
-        @current_website ||= Features::Websites::Site.with_host(request.host)
+      @current_website ||= Features::Websites::Site.with_host(request.host)
     end
     helper_method :current_website
 
diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb
index b98bccfb7..b8ba504d6 100644
--- a/app/helpers/admin/application_helper.rb
+++ b/app/helpers/admin/application_helper.rb
@@ -7,21 +7,21 @@ module Admin::ApplicationHelper
 
   def show_link(object, **options)
     link_to_if  can?(:read, object),
-                options.delete(:label) || 'Voir',
+                options.delete(:label) || t('show'),
                 polymorphic_url_param(object, **options),
                 class: button_classes
   end
 
   def edit_link(object, **options)
     return unless can?(:update, object)
-    link_to options.delete(:label) || 'Modifier',
+    link_to options.delete(:label) || t('edit'),
             polymorphic_url_param(object, prefix: :edit, **options),
             class: button_classes
   end
 
   def destroy_link(object, **options)
     return unless can?(:destroy, object)
-    link_to options.delete(:label) || 'Supprimer',
+    link_to options.delete(:label) || t('delete'),
             polymorphic_url_param(object, **options),
             method: :delete,
             data: { confirm: 'Êtes-vous certain ?' },
@@ -32,7 +32,7 @@ module Admin::ApplicationHelper
     return unless can?(:create, object_class)
     object_class_sym = object_class.name.underscore.gsub('/', '_').to_sym
 
-    link_to options.delete(:label) || 'Créer',
+    link_to options.delete(:label) || t('create'),
             polymorphic_url_param(object_class_sym, prefix: :new, **options),
             class: button_classes
   end
diff --git a/app/views/adminserver/universities/index.html.erb b/app/views/adminserver/universities/index.html.erb
index f9a375941..41ae95471 100644
--- a/app/views/adminserver/universities/index.html.erb
+++ b/app/views/adminserver/universities/index.html.erb
@@ -24,5 +24,5 @@
 </table>
 
 <% content_for :buttons do %>
-  <%= create_link University %>
+  <%= link_to t('create'), new_adminserver_university_path, class: button_classes %>
 <% end %>
diff --git a/app/views/application/_footer.html.erb b/app/views/application/_footer.html.erb
new file mode 100644
index 000000000..3eacc69e9
--- /dev/null
+++ b/app/views/application/_footer.html.erb
@@ -0,0 +1,5 @@
+<footer>
+  <div class="container small">
+    <%= current_university %>
+  </div>
+</footer>
diff --git a/app/views/application/_nav.html.erb b/app/views/application/_nav.html.erb
new file mode 100644
index 000000000..e36e224d7
--- /dev/null
+++ b/app/views/application/_nav.html.erb
@@ -0,0 +1,11 @@
+<nav class="navbar navbar-light">
+  <div class="container">
+    <a class="navbar-brand" href="/">
+      <% if current_website %>
+        <%= current_website %><br>
+      <% else %>
+        <%= current_university %>
+      <% end %>
+    </a>
+  </div>
+</nav>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index e4f5be40e..7981d2b48 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -10,17 +10,11 @@
     <%= javascript_include_tag 'application' %>
   </head>
   <body>
-    <nav>
-      <div class="container-fluid text-center">
-        <% if current_website %>
-        Site: <%= current_website %><br>
-        <% end %>
-        University: <%= current_university %>
-      </div>
-    </nav>
-    <main class="container-fluid">
+    <%= render 'nav' %>
+    <main class="container">
       <%= render_breadcrumbs builder: Appstack::BreadcrumbsOnRailsBuilder %>
       <%= yield %>
     </main>
+    <%= render 'footer' %>
   </body>
 </html>
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index 93c8c1875..9e129820f 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -2,6 +2,8 @@ fr:
   true: Oui
   false: Non
   dashboard: Tableau de bord
+  show: Voir
+  create: Créer
   edit: Modifier
   delete: Supprimer
   activerecord:
-- 
GitLab