From a2fc170dd7742147001f0c00e68b94f4319ce755 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Wed, 8 Mar 2023 17:25:56 +0100
Subject: [PATCH] front wip

---
 .../communication/extranets/files_controller.rb  |  2 +-
 .../extranet/files/application_controller.rb     |  9 +++++++++
 .../extranet/files/files_controller.rb           | 16 ++++++++++++++++
 app/models/communication/extranet/file.rb        |  3 +++
 app/views/extranet/files/files/_list.html.erb    | 13 +++++++++++++
 app/views/extranet/files/files/index.html.erb    |  3 +++
 app/views/extranet/files/files/show.html.erb     |  3 +++
 config/extranet_navigation.rb                    | 12 +++++++++---
 config/locales/communication/en.yml              |  2 +-
 config/locales/communication/fr.yml              |  2 +-
 config/routes/extranet.rb                        |  2 +-
 11 files changed, 60 insertions(+), 7 deletions(-)
 create mode 100644 app/controllers/extranet/files/application_controller.rb
 create mode 100644 app/controllers/extranet/files/files_controller.rb
 create mode 100644 app/views/extranet/files/files/_list.html.erb
 create mode 100644 app/views/extranet/files/files/index.html.erb
 create mode 100644 app/views/extranet/files/files/show.html.erb

diff --git a/app/controllers/admin/communication/extranets/files_controller.rb b/app/controllers/admin/communication/extranets/files_controller.rb
index e933b980f..25161c001 100644
--- a/app/controllers/admin/communication/extranets/files_controller.rb
+++ b/app/controllers/admin/communication/extranets/files_controller.rb
@@ -48,7 +48,7 @@ class Admin::Communication::Extranets::FilesController < Admin::Communication::E
 
   def breadcrumb
     super
-    add_breadcrumb Communication::Extranet::File.model_name.human(count: 2), admin_communication_extranet_files_path
+    add_breadcrumb Communication::Extranet.human_attribute_name(:feature_files), admin_communication_extranet_files_path
     breadcrumb_for @file
   end
 
diff --git a/app/controllers/extranet/files/application_controller.rb b/app/controllers/extranet/files/application_controller.rb
new file mode 100644
index 000000000..a5c261292
--- /dev/null
+++ b/app/controllers/extranet/files/application_controller.rb
@@ -0,0 +1,9 @@
+class Extranet::Files::ApplicationController < Extranet::ApplicationController
+
+  protected
+
+  def breadcrumb
+    super
+    add_breadcrumb Communication::Extranet.human_attribute_name(:feature_files), files_root_path
+  end
+end
\ No newline at end of file
diff --git a/app/controllers/extranet/files/files_controller.rb b/app/controllers/extranet/files/files_controller.rb
new file mode 100644
index 000000000..d89f53eee
--- /dev/null
+++ b/app/controllers/extranet/files/files_controller.rb
@@ -0,0 +1,16 @@
+class Extranet::Files::FilesController < Extranet::Files::ApplicationController
+
+  def index
+    @files = current_extranet.files
+                             .published
+                             .ordered
+                             .page(params[:page])
+    breadcrumb
+  end
+
+  def show
+    @file = current_extranet.files.find params[:id]
+    breadcrumb
+    add_breadcrumb @file
+  end
+end
diff --git a/app/models/communication/extranet/file.rb b/app/models/communication/extranet/file.rb
index 0c1a33ecf..e0ee1e32a 100644
--- a/app/models/communication/extranet/file.rb
+++ b/app/models/communication/extranet/file.rb
@@ -31,6 +31,9 @@ class Communication::Extranet::File < ApplicationRecord
 
   before_validation :set_published_at
 
+  scope :published, -> { where(published: true) }
+  scope :ordered, -> { order(published_at: :desc) }
+
   def to_s
     "#{name}"
   end
