From f2c64995c002a3ca814c39bd66fa30d4363a3a0d Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Fri, 21 Jan 2022 10:24:18 +0100
Subject: [PATCH] short names

---
 .../admin/research/laboratory/axes_controller.rb      |  2 +-
 app/models/research/laboratory/axis.rb                |  1 +
 .../admin/research/laboratory/axes/_form.html.erb     | 11 +++++++++--
 .../admin/research/laboratory/axes/_list.html.erb     |  2 ++
 .../admin/research/laboratory/axes/show.html.erb      |  6 +++++-
 config/locales/research/en.yml                        |  1 +
 config/locales/research/fr.yml                        |  1 +
 ...1710_add_short_name_to_research_laboratory_axes.rb |  5 +++++
 db/schema.rb                                          |  3 ++-
 docs/research/{labs.md => laboratories.md}            |  2 +-
 docs/research/readme.md                               |  1 +
 test/fixtures/research/laboratory/axes.yml            |  1 +
 test/fixtures/research/theses.yml                     |  1 -
 test/models/research/laboratory/axis_test.rb          |  1 +
 14 files changed, 31 insertions(+), 7 deletions(-)
 create mode 100644 db/migrate/20220121091710_add_short_name_to_research_laboratory_axes.rb
 rename docs/research/{labs.md => laboratories.md} (99%)

diff --git a/app/controllers/admin/research/laboratory/axes_controller.rb b/app/controllers/admin/research/laboratory/axes_controller.rb
index 4405e1334..293def8bc 100644
--- a/app/controllers/admin/research/laboratory/axes_controller.rb
+++ b/app/controllers/admin/research/laboratory/axes_controller.rb
@@ -55,7 +55,7 @@ class Admin::Research::Laboratory::AxesController < Admin::Research::Laboratory:
 
   def axis_params
     params.require(:research_laboratory_axis)
-          .permit(:name, :description, :text)
+          .permit(:name, :short_name, :description, :text)
           .merge(university_id: current_university.id)
   end
 end
diff --git a/app/models/research/laboratory/axis.rb b/app/models/research/laboratory/axis.rb
index 6d8a63d94..6646631c4 100644
--- a/app/models/research/laboratory/axis.rb
+++ b/app/models/research/laboratory/axis.rb
@@ -6,6 +6,7 @@
 #  description            :text
 #  name                   :string
 #  position               :integer
+#  short_name             :string
 #  created_at             :datetime         not null
 #  updated_at             :datetime         not null
 #  research_laboratory_id :uuid             not null
diff --git a/app/views/admin/research/laboratory/axes/_form.html.erb b/app/views/admin/research/laboratory/axes/_form.html.erb
index 90a3730ae..1528df4da 100644
--- a/app/views/admin/research/laboratory/axes/_form.html.erb
+++ b/app/views/admin/research/laboratory/axes/_form.html.erb
@@ -6,8 +6,15 @@
           <h5 class="card-title mb-0"><%= t('content') %></h5>
         </div>
         <div class="card-body">
-          <%= f.input :name %>
-          <%= f.input :description, as: :text, input_html: { rows: 8 } %>
+          <div class="row">
+            <div class="col-lg-8 col-xxl-9">
+              <%= f.input :name %>
+            </div>
+            <div class="col-lg-4 col-xxl-3">
+              <%= f.input :short_name %>
+            </div>
+          </div>
+          <%= f.input :description, as: :text, input_html: { rows: 2 } %>
           <%= f.input :text, as: :rich_text_area %>
         </div>
       </div>
diff --git a/app/views/admin/research/laboratory/axes/_list.html.erb b/app/views/admin/research/laboratory/axes/_list.html.erb
index 659fe3fa8..baf2e27f8 100644
--- a/app/views/admin/research/laboratory/axes/_list.html.erb
+++ b/app/views/admin/research/laboratory/axes/_list.html.erb
@@ -2,6 +2,7 @@
   <thead>
     <tr>
       <th><%= Research::Laboratory::Axis.model_name.human %></th>
+      <th><%= Research::Laboratory::Axis.human_attribute_name('short_name') %></th>
       <th></th>
     </tr>
   </thead>
@@ -11,6 +12,7 @@
         <td>
           <%= link_to axis, admin_research_laboratory_axis_path(laboratory_id: axis.laboratory, id: axis) %>
         </td>
+        <td><%= axis.short_name %></td>
         <td class="text-end">
           <div class="btn-group" role="group">
             <%= link_to t('edit'),
diff --git a/app/views/admin/research/laboratory/axes/show.html.erb b/app/views/admin/research/laboratory/axes/show.html.erb
index fe8467edb..33a33613f 100644
--- a/app/views/admin/research/laboratory/axes/show.html.erb
+++ b/app/views/admin/research/laboratory/axes/show.html.erb
@@ -7,7 +7,11 @@
         <h2 class="card-title mb-0 h5"><%= t('content') %></h2>
       </div>
       <div class="card-body">
