From 52148742104beff034aa03b01ccb84ce6313d283 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Tue, 6 Feb 2024 08:32:41 +0100
Subject: [PATCH] favorites

---
 app/models/user/favorite.rb                   |  3 ++
 .../application/favorites/_show.html.erb      | 40 +++++++++++--------
 .../communication/websites/_list.html.erb     | 15 +++++++
 .../communication/websites/index.html.erb     | 19 ++-------
 app/views/admin/dashboard/index.html.erb      | 20 ----------
 5 files changed, 44 insertions(+), 53 deletions(-)
 create mode 100644 app/views/admin/communication/websites/_list.html.erb

diff --git a/app/models/user/favorite.rb b/app/models/user/favorite.rb
index 03876b345..816a9505e 100644
--- a/app/models/user/favorite.rb
+++ b/app/models/user/favorite.rb
@@ -22,6 +22,9 @@ class User::Favorite < ApplicationRecord
   belongs_to :user
   belongs_to :about, polymorphic: true
 
+  scope :websites, -> { where(about_type: 'Communication::Website') }
+  scope :except_websites, -> { where.not(about_type: 'Communication::Website') }
+
   def self.permitted_about_types
     ApplicationRecord.model_names_with_concern(Favoritable)
   end
diff --git a/app/views/admin/application/favorites/_show.html.erb b/app/views/admin/application/favorites/_show.html.erb
index a9efe4281..b5e1cb046 100644
--- a/app/views/admin/application/favorites/_show.html.erb
+++ b/app/views/admin/application/favorites/_show.html.erb
@@ -1,19 +1,25 @@
 <h2 class="category"><%= User::Favorite.model_name.human(count: 2) %></h2>
-<div class="row">
-  <% if current_user.favorites.none? %>
-    <p><%= t 'user.favorites.none' %></p>
-  <% else %>
-    <% current_user.favorites.each do |favorite| %>
-      <% about = favorite.about %>
-      <% next unless can?(:read, about) %>
-      <div class="col-md-6 col-xl-4 d-flex">
-        <%= osuny_panel about do %>
-          <p class="small mt-n2 mb-1"><%= about.class.model_name.human %></p>
-          <%= link_to t('show'), 
-                      [:admin, about], 
-                      class: 'stretched-link' %>
-        <% end %>
-      </div>
-    <% end %>
+<% if current_user.favorites.none? %>
+  <p><%= t 'user.favorites.none' %></p>
+<% else %>
+  <% websites = current_user.favorites.websites.collect(&:about) %>
+  <%= render 'admin/communication/websites/list', websites: websites %>
+  <% other = current_user.favorites.except_websites %>
+
+  <% if other.any? %>
+    <div class="row">
+      <% current_user.favorites.except_websites.each do |favorite| %>
+        <% about = favorite.about %>
+        <% next unless can?(:read, about) %>
+        <div class="col-md-6 col-xl-3 d-flex">
+          <%= osuny_panel about do %>
+            <p class="small mt-n2 mb-1"><%= about.class.model_name.human %></p>
+            <%= link_to t('show'), 
+                        [:admin, about], 
+                        class: 'stretched-link' %>
+          <% end %>
+        </div>
+      <% end %>
+    </div>
   <% end %>
-</div>
\ No newline at end of file
+<% end %>
\ No newline at end of file
diff --git a/app/views/admin/communication/websites/_list.html.erb b/app/views/admin/communication/websites/_list.html.erb
new file mode 100644
index 000000000..a2a3327f3
--- /dev/null
+++ b/app/views/admin/communication/websites/_list.html.erb
@@ -0,0 +1,15 @@
+<div class="row">
+  <% websites.each do |website| %>
+    <div class="col-lg-4 col-xl-3">
+      <div class=" position-relative mb-5">
+        <div class="ratio bg-light" style="--bs-aspect-ratio: 62.5%">
+          <%= kamifusen_tag website.screenshot, width: 500, class:'img-fluid rounded border' if website.screenshot.attached? %>
+        </div>
+        <p class="strong mt-2 mb-0">
+          <%= website %>
+          <%= link_to t('show'), [:admin, website], class: 'float-end action stretched-link' %>
+        </p>
+      </div>
+    </div>
+  <% end %>
+</div>
\ No newline at end of file
diff --git a/app/views/admin/communication/websites/index.html.erb b/app/views/admin/communication/websites/index.html.erb
index 4a2aad6b2..4f23c7c27 100644
--- a/app/views/admin/communication/websites/index.html.erb
+++ b/app/views/admin/communication/websites/index.html.erb
@@ -1,23 +1,10 @@
 <% content_for :title, "#{Communication::Website.model_name.human(count: 2)} (#{@websites.total_count})" %>
 
 <%= render 'filters', current_path: admin_communication_websites_path, filters: @filters if @filters.any?  %>
-
-<div class="row pt-5">
-  <% @websites.each do |website| %>
-    <div class="col-lg-4 col-xl-3">
-      <div class=" position-relative mb-5">
-        <div class="ratio bg-light" style="--bs-aspect-ratio: 62.5%">
-          <%= kamifusen_tag website.screenshot, width: 500, class:'img-fluid rounded border' if website.screenshot.attached? %>
-        </div>
-        <p class="strong mt-2 mb-0">
-          <%= website %>
-          <%= link_to t('show'), [:admin, website], class: 'float-end action stretched-link' %>
-        </p>
-      </div>
-    </div>
-  <% end %>
+<div class="pt-5">
+  <%= render 'admin/communication/websites/list', websites: @websites %>
+  <%= paginate @websites, theme: 'bootstrap-5' %>
 </div>
-<%= paginate @websites, theme: 'bootstrap-5' %>
 
 <% content_for :action_bar_right do %>
   <%= create_link Communication::Website %>
diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb
index de264b5de..6f25cb8b1 100644
--- a/app/views/admin/dashboard/index.html.erb
+++ b/app/views/admin/dashboard/index.html.erb
@@ -30,23 +30,3 @@
 <% else %>
   <%= render 'admin/dashboard/not_a_university' %>
 <% end %>
-
-<% if current_admin_theme == 'appstack' %>
-  <div class="small mt-5">
-    <ul class="list-inline">
-      <li class="list-inline-item">
-        <%= link_to 'API', api_root_path %>
-      </li>
-      <%
-      [
-      :terms_of_service,
-      :privacy_policy,
-      :cookies_policy
-      ].each do |term| %>
-        <li class="list-inline-item">
-          <%= link_to t("#{term}"), t("#{term}_url"), target: '_blank', rel: 'noreferrer' %>
-        </li>
-      <% end %>
-    </ul>
-  </div>
-<% end %>
-- 
GitLab