From 1c5beb9b1bddf5bd78a7bd3d335ba458312ecb04 Mon Sep 17 00:00:00 2001
From: pabois <pierreandre.boissinot@noesya.coop>
Date: Mon, 16 May 2022 17:38:44 +0200
Subject: [PATCH] filters

---
 .../filters/admin/communication/extranets.rb  |  4 ++-
 .../admin/communication/website/posts.rb      | 23 +++++++++++++---
 .../filters/admin/communication/websites.rb   |  4 ++-
 .../filters/admin/education/programs.rb       |  6 ++---
 .../filters/admin/education/schools.rb        |  2 +-
 .../filters/admin/education/teachers.rb       |  2 +-
 .../filters/admin/university/organizations.rb |  4 ++-
 .../filters/admin/university/people.rb        |  4 ++-
 .../filters/admin/university/people/alumni.rb | 22 ++++++++++++++++
 .../filters/admin/university/person/alumni.rb |  8 ------
 app/services/filters/admin/users.rb           |  4 ++-
 .../admin/education/cohorts/show.html.erb     | 26 ++++++++++++-------
 config/locales/education/en.yml               |  3 ++-
 config/locales/education/fr.yml               |  3 ++-
 14 files changed, 82 insertions(+), 33 deletions(-)
 create mode 100644 app/services/filters/admin/university/people/alumni.rb
 delete mode 100644 app/services/filters/admin/university/person/alumni.rb

diff --git a/app/services/filters/admin/communication/extranets.rb b/app/services/filters/admin/communication/extranets.rb
index 059f47780..b91877418 100644
--- a/app/services/filters/admin/communication/extranets.rb
+++ b/app/services/filters/admin/communication/extranets.rb
@@ -3,7 +3,9 @@ module Filters
     def initialize(user)
       super
       add_search
-      add :for_about_type, ::Communication::Extranet::about_types.compact.map { |r| { to_s: I18n.t("activerecord.attributes.communication/extranet.about_#{r}"), id: r } }, I18n.t('filters.attributes.kind')
+      add :for_about_type,
+          ::Communication::Extranet::about_types.compact.map { |r| { to_s: I18n.t("activerecord.attributes.communication/extranet.about_#{r}"), id: r } },
+          I18n.t('filters.attributes.kind')
     end
   end
 end
diff --git a/app/services/filters/admin/communication/website/posts.rb b/app/services/filters/admin/communication/website/posts.rb
index 30559c526..634ee1359 100644
--- a/app/services/filters/admin/communication/website/posts.rb
+++ b/app/services/filters/admin/communication/website/posts.rb
@@ -3,9 +3,26 @@ module Filters
     def initialize(user, website)
       super(user)
       add_search
-      add :for_author, website.authors.ordered, I18n.t('filters.attributes.element', element: I18n.t('activerecord.attributes.communication/website/post.author').downcase)
-      add :for_category, website.categories, I18n.t('filters.attributes.element', element: I18n.t('activerecord.models.communication/website/category.one').downcase), false, true
-      add :for_pinned, [{ to_s: I18n.t('true'), id: 'true' }, { to_s: I18n.t('false'), id: 'false' }], I18n.t('filters.attributes.element', element: I18n.t('admin.communication.website.post.pinned_status').downcase)
+      add :for_author,
+          website.authors.ordered,
+          I18n.t(
+            'filters.attributes.element',
+            element: I18n.t('activerecord.attributes.communication/website/post.author').downcase
+          )
+      add :for_category,
+          website.categories,
+          I18n.t(
+            'filters.attributes.element',
+            element: Communication::Website::Category.model_name.human.downcase
+          ),
+          false,
+          true
+      add :for_pinned,
+          [{ to_s: I18n.t('true'), id: 'true' }, { to_s: I18n.t('false'), id: 'false' }],
+          I18n.t(
+            'filters.attributes.element',
+            element: I18n.t('admin.communication.website.post.pinned_status').downcase
+          )
     end
   end
 end
diff --git a/app/services/filters/admin/communication/websites.rb b/app/services/filters/admin/communication/websites.rb
index 4f43797b3..418264ccc 100644
--- a/app/services/filters/admin/communication/websites.rb
+++ b/app/services/filters/admin/communication/websites.rb
@@ -3,7 +3,9 @@ module Filters
     def initialize(user)
       super
       add_search