diff --git a/app/views/extranet/files/files/_list.html.erb b/app/views/extranet/files/files/_list.html.erb
new file mode 100644
index 000000000..53f1f21be
--- /dev/null
+++ b/app/views/extranet/files/files/_list.html.erb
@@ -0,0 +1,13 @@
+<div class="row mt-n5">
+  <% files.each do |file| %>
+    <div class="col-lg-4">
+      <div class="position-relative mt-5">
+        <p class="mt-2">
+          <b><%= file %></b><br>
+          <span class="text-muted"><%= l file.published_at.to_date %><span>
+        </p>
+        <%= link_to t('extranet.files.show'), files_communication_extranet_file_path(file), class: ' btn btn-outline-primary stretched-link' %>
+      </div>
+    </div>
+  <% end %>
+</div>
\ No newline at end of file
diff --git a/app/views/extranet/files/files/index.html.erb b/app/views/extranet/files/files/index.html.erb
new file mode 100644
index 000000000..7195c8fad
--- /dev/null
+++ b/app/views/extranet/files/files/index.html.erb
@@ -0,0 +1,3 @@
+<% content_for :title, Communication::Extranet::File.model_name.human(count: 2) %>
+
+<%= render 'extranet/files/files/list', files: @files %>
\ No newline at end of file
diff --git a/app/views/extranet/files/files/show.html.erb b/app/views/extranet/files/files/show.html.erb
new file mode 100644
index 000000000..7f73570d1
--- /dev/null
+++ b/app/views/extranet/files/files/show.html.erb
@@ -0,0 +1,3 @@
+<% content_for :title, @post %>
+
+
diff --git a/config/extranet_navigation.rb b/config/extranet_navigation.rb
index cf5443b54..84f8e8ddf 100644
--- a/config/extranet_navigation.rb
+++ b/config/extranet_navigation.rb
@@ -6,9 +6,14 @@ SimpleNavigation::Configuration.run do |navigation|
   navigation.items do |primary|
     primary.item      :posts,
                       Communication::Extranet.human_attribute_name(:feature_posts),
-                      posts_root_path if current_extranet.feature_posts
+                      posts_root_path if current_extranet.feature_posts?
 
-    primary.item :contacts, Communication::Extranet.human_attribute_name(:feature_contacts) do |secondary|
+    primary.item      :files,
+                      Communication::Extranet.human_attribute_name(:feature_files),
+                      files_root_path if current_extranet.feature_files?
+
+    primary.item      :contacts, 
+                      Communication::Extranet.human_attribute_name(:feature_contacts) do |secondary|
       secondary.item  :person,
                       University::Person.model_name.human(count: 2),
                       contacts_university_persons_path
@@ -17,7 +22,8 @@ SimpleNavigation::Configuration.run do |navigation|
                       contacts_university_organizations_path
     end if current_extranet.feature_contacts?
 
-    primary.item :alumni, University::Person::Alumnus.model_name.human(count: 2) do |secondary|
+    primary.item      :alumni, 
+                      University::Person::Alumnus.model_name.human(count: 2) do |secondary|
       secondary.item  :person,
                       University::Person.model_name.human(count: 2),
                       alumni_university_persons_path
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index be1392e10..0462a89f1 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -62,7 +62,7 @@ en:
         description: Espaces d'échanges sécurisés dédiés aux personnes authentifiées
         favicon: Favicon (.png)
         feature_alumni: Alumni
-        feature_files: Files
+        feature_files: Documents
         feature_contacts: Directory
         feature_posts: News
         feature_jobs: Job board
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index 168db765e..2974a2d62 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -62,7 +62,7 @@ fr:
         description: Espaces d'échanges sécurisés dédiés aux personnes authentifiées
         favicon: Favicon (.png)
         feature_alumni: Alumni
-        feature_files: Gestion de fichiers
+        feature_files: Documents
         feature_contacts: Annuaire
         feature_posts: Actualités
         feature_jobs: Offres d'emploi
diff --git a/config/routes/extranet.rb b/config/routes/extranet.rb
index bdd8b1bd6..e75e5ec15 100644
--- a/config/routes/extranet.rb
+++ b/config/routes/extranet.rb
@@ -24,7 +24,7 @@ namespace :posts do
   root to: 'posts#index'
 end
 namespace :files do
-  get ':id' => 'posts#show', as: :communication_extranet_file
+  get ':id' => 'files#show', as: :communication_extranet_file
   root to: 'files#index'
 end
 get 'account' => 'account#show', as: :account
-- 
GitLab