From ce27b2bcc29b60f471f3e9528e4c41eab0439876 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Tue, 26 Oct 2021 07:00:07 +0200
Subject: [PATCH] school website

---
 app/models/communication/website.rb               |  2 +-
 app/models/education/school.rb                    |  1 +
 .../admin/communication/websites/_form.html.erb   |  2 ++
 .../admin/communication/websites/show.html.erb    |  6 ++++--
 app/views/admin/education/schools/show.html.erb   |  8 ++++++++
 app/views/admin/research/journals/show.html.erb   | 15 ++++++++-------
 config/locales/communication/en.yml               |  2 +-
 config/locales/communication/fr.yml               |  2 +-
 config/locales/research/en.yml                    |  1 +
 config/locales/research/fr.yml                    |  1 +
 10 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb
index dc9397701..c41cac826 100644
--- a/app/models/communication/website.rb
+++ b/app/models/communication/website.rb
@@ -32,7 +32,7 @@ class Communication::Website < ApplicationRecord
           dependent: :destroy
 
   def self.about_types
-    [nil, Research::Journal.name]
+    [nil, Education::School.name, Research::Journal.name]
   end
 
   def domain_url
diff --git a/app/models/education/school.rb b/app/models/education/school.rb
index f5352ef5a..422d7f102 100644
--- a/app/models/education/school.rb
+++ b/app/models/education/school.rb
@@ -24,6 +24,7 @@
 #
 class Education::School < ApplicationRecord
   belongs_to :university
+  has_one :website, class_name: 'Communication::Website', foreign_key: :about
 
   def to_s
     "#{name}"
diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb
index 3ad7c36fa..c9cf878a4 100644
--- a/app/views/admin/communication/websites/_form.html.erb
+++ b/app/views/admin/communication/websites/_form.html.erb
@@ -13,6 +13,8 @@
         case website.about_type
         when Research::Journal.name
           collection = current_university.research_journals
+        when Education::School.name
+          collection = current_university.education_schools
         end
       %>
         <%= f.input :about_id,
diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb
index 2a7724826..38ef5110d 100644
--- a/app/views/admin/communication/websites/show.html.erb
+++ b/app/views/admin/communication/websites/show.html.erb
@@ -1,9 +1,11 @@
 <% content_for :title, @website %>
 
 <% content_for :title_right do %>
-  <%= link_to @website.domain_url, @website.domain_url, target: :_blank %><br>
+  <% unless @website.domain.blank? %>
+    <%= link_to @website.domain_url, @website.domain_url, target: :_blank %><br>
+  <% end %>
   <%= I18n.t("activerecord.attributes.communication/website.about_#{@website.about_type}") %>
-  <%= link_to @website.about, [:admin, @website.about] unless @website.about.nil? %>
+  (<%= link_to @website.about, [:admin, @website.about] unless @website.about.nil? %>)
 <% end %>
 
 <div class="card mt-5">
diff --git a/app/views/admin/education/schools/show.html.erb b/app/views/admin/education/schools/show.html.erb
index 948820033..2947ba58b 100644
--- a/app/views/admin/education/schools/show.html.erb
+++ b/app/views/admin/education/schools/show.html.erb
@@ -1,5 +1,13 @@
 <% content_for :title, @school %>
 
+<% content_for :title_right do %>
+  <% if @school.website %>
+    <%= Communication::Website.model_name.human %>
+    <i class="fas fa-arrow-right small"></i>
+    <%= link_to @school.website, [:admin, @school.website] %><br>
+  <% end %>
+<% end %>
+
 <p>
   <%= @school.address %><br>
   <%= @school.zipcode %> <%= @school.city %><br>
diff --git a/app/views/admin/research/journals/show.html.erb b/app/views/admin/research/journals/show.html.erb
index 5104e3505..674a37a04 100644
--- a/app/views/admin/research/journals/show.html.erb
+++ b/app/views/admin/research/journals/show.html.erb
@@ -1,14 +1,15 @@
 <% content_for :title, @journal %>
 
-<p>ISSN : <%= @journal.issn %></p>
-
-<% if @journal.website %>
-  <p>
-    Site :
-    <%= link_to @journal.website, [:admin, @journal.website] %>
-  </p>
+<% content_for :title_right do %>
+  <% if @journal.website %>
+    <%= Communication::Website.model_name.human %>
+    <i class="fas fa-arrow-right small"></i>
+    <%= link_to @journal.website, [:admin, @journal.website] %><br>
+  <% end %>
+  <% if @journal.issn %><%= Research::Journal.human_attribute_name('issn') %> <%= @journal.issn %><% end %>
 <% end %>
 
+
 <div class="card mt-5">
   <div class="card-header">
     <div class="float-end">
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index 1484428fb..436711bfc 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -40,7 +40,7 @@ en:
         about_type: About
         about_: Nothing (independent website)
         about_Research::Journal: Journal website
-        about_School: School website
+        about_Education::School: School website
       communication/website/imported/medium:
         filename: Filename
       communication/website/page:
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index 8bc2e040f..1faa0dfd9 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -40,7 +40,7 @@ fr:
         about_type: Sujet du site
         about_: Aucun sujet (site indépendant)
         about_Research::Journal: Site de revue scientifique
-        about_School: Site d'école
+        about_Education::School: Site d'école
       communication/website/imported/medium:
         filename: Nom du fichier
       communication/website/page:
diff --git a/config/locales/research/en.yml b/config/locales/research/en.yml
index 986e1e44d..b135f9ccb 100644
--- a/config/locales/research/en.yml
+++ b/config/locales/research/en.yml
@@ -19,6 +19,7 @@ en:
     attributes:
       research/journal:
         title: Title
+        issn: ISSN
       research/journal/article:
         title: Title
         researchers: Authors
diff --git a/config/locales/research/fr.yml b/config/locales/research/fr.yml
index 69b5a7228..8bc0da529 100644
--- a/config/locales/research/fr.yml
+++ b/config/locales/research/fr.yml
@@ -19,6 +19,7 @@ fr:
     attributes:
       research/journal:
         title: Titre
+        issn: ISSN
       research/journal/article:
         title: Titre
         researchers: Auteu·rs·rices
-- 
GitLab