-      add :for_about_type, ::Communication::Website::about_types.compact.map { |r| { to_s: I18n.t("activerecord.attributes.communication/website.about_#{r}"), id: r } }, I18n.t('filters.attributes.kind')
+      add :for_about_type,
+          ::Communication::Website::about_types.compact.map { |r| { to_s: I18n.t("activerecord.attributes.communication/website.about_#{r}"), id: r } },
+          I18n.t('filters.attributes.kind')
     end
   end
 end
diff --git a/app/services/filters/admin/education/programs.rb b/app/services/filters/admin/education/programs.rb
index 5680fa3ac..e6eb599cb 100644
--- a/app/services/filters/admin/education/programs.rb
+++ b/app/services/filters/admin/education/programs.rb
@@ -7,10 +7,8 @@ module Filters
           user.university.education_diplomas,
           I18n.t(
             'filters.attributes.element',
-            element: I18n.t('activerecord.models.education/diploma.one').downcase
-          ),
-          false,
-          false
+            element: Education::Diploma.model_name.human.downcase
+          )
     end
   end
 end
diff --git a/app/services/filters/admin/education/schools.rb b/app/services/filters/admin/education/schools.rb
index 89712eb57..ab5c6070e 100644
--- a/app/services/filters/admin/education/schools.rb
+++ b/app/services/filters/admin/education/schools.rb
@@ -7,7 +7,7 @@ module Filters
           user.university.education_programs,
           I18n.t(
             'filters.attributes.element',
-            element: I18n.t('activerecord.models.education/program.one').downcase
+            element: Education::Program.model_name.human.downcase
           ),
           false,
           true
diff --git a/app/services/filters/admin/education/teachers.rb b/app/services/filters/admin/education/teachers.rb
index a6f2a0c04..f7367c36e 100644
--- a/app/services/filters/admin/education/teachers.rb
+++ b/app/services/filters/admin/education/teachers.rb
@@ -7,7 +7,7 @@ module Filters
           user.university.education_programs,
           I18n.t(
             'filters.attributes.element',
-            element: I18n.t('activerecord.models.education/program.one').downcase
+            element: Education::Program.model_name.human.downcase
           ),
           false,
           true
diff --git a/app/services/filters/admin/university/organizations.rb b/app/services/filters/admin/university/organizations.rb
index 85b22cef3..bfd4cbb4f 100644
--- a/app/services/filters/admin/university/organizations.rb
+++ b/app/services/filters/admin/university/organizations.rb
@@ -3,7 +3,9 @@ module Filters
     def initialize(user)
       super
       add_search
-      add :for_kind, ::University::Organization::kinds.keys.map { |r| { to_s: I18n.t("enums.university.organization.kind.#{r}"), id: r } }, I18n.t('filters.attributes.kind')
+      add :for_kind,
+          ::University::Organization::kinds.keys.map { |r| { to_s: I18n.t("enums.university.organization.kind.#{r}"), id: r } },
+          I18n.t('filters.attributes.kind')
     end
   end
 end
diff --git a/app/services/filters/admin/university/people.rb b/app/services/filters/admin/university/people.rb
index 515697eaf..138f8291d 100644
--- a/app/services/filters/admin/university/people.rb
+++ b/app/services/filters/admin/university/people.rb
@@ -3,7 +3,9 @@ module Filters
     def initialize(user)
       super
       add_search
-      add :for_role, ::University::Person::LIST_OF_ROLES.map { |r| { to_s: I18n.t("activerecord.attributes.university/person.#{r}"), id: r } }, I18n.t('filters.attributes.role')
+      add :for_role,
+          ::University::Person::LIST_OF_ROLES.map { |r| { to_s: I18n.t("activerecord.attributes.university/person.#{r}"), id: r } },
+          I18n.t('filters.attributes.role')
     end
   end
 end