-        <h3 class="h5"><%= Research::Laboratory::Axis.human_attribute_name('description') %></h3>
+        <% unless @axis.short_name.empty? %>
+        <h3 class="h5"><%= Research::Laboratory::Axis.human_attribute_name('short_name') %></h3>
+        <%= @axis.short_name %>
+        <% end %>
+        <h3 class="h5 mt-4"><%= Research::Laboratory::Axis.human_attribute_name('description') %></h3>
         <%= simple_format @axis.description %>
         <h3 class="h5 mt-4"><%= Research::Laboratory::Axis.human_attribute_name('text') %></h3>
         <%= @axis.text %>
diff --git a/config/locales/research/en.yml b/config/locales/research/en.yml
index a19815bd5..94f59dae5 100644
--- a/config/locales/research/en.yml
+++ b/config/locales/research/en.yml
@@ -54,6 +54,7 @@ en:
       research/laboratory/axis:
         description: Description
         name: Name
+        short_name: Short name
         text: Text
       research/thesis:
         abstract: Abstract
diff --git a/config/locales/research/fr.yml b/config/locales/research/fr.yml
index 926719c22..09c945a1d 100644
--- a/config/locales/research/fr.yml
+++ b/config/locales/research/fr.yml
@@ -54,6 +54,7 @@ fr:
       research/laboratory/axis:
         description: Description
         name: Nom
+        short_name: Nom court
         text: Texte
       research/thesis:
         abstract: Résumé
diff --git a/db/migrate/20220121091710_add_short_name_to_research_laboratory_axes.rb b/db/migrate/20220121091710_add_short_name_to_research_laboratory_axes.rb
new file mode 100644
index 000000000..2eac65d6e
--- /dev/null
+++ b/db/migrate/20220121091710_add_short_name_to_research_laboratory_axes.rb
@@ -0,0 +1,5 @@
+class AddShortNameToResearchLaboratoryAxes < ActiveRecord::Migration[6.1]
+  def change
+    add_column :research_laboratory_axes, :short_name, :string
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 4e703ecb1..fb97bdc1e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2022_01_20_111315) do
+ActiveRecord::Schema.define(version: 2022_01_21_091710) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
@@ -519,6 +519,7 @@ ActiveRecord::Schema.define(version: 2022_01_20_111315) do
     t.integer "position"
     t.datetime "created_at", precision: 6, null: false
     t.datetime "updated_at", precision: 6, null: false
+    t.string "short_name"
     t.index ["research_laboratory_id"], name: "index_research_laboratory_axes_on_research_laboratory_id"
     t.index ["university_id"], name: "index_research_laboratory_axes_on_university_id"
   end
diff --git a/docs/research/labs.md b/docs/research/laboratories.md
similarity index 99%
rename from docs/research/labs.md
rename to docs/research/laboratories.md
index 1afb3e27f..927694980 100644
--- a/docs/research/labs.md
+++ b/docs/research/laboratories.md
@@ -1,4 +1,4 @@
-# Labs
+# Laboratories
 
 ## Axes (research axis/axes) ou équipes
 
diff --git a/docs/research/readme.md b/docs/research/readme.md
index 30e0c0348..36b8e6529 100644
--- a/docs/research/readme.md
+++ b/docs/research/readme.md
@@ -20,6 +20,7 @@
 - university:references
 - research_laboratory:references
 - name:string
+- short_name:string
 - position:integer
 - description:text
 - text:html
diff --git a/test/fixtures/research/laboratory/axes.yml b/test/fixtures/research/laboratory/axes.yml
index 15041de82..9d34e7ee3 100644
--- a/test/fixtures/research/laboratory/axes.yml
+++ b/test/fixtures/research/laboratory/axes.yml
@@ -6,6 +6,7 @@
 #  description            :text
 #  name                   :string
 #  position               :integer
+#  short_name             :string
 #  created_at             :datetime         not null
 #  updated_at             :datetime         not null
 #  research_laboratory_id :uuid             not null
diff --git a/test/fixtures/research/theses.yml b/test/fixtures/research/theses.yml
index 922ad5511..6c76eb0cc 100644
--- a/test/fixtures/research/theses.yml
+++ b/test/fixtures/research/theses.yml
@@ -29,7 +29,6 @@
 #  fk_rails_...  (research_laboratory_id => research_laboratories.id)
 #  fk_rails_...  (university_id => universities.id)
 #
-# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
 
 one:
   university: one
diff --git a/test/models/research/laboratory/axis_test.rb b/test/models/research/laboratory/axis_test.rb
index a4228e54f..f9f0d6ea7 100644
--- a/test/models/research/laboratory/axis_test.rb
+++ b/test/models/research/laboratory/axis_test.rb
@@ -6,6 +6,7 @@
 #  description            :text
 #  name                   :string
 #  position               :integer
+#  short_name             :string
 #  created_at             :datetime         not null
 #  updated_at             :datetime         not null
 #  research_laboratory_id :uuid             not null
-- 
GitLab