From 5b06b5cf5b8afa1b785d47f8bc753c29775d90c3 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Tue, 27 Dec 2022 09:47:57 +0100
Subject: [PATCH] websites in universities

---
 app/controllers/server/websites_controller.rb |  2 +-
 app/views/server/universities/show.html.erb   | 25 +-----------
 app/views/server/websites/_list.html.erb      | 37 ++++++++++++++++++
 app/views/server/websites/index.html.erb      | 39 +------------------
 4 files changed, 41 insertions(+), 62 deletions(-)
 create mode 100644 app/views/server/websites/_list.html.erb

diff --git a/app/controllers/server/websites_controller.rb b/app/controllers/server/websites_controller.rb
index 7ee0a9b20..f61e76457 100644
--- a/app/controllers/server/websites_controller.rb
+++ b/app/controllers/server/websites_controller.rb
@@ -9,7 +9,7 @@ class Server::WebsitesController < Server::ApplicationController
   def refresh
     @website = Communication::Website.find params[:id]
     @website.get_current_theme_version!
-    redirect_to server_websites_path
+    redirect_back fallback_location: server_websites_path
   end
 
 end
\ No newline at end of file
diff --git a/app/views/server/universities/show.html.erb b/app/views/server/universities/show.html.erb
index 5c19f84f8..10102c01c 100644
--- a/app/views/server/universities/show.html.erb
+++ b/app/views/server/universities/show.html.erb
@@ -34,29 +34,8 @@
   </div>
 </div>
 
-<h2>Blocks</h2>
-<div class="table-responsive">
-  <table class="<%= table_classes %>">
-    <thead>
-      <tr>
-        <th>Block</th>
-        <th>About</th>
-        <th>Template</th>
-        <th></th>
-      </tr>
-    </thead>
-    <tbody>
-      <% @university.communication_blocks.each do |block| %>
-        <tr>
-          <td><%= block %></td>
-          <td><%= block.about %></td>
-          <td><%= block.template_kind %></td>
-          <td><%= edit_link block %></td>
-        </tr>
-      <% end %>
-    </tbody>
-  </table>
-</div>
+<h2 class="mt-5 h3"><%= Communication::Website.model_name.human(count: @university.websites.count) %></h2>
+<%= render 'server/websites/list', websites: @university.websites %>
 
 <% content_for :action_bar_right do %>
   <%= link_to t('edit'), edit_server_university_path(@university), class: button_classes %>
diff --git a/app/views/server/websites/_list.html.erb b/app/views/server/websites/_list.html.erb
new file mode 100644
index 000000000..73408181d
--- /dev/null
+++ b/app/views/server/websites/_list.html.erb
@@ -0,0 +1,37 @@
+<div class="table-responsive">
+  <table class="<%= table_classes %>">
+    <thead>
+      <tr>
+        <th><%= Communication::Website.human_attribute_name('name') %></th>
+        <th><%= Communication::Website.human_attribute_name('url') %></th>
+        <th><%= Communication::Website.human_attribute_name('theme_version') %></th>
+        <th><%= University.model_name.human %></th>
+        <th></th>
+      </tr>
+    </thead>
+    <tbody>
+      <% websites.ordered.each do |website| %>
+        <tr>
+          <td>
+            <%= link_to website.name, edit_server_website_path(website) %>
+          </td>
+          <td>
+            <%= link_to website.url, website.url, target: :_blank if website.url.present? %>
+            <% if website.in_production %>
+              <span class="badge bg-success">Prod</span>
+            <% end %>
+          </td>
+          <td>
+            <%= link_to website.theme_version, website.theme_version_url, target: :_blank if website.theme_version_url.present? %>
+          </td>
+          <td>
+            <%= link_to website.university, [:server, website.university] %>
+          </td>
+          <td>
+            <%= link_to "Sync version", refresh_server_website_path(website), method: :post, class: button_classes %>
+          </td>
+        </tr>
+      <% end %>
+    </tbody>
+  </table>
+</div>
\ No newline at end of file
diff --git a/app/views/server/websites/index.html.erb b/app/views/server/websites/index.html.erb
index 5995955a4..b3d4a09cc 100644
--- a/app/views/server/websites/index.html.erb
+++ b/app/views/server/websites/index.html.erb
@@ -2,41 +2,4 @@
 
 <p><%= Communication::Website.in_production.count %> en production</p>
 
-<div class="table-responsive">
-  <table class="<%= table_classes %>">
-    <thead>
-      <tr>
-        <th><%= Communication::Website.human_attribute_name('name') %></th>
-        <th><%= Communication::Website.human_attribute_name('url') %></th>
-        <th><%= Communication::Website.human_attribute_name('in_production') %></th>
-        <th><%= Communication::Website.human_attribute_name('theme_version') %></th>
-        <th><%= University.model_name.human %></th>
-        <th></th>
-      </tr>
-    </thead>
-    <tbody>
-      <% @websites.each do |website| %>
-        <tr>
-          <td>
-            <%= link_to website.name, edit_server_website_path(website) %>
-          </td>
-          <td>
-            <%= link_to website.url, website.url, target: :_blank if website.url.present? %>
-          </td>
-          <td>
-            <%= t website.in_production %>
-          </td>
-          <td>
-            <%= link_to website.theme_version, website.theme_version_url, target: :_blank if website.theme_version_url.present? %>
-          </td>
-          <td>
-            <%= link_to website.university, [:server, website.university] %>
-          </td>
-          <td>
-            <%= link_to "Sync version", refresh_server_website_path(website), method: :post, class: button_classes %>
-          </td>
-        </tr>
-      <% end %>
-    </tbody>
-  </table>
-</div>
\ No newline at end of file
+<%= render 'server/websites/list', websites: @websites %>
\ No newline at end of file
-- 
GitLab