diff --git a/app/services/filters/admin/university/people/alumni.rb b/app/services/filters/admin/university/people/alumni.rb
new file mode 100644
index 000000000..6495bda45
--- /dev/null
+++ b/app/services/filters/admin/university/people/alumni.rb
@@ -0,0 +1,22 @@
+module Filters
+  class Admin::University::People::Alumni < Filters::Base
+    def initialize(user)
+      super
+      add_search
+      add :for_program,
+          user.university.education_programs,
+          I18n.t(
+            'filters.attributes.element',
+            element: Education::Program.model_name.human.downcase
+          ),
+          false,
+          true
+      add :for_academic_year,
+          user.university.academic_years.ordered,
+          I18n.t(
+            'filters.attributes.element',
+            element: Education::AcademicYear.model_name.human.downcase
+          )
+    end
+  end
+end
diff --git a/app/services/filters/admin/university/person/alumni.rb b/app/services/filters/admin/university/person/alumni.rb
deleted file mode 100644
index 923f4c5f4..000000000
--- a/app/services/filters/admin/university/person/alumni.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-module Filters
-  class Admin::University::Person::Alumni < Filters::Base
-    def initialize(user)
-      super
-      add_search
-    end
-  end
-end
diff --git a/app/services/filters/admin/users.rb b/app/services/filters/admin/users.rb
index bc431fa8e..543803811 100644
--- a/app/services/filters/admin/users.rb
+++ b/app/services/filters/admin/users.rb
@@ -3,7 +3,9 @@ module Filters
     def initialize(user)
       super
       add_search
-      add :for_role, ::User.roles.keys.map { |r| { to_s: I18n.t("activerecord.attributes.user.roles.#{r}"), id: r } }, I18n.t('filters.attributes.role')
+      add :for_role,
+          ::User.roles.keys.map { |r| { to_s: I18n.t("activerecord.attributes.user.roles.#{r}"), id: r } },
+          I18n.t('filters.attributes.role')
     end
   end
 end
diff --git a/app/views/admin/education/cohorts/show.html.erb b/app/views/admin/education/cohorts/show.html.erb
index f6e8735f6..804ff183e 100644
--- a/app/views/admin/education/cohorts/show.html.erb
+++ b/app/views/admin/education/cohorts/show.html.erb
@@ -1,14 +1,22 @@
 <% content_for :title, @cohort %>
 
-<p>
-  <strong>Program:</strong>
-  <%= link_to @cohort.program, [:admin, @cohort.program] %>
-</p>
-
-<p>
-  <strong>Academic year:</strong>
-  <%= link_to @cohort.academic_year, [:admin, @cohort.academic_year] %>
-</p>
+
+<div class="row">
+  <div class="col-md-8">
+    <div class="card flex-fill w-100">
+      
+      <div class="card-body">
+        <h3 class="h5"><%= Education::Cohort.human_attribute_name('program') %></h3>
+        <p><%= link_to_if can?(:read, @cohort.program), @cohort.program, [:admin, @cohort.program] %></p>
+        <h3 class="h5"><%= Education::Cohort.human_attribute_name('year') %></h3>
+        <p><%= link_to_if can?(:read, @cohort.academic_year), @cohort.academic_year, [:admin, @cohort.academic_year] %></p>
+      </div>
+    </div>
+  </div>
+</div>
+
+
+
 
 <h2><%= University::Person::Alumnus.model_name.human(count: 2) %></h2>
 
diff --git a/config/locales/education/en.yml b/config/locales/education/en.yml
index 3733fcfe1..987d92601 100644
--- a/config/locales/education/en.yml
+++ b/config/locales/education/en.yml
@@ -21,8 +21,9 @@ en:
         other: Schools
     attributes:
       education/cohort:
-        year: Year
         alumni: Alumni
+        program: Program
+        year: Year
       education/diploma:
         name: Name
         short_name: Short name
diff --git a/config/locales/education/fr.yml b/config/locales/education/fr.yml
index ecd791e55..6211e767b 100644
--- a/config/locales/education/fr.yml
+++ b/config/locales/education/fr.yml
@@ -21,8 +21,9 @@ fr:
         other: Écoles
     attributes:
       education/cohort:
-        year: Année
         alumni: Alumni
+        program: Formation
+        year: Année
       education/diploma:
         name: Nom
         short_name: Nom abrégé
-- 
GitLab