From df8e6c8c8071dca47111973f932a374a7b42596e Mon Sep 17 00:00:00 2001
From: Arnaud Levy <arnaud.levy@noesya.coop>
Date: Wed, 30 Oct 2024 07:27:38 +0100
Subject: [PATCH] =?UTF-8?q?Simplification=20des=20r=C3=A9glages=20de=20sit?=
 =?UTF-8?q?e=20(#2382)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* Simplification des réglages de site

* simpler
---
 .../communication/websites_controller.rb      |  16 +-
 .../communication/websites/_form.html.erb     | 146 ------------------
 .../communication/websites/edit.html.erb      |  49 +++++-
 .../websites/edit_language.html.erb           |  50 ++++++
 .../websites/edit_technical.html.erb          |  60 +++++++
 .../websites/form/_features.html.erb          |  13 ++
 .../admin/communication/websites/new.html.erb |  19 ++-
 .../websites/posts/categories/index.html.erb  |   2 +-
 .../communication/websites/show.html.erb      |   4 +-
 .../website/settings_navigation.rb            |  11 +-
 config/routes/admin/communication.rb          |   2 +
 11 files changed, 219 insertions(+), 153 deletions(-)
 delete mode 100644 app/views/admin/communication/websites/_form.html.erb
 create mode 100644 app/views/admin/communication/websites/edit_language.html.erb
 create mode 100644 app/views/admin/communication/websites/edit_technical.html.erb
 create mode 100644 app/views/admin/communication/websites/form/_features.html.erb

diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb
index 9b80c0679..1936d4576 100644
--- a/app/controllers/admin/communication/websites_controller.rb
+++ b/app/controllers/admin/communication/websites_controller.rb
@@ -1,7 +1,7 @@
 class Admin::Communication::WebsitesController < Admin::Communication::Websites::ApplicationController
   include Admin::Localizable
 
-  before_action :set_feature_nav, only: [:edit, :update]
+  before_action :set_feature_nav, only: [:edit, :edit_language, :edit_technical, :update]
 
   def index
     @websites = @websites.filter_by(params[:filters], current_language)
@@ -52,6 +52,20 @@ class Admin::Communication::WebsitesController < Admin::Communication::Websites:
     add_breadcrumb t('admin.subnav.settings')
   end
 
+  def edit_language
+    @l10n = @website.localization_for(current_language)
+    breadcrumb
+    add_breadcrumb t('admin.subnav.settings'), edit_admin_communication_website_path(@website, website_id: nil)
+    add_breadcrumb current_language
+  end
+
+  def edit_technical
+    @l10n = @website.localization_for(current_language)
+    breadcrumb
+    add_breadcrumb t('admin.subnav.settings'), edit_admin_communication_website_path(@website, website_id: nil)
+    add_breadcrumb t('admin.communication.website.technical.label')
+  end
+
   def create
     if @website.save_and_sync
       redirect_to [:admin, @website], notice: t('admin.successfully_created_html', model: @website.to_s_in(current_language))
diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb
deleted file mode 100644
index 3522a5fac..000000000
--- a/app/views/admin/communication/websites/_form.html.erb
+++ /dev/null
@@ -1,146 +0,0 @@
-<%= simple_form_for [:admin, website] do |f| %>
-  <%= f.simple_fields_for :localizations, l10n do |lf| %>
-    <%= f.error_notification %>
-    <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
-
-    <%= lf.hidden_field :language_id, value: current_language.id %>
-
-    <div class="row">
-      <div class="col-lg-4">
-        <%= lf.input :name %>
-        <% if website.localizations.many? %>
-          <%= lf.input  :published,
-                        wrapper: :custom_boolean_switch,
-                        disabled: l10n.published? && website.active_languages.one? %>
-          <%= f.association :default_language,
-                            include_blank: false,
-                            collection: website.languages,
-                            label_method: lambda { |l| language_name(l.iso_code) } %>
-        <% end %>
-      </div>
-      <div class="col-lg-8">
-        <section>
-          <p class="float-end blocks__category__description"><%= t "admin.communication.website.editorial.description" %></p>
-          <h2 class="h3 category blocks__category__title"><%= t "admin.communication.website.editorial.label" %></h2>
-          <%= osuny_panel Communication::Website.human_attribute_name('features') do %>
-            <div class="row">
-              <div class="col-lg-6">
-                <%= f.input :feature_posts %>
-              </div>
-              <div class="col-lg-6">
-                <%= f.input :feature_agenda %>
-              </div>
-              <div class="col-lg-6">
-                <%= f.input :feature_portfolio %>
-              </div>
-            </div>
-          <% end %>
-
-          <%= osuny_panel Communication::Website.human_attribute_name('appearance') do %>
-            <div class="row">
-              <div class="col-lg-6">
-                <p class="form-text">
-                  <%= t('admin.communication.website.default_image') %>
-                </p>
-                <%= f.input :default_image,
-                            as: :single_deletable_file,
-                            direct_upload: true,
-                            hint: images_formats_accepted_hint,
-                            input_html: { accept: default_images_formats_accepted },
-                            preview: 300 %>
-                <%= f.input :default_shared_image,
-                            as: :single_deletable_file,
-                            direct_upload: true,
-                            hint: images_formats_accepted_hint,
-                            input_html: { accept: default_images_formats_accepted },
-                            preview: 300 %>
-              </div>
-            </div>
-          <% end %>
-
-          <%= osuny_panel Communication::Website.human_attribute_name('feature_agenda') do %>
-            <div class="row">
-              <div class="col-lg-6">
-                <%= f.input :default_time_zone,
-                            collection: time_zones_for_select,
-                            include_blank: false,
-                            selected: f.object.default_time_zone || Time.zone.name %>
-              </div>
-            </div>
-          <% end %>
-
-          <%= osuny_panel Communication::Website.human_attribute_name('social') do %>
-            <div class="row">
-              <div class="col-lg-6">
-                <p><%= t('admin.communication.website.social.free') %></p>
-                <%= lf.input :social_email %>
-                <%= lf.input :social_mastodon %>
-                <%= lf.input :social_peertube %>
-              </div>
-              <div class="col-lg-6">
-                <p><%= t('admin.communication.website.social.private') %></p>
-                <%= lf.input :social_x %>
-                <%= lf.input :social_github %>
-                <%= lf.input :social_linkedin %>
-                <%= lf.input :social_youtube %>
-                <%= lf.input :social_vimeo %>
-                <%= lf.input :social_instagram %>
-                <%= lf.input :social_facebook %>
-                <%= lf.input :social_tiktok %>
-              </div>
-            </div>
-          <% end %>
-        </section>
-
-        <section>
-          <p class="float-end blocks__category__description"><%= t "admin.communication.website.technical.description" %></p>
-          <h2 class="h3 category blocks__category__title"><%= t "admin.communication.website.technical.label" %></h2>
-
-          <%= osuny_panel t('metadata') do %>
-            <%= f.input :url %>
-            <%= f.input :in_production %>
-            <%= render 'admin/communication/abouts', f: f, i18n_key: 'activerecord.attributes.communication/website.about_' %>
-          <% end %>
-
-          <%= osuny_panel t('communication.website.showcase') do %>
-            <%= f.input :in_showcase, hint: link_to(t('admin.communication.website.see_showcase'), "https://#{ENV['OSUNY_SHOWCASE']}", target: :_blank) %>
-            <%= f.association :showcase_tags, as: :check_boxes %>
-          <% end %>
-
-          <%= osuny_panel t('communication.website.hosting') do %>
-            <%= f.input :deuxfleurs_hosting, hint: website.deuxfleurs_identifier %>
-            <%= f.input :autoupdate_theme %>
-            <%= f.input :plausible_url %>
-          <% end %>
-
-          <%= osuny_panel t('communication.website.git') do %>
-            <%= f.input :git_provider, include_blank: false %>
-            <%= f.input :git_endpoint %>
-            <%= f.input :access_token,
-                        as: :string,
-                        placeholder: masked_string(f.object.access_token),
-                        hint: t("simple_form.hints.communication_website.access_token_#{f.object.access_token.blank? ? 'without' : 'with'}_existing").html_safe,
-                        input_html: {
-                          autocomplete: 'access_token',
-                          role: 'presentation',
-                          value: ''
-                        }
-                        %>
-            <%= f.input :repository %>
-            <%= f.input :git_branch %>
-            <%= f.input :deployment_status_badge,
-                        as: :string,
-                        input_html: {
-                          autocomplete: 'deployment_status_badge',
-                          role: 'presentation'
-                        }
-                        %>
-          <% end %>
-        </section>
-      </div>
-    </div>
-    <% content_for :action_bar_right do %>
-      <%= submit f %>
-    <% end %>
-  <% end %>
-<% end %>
diff --git a/app/views/admin/communication/websites/edit.html.erb b/app/views/admin/communication/websites/edit.html.erb
index 49eca46c6..f5ed33f40 100644
--- a/app/views/admin/communication/websites/edit.html.erb
+++ b/app/views/admin/communication/websites/edit.html.erb
@@ -1,3 +1,50 @@
 <% content_for :title, t('admin.subnav.settings') %>
 
-<%= render 'form', website: @website, l10n: @l10n %>
+<%= simple_form_for [:admin, @website] do |f| %>
+  <%= f.simple_fields_for :localizations, @l10n do |lf| %>
+    <%= f.error_notification %>
+    <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
+
+    <%= lf.hidden_field :language_id, value: current_language.id %>
+
+    <%= render 'admin/communication/websites/form/features', f: f %>
+    <%= osuny_separator %>
+    <div class="row">
+      <div class="col-lg-4">
+        <%= lf.input :name unless @website.persisted? %>
+        <% if @website.localizations.many? %>
+          <%= f.association :default_language,
+                            include_blank: false,
+                            collection: website.languages,
+                            label_method: lambda { |l| language_name(l.iso_code) } %>
+        <% end %>
+        <%= f.input :default_time_zone,
+                    collection: time_zones_for_select,
+                    include_blank: false,
+                    selected: f.object.default_time_zone || Time.zone.name %>
+      </div>
+      <div class="col-lg-4">
+        <%= f.input :default_image,
+                    as: :single_deletable_file,
+                    direct_upload: true,
+                    hint: images_formats_accepted_hint,
+                    input_html: { accept: default_images_formats_accepted },
+                    preview: 300 %>
+        <p class="form-text">
+          <%= t('admin.communication.website.default_image') %>
+        </p>
+      </div>
+      <div class="col-lg-4">
+        <%= f.input :default_shared_image,
+                    as: :single_deletable_file,
+                    direct_upload: true,
+                    hint: images_formats_accepted_hint,
+                    input_html: { accept: default_images_formats_accepted },
+                    preview: 300 %>
+      </div>
+    </div>
+    <% content_for :action_bar_right do %>
+      <%= submit f %>
+    <% end %>
+  <% end %>
+<% end %>
diff --git a/app/views/admin/communication/websites/edit_language.html.erb b/app/views/admin/communication/websites/edit_language.html.erb
new file mode 100644
index 000000000..3b42b091c
--- /dev/null
+++ b/app/views/admin/communication/websites/edit_language.html.erb
@@ -0,0 +1,50 @@
+<% content_for :title, current_language %>
+
+<%= simple_form_for [:admin, @website] do |f| %>
+  <%= f.simple_fields_for :localizations, @l10n do |lf| %>
+    <%= f.error_notification %>
+    <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
+
+    <%= lf.hidden_field :language_id, value: current_language.id %>
+
+    <div class="row">
+      <div class="col-lg-4">
+        <% if @website.localizations.many? %>
+          <%= lf.input  :published,
+                        wrapper: :custom_boolean_switch,
+                        disabled: @l10n.published? && @website.active_languages.one? %>
+        <% end %>
+        <%= lf.input :name %>
+      </div>
+      <div class="col-lg-8">
+        <%= osuny_panel Communication::Website.human_attribute_name('social') do %>
+          <div class="row">
+            <div class="col-lg-6">
+              <p><%= t('admin.communication.website.social.free') %></p>
+              <%= lf.input :social_email %>
+              <%= lf.input :social_mastodon %>
+              <%= lf.input :social_peertube %>
+            </div>
+            <div class="col-lg-6">
+              <p><%= t('admin.communication.website.social.private') %></p>
+              <%= lf.input :social_x %>
+              <%= lf.input :social_github %>
+              <%= lf.input :social_linkedin %>
+              <%= lf.input :social_youtube %>
+              <%= lf.input :social_vimeo %>
+              <%= lf.input :social_instagram %>
+              <%= lf.input :social_facebook %>
+              <%= lf.input :social_tiktok %>
+            </div>
+          </div>
+        <% end %>
+      </div>
+      <div class="col-lg-6 col-xxl-4">
+      </div>
+    </div>
+
+    <% content_for :action_bar_right do %>
+      <%= submit f %>
+    <% end %>
+  <% end %>
+<% end %>
diff --git a/app/views/admin/communication/websites/edit_technical.html.erb b/app/views/admin/communication/websites/edit_technical.html.erb
new file mode 100644
index 000000000..1d4f000ff
--- /dev/null
+++ b/app/views/admin/communication/websites/edit_technical.html.erb
@@ -0,0 +1,60 @@
+<% content_for :title, t('admin.communication.website.technical.label') %>
+
+<%= simple_form_for [:admin, @website] do |f| %>
+  <%= f.simple_fields_for :localizations, @l10n do |lf| %>
+    <%= f.error_notification %>
+    <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
+
+    <%= lf.hidden_field :language_id, value: current_language.id %>
+
+    <div class="row">
+      <div class="col-lg-6 col-xxl-4">
+        <%= osuny_panel t('metadata') do %>
+          <%= f.input :url %>
+          <%= render 'admin/communication/abouts', f: f, i18n_key: 'activerecord.attributes.communication/website.about_' %>
+          <%= f.input :in_production %>
+        <% end %>
+      </div>
+      <div class="col-lg-6 col-xxl-4">
+        <%= osuny_panel t('communication.website.git') do %>
+          <%= f.input :git_provider, include_blank: false %>
+          <%= f.input :git_endpoint %>
+          <%= f.input :access_token,
+                      as: :string,
+                      placeholder: masked_string(f.object.access_token),
+                      hint: t("simple_form.hints.communication_website.access_token_#{f.object.access_token.blank? ? 'without' : 'with'}_existing").html_safe,
+                      input_html: {
+                        autocomplete: 'access_token',
+                        role: 'presentation',
+                        value: ''
+                      }
+                      %>
+          <%= f.input :repository %>
+          <%= f.input :git_branch %>
+          <%= f.input :deployment_status_badge,
+                      as: :string,
+                      input_html: {
+                        autocomplete: 'deployment_status_badge',
+                        role: 'presentation'
+                      }
+                      %>
+        <% end %>
+      </div>
+      <div class="col-lg-6 col-xxl-4">
+        <%= osuny_panel t('communication.website.hosting') do %>
+          <%= f.input :deuxfleurs_hosting, hint: @website.deuxfleurs_identifier %>
+          <%= f.input :autoupdate_theme %>
+          <%= f.input :plausible_url %>
+        <% end %>
+        <%= osuny_panel t('communication.website.showcase') do %>
+          <%= f.input :in_showcase, hint: link_to(t('admin.communication.website.see_showcase'), "https://#{ENV['OSUNY_SHOWCASE']}", target: :_blank) %>
+          <%= f.association :showcase_tags, as: :check_boxes %>
+        <% end %>
+      </div>
+    </div>
+
+    <% content_for :action_bar_right do %>
+      <%= submit f %>
+    <% end %>
+  <% end %>
+<% end %>
diff --git a/app/views/admin/communication/websites/form/_features.html.erb b/app/views/admin/communication/websites/form/_features.html.erb
new file mode 100644
index 000000000..57758dd22
--- /dev/null
+++ b/app/views/admin/communication/websites/form/_features.html.erb
@@ -0,0 +1,13 @@
+<%= osuny_panel Communication::Website.human_attribute_name('features') do %>
+  <div class="row">
+    <div class="col-lg-4">
+      <%= f.input :feature_posts %>
+    </div>
+    <div class="col-lg-4">
+      <%= f.input :feature_agenda %>
+    </div>
+    <div class="col-lg-4">
+      <%= f.input :feature_portfolio %>
+    </div>
+  </div>
+<% end %>
\ No newline at end of file
diff --git a/app/views/admin/communication/websites/new.html.erb b/app/views/admin/communication/websites/new.html.erb
index 568aedf3f..c1fda73ed 100644
--- a/app/views/admin/communication/websites/new.html.erb
+++ b/app/views/admin/communication/websites/new.html.erb
@@ -1,3 +1,20 @@
 <% content_for :title, Communication::Website.model_name.human %>
 
-<%= render 'form', website: @website, l10n: @l10n %>
+<%= simple_form_for [:admin, @website] do |f| %>
+  <%= f.simple_fields_for :localizations, @l10n do |lf| %>
+    <%= f.error_notification %>
+    <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
+
+    <%= lf.hidden_field :language_id, value: current_language.id %>
+
+    <div class="row mb-5">
+      <div class="col-lg-6">
+        <%= lf.input :name %>
+      </div>
+    </div>
+    <%= render 'admin/communication/websites/form/features', f: f %>
+    <% content_for :action_bar_right do %>
+      <%= submit f %>
+    <% end %>
+  <% end %>
+<% end %>
diff --git a/app/views/admin/communication/websites/posts/categories/index.html.erb b/app/views/admin/communication/websites/posts/categories/index.html.erb
index f1207a9be..c86895a8b 100644
--- a/app/views/admin/communication/websites/posts/categories/index.html.erb
+++ b/app/views/admin/communication/websites/posts/categories/index.html.erb
@@ -1,4 +1,4 @@
-<% content_for :title, "#{Communication::Website::Post::Category.model_name.human(count: 2)} (#{@categories.count})" %>
+<% content_for :title, Communication::Website::Post::Category.model_name.human(count: 2) %>
 
 <%= render 'admin/application/categories/list', 
             root_categories: @root_categories, 
diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb
index 77ada0a20..f6d37f57f 100644
--- a/app/views/admin/communication/websites/show.html.erb
+++ b/app/views/admin/communication/websites/show.html.erb
@@ -1,11 +1,11 @@
 <% content_for :title, @l10n %>
 
-<% content_for :title_left do %>
+<% content_for :title_right do %>
   <%= render 'admin/application/favorites/widget', about: @website %>
   <%= link_to @website.url, @website.url, target: :_blank unless @website.url.blank? %>
   <div class="small">
-    <%= I18n.t("activerecord.attributes.communication/website.about_#{@website.about_type}") %>
     <% if @website.about.present? %>
+      <%= I18n.t("activerecord.attributes.communication/website.about_#{@website.about_type}") %>
       — <%= osuny_link_localized_if can?(:read, @website.about), @website.about, [:admin, @website.about] %>
     <% end %>
   </div>
diff --git a/config/navigation/admin/communication/website/settings_navigation.rb b/config/navigation/admin/communication/website/settings_navigation.rb
index 55ea7ccc8..342fb8f44 100644
--- a/config/navigation/admin/communication/website/settings_navigation.rb
+++ b/config/navigation/admin/communication/website/settings_navigation.rb
@@ -6,6 +6,15 @@ SimpleNavigation::Configuration.run do |navigation|
   navigation.items do |primary|
     primary.item  :subnav_settings,
                   t('admin.subnav.settings'),
-                  edit_admin_communication_website_path(id: @website.id, website_id: nil) if can?(:edit, @website)
+                  edit_admin_communication_website_path(id: @website.id, website_id: nil),
+                  highlights_on: lambda { 
+                    controller_name == "websites" && action_name == "edit" 
+                  } if can?(:edit, @website)
+    primary.item  :subnav_language,
+                  current_language,
+                  edit_language_admin_communication_website_path(id: @website.id, website_id: nil) if can?(:edit, @website)
+    primary.item  :subnav_technical,
+                  t('admin.communication.website.technical.label'),
+                  edit_technical_admin_communication_website_path(id: @website.id, website_id: nil) if can?(:edit, @website)
   end
 end
diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb
index 6c163fad9..c35054775 100644
--- a/config/routes/admin/communication.rb
+++ b/config/routes/admin/communication.rb
@@ -5,6 +5,8 @@ namespace :communication do
   end
   resources :websites do
     member do
+      get 'edit/language' => 'websites#edit_language', as: :edit_language
+      get 'edit/technical' => 'websites#edit_technical', as: :edit_technical
       get :analytics
       get :security
       get :static
-- 
GitLab