From 35827117e01b8084bcaee77027274472e126e96e Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Wed, 19 Oct 2022 09:31:10 +0200
Subject: [PATCH] better extranet

---
 app/assets/stylesheets/extranet.sass          |  3 ++-
 .../stylesheets/extranet/bootstrap-icons.sass |  5 +++++
 .../extranet/cohorts/_index.cards.html.erb    | 21 +++++++++++++++++++
 .../extranet/cohorts/_index.facets.html.erb   |  8 +++++++
 app/views/extranet/cohorts/index.html.erb     | 13 +++++-------
 package.json                                  |  1 +
 yarn.lock                                     |  5 +++++
 7 files changed, 47 insertions(+), 9 deletions(-)
 create mode 100644 app/assets/stylesheets/extranet/bootstrap-icons.sass
 create mode 100644 app/views/extranet/cohorts/_index.cards.html.erb
 create mode 100644 app/views/extranet/cohorts/_index.facets.html.erb

diff --git a/app/assets/stylesheets/extranet.sass b/app/assets/stylesheets/extranet.sass
index 432c569b9..fbe2f9a17 100644
--- a/app/assets/stylesheets/extranet.sass
+++ b/app/assets/stylesheets/extranet.sass
@@ -5,13 +5,14 @@
 
 // Vendors
 @import 'bootstrap'
-@import 'bootstrap-print-css/css/bootstrap-print.min'
+@import 'bootstrap-icons/font/bootstrap-icons.css'
 @import 'simple_form_password_with_hints'
 @import 'simple_form_bs5_file_input'
 @import 'gdpr/cookie_consent'
 @import 'cropperjs/dist/cropper'
 
 // Default
+@import 'extranet/bootstrap-icons'
 @import 'extranet/_default/base/*'
 @import 'extranet/_default/layouts/*'
 @import 'extranet/_default/components/*'
diff --git a/app/assets/stylesheets/extranet/bootstrap-icons.sass b/app/assets/stylesheets/extranet/bootstrap-icons.sass
new file mode 100644
index 000000000..bebfb5723
--- /dev/null
+++ b/app/assets/stylesheets/extranet/bootstrap-icons.sass
@@ -0,0 +1,5 @@
+@import 'bootstrap-print-css/css/bootstrap-print.min'
+
+@font-face
+  font-family: "bootstrap-icons"
+  src: font-url("bootstrap-icons/font/fonts/bootstrap-icons.woff2") format("woff2"), font-url("bootstrap-icons/font/fonts/bootstrap-icons.woff") format("woff")
\ No newline at end of file
diff --git a/app/views/extranet/cohorts/_index.cards.html.erb b/app/views/extranet/cohorts/_index.cards.html.erb
new file mode 100644
index 000000000..e95a2f627
--- /dev/null
+++ b/app/views/extranet/cohorts/_index.cards.html.erb
@@ -0,0 +1,21 @@
+<% cohorts_paged = @cohorts.ordered.page(params[:page]).per(60) %>
+<div class="row">
+  <% cohorts_paged.each do |cohort| %>
+  <div class="col-md-4 col-xl-3">
+    <article class="card">
+      <div class="card-body">
+        <h2><%= link_to cohort.program, cohort, class: 'stretched-link' %></h2>
+        <p><%= cohort.academic_year.year %></p>
+        <p class="small">
+          <%= cohort.people.count %>
+          <%= University::Person::Alumnus.model_name.human(count: cohort.people.count).downcase %>
+        </p>
+        <p class="text-end mb-0">
+          <i class="bi bi-arrow-right"></i>
+        </p>
+      </div>
+    </article>
+  </div>
+  <% end %>
+</div>
+<%= paginate cohorts_paged, theme: 'bootstrap-5', window: 2 %>
diff --git a/app/views/extranet/cohorts/_index.facets.html.erb b/app/views/extranet/cohorts/_index.facets.html.erb
new file mode 100644
index 000000000..642682d7c
--- /dev/null
+++ b/app/views/extranet/cohorts/_index.facets.html.erb
@@ -0,0 +1,8 @@
+<div class="row">
+  <div class="col-md-3">
+    <%= render 'faceted_search/facets', facets: @facets %>
+  </div>
+  <div class="col-md-8 offset-md-1">
+    <%= render 'extranet/cohorts/list', cohorts: @cohorts %>
+  </div>
+</div>
diff --git a/app/views/extranet/cohorts/index.html.erb b/app/views/extranet/cohorts/index.html.erb
index 5cc630029..492272752 100644
--- a/app/views/extranet/cohorts/index.html.erb
+++ b/app/views/extranet/cohorts/index.html.erb
@@ -8,11 +8,8 @@
   </p>
 </header>
 
-<div class="row">
-  <div class="col-md-3">
-    <%= render 'faceted_search/facets', facets: @facets %>
-  </div>
-  <div class="col-md-8 offset-md-1">
-    <%= render 'extranet/cohorts/list', cohorts: @cohorts %>
-  </div>
-</div>
+<% if current_extranet.should_show_years? %>
+  <%= render 'index.facets' %>
+<% else %>
+  <%= render 'index.cards' %>
+<% end %>
\ No newline at end of file
diff --git a/package.json b/package.json
index 4c549cf34..a2d860975 100644
--- a/package.json
+++ b/package.json
@@ -5,6 +5,7 @@
   },
   "dependencies": {
     "16": "0.0.2",
+    "bootstrap-icons": "^1.9.1",
     "bootstrap-print-css": "^1.0.1",
     "cropperjs": "^1.5.12",
     "jquery-cropper": "^1.0.1",
diff --git a/yarn.lock b/yarn.lock
index f3c70d157..3b61a7621 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -104,6 +104,11 @@
   resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.2.31.tgz#c90de7126d833dcd3a4c7534d534be2fb41faa4e"
   integrity sha512-ymN2pj6zEjiKJZbrf98UM2pfDd6F2H7ksKw7NDt/ZZ1fh5Ei39X5tABugtT03ZRlWd9imccoK0hE8hpjpU7irQ==
 
+bootstrap-icons@^1.9.1:
+  version "1.9.1"
+  resolved "https://registry.yarnpkg.com/bootstrap-icons/-/bootstrap-icons-1.9.1.tgz#cf22d91a25447645e45c49ebde4e56eafdfe761b"
+  integrity sha512-d4ZkO30MIkAhQ2nNRJqKXJVEQorALGbLWTuRxyCTJF96lRIV6imcgMehWGJUiJMJhglN0o2tqLIeDnMdiQEE9g==
+
 bootstrap-print-css@^1.0.1:
   version "1.0.1"
   resolved "https://registry.yarnpkg.com/bootstrap-print-css/-/bootstrap-print-css-1.0.1.tgz#acc0264388caebbad0805e60c869d42cd6fe55bf"
-- 
GitLab