From 0a6407d6c617f58de4e3ba1f4520c45a1a7e3f95 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Fri, 17 Feb 2023 07:36:12 +0100 Subject: [PATCH] relocate connect and disconnect in pages --- .../websites/connections_controller.rb | 20 ----------- .../websites/pages_controller.rb | 18 ++++++++++ .../admin/application/_connections.html.erb | 23 ++++++++++++ .../admin/application/a11y/_widget.html.erb | 2 +- .../show/special_pages/_organization.html.erb | 6 ++-- .../admin/layouts/themes/pure/_panel.html.erb | 2 +- .../university/organizations/show.html.erb | 35 ++----------------- config/routes/admin/communication.rb | 4 ++- 8 files changed, 51 insertions(+), 59 deletions(-) create mode 100644 app/views/admin/application/_connections.html.erb diff --git a/app/controllers/admin/communication/websites/connections_controller.rb b/app/controllers/admin/communication/websites/connections_controller.rb index ada7d1436..02820624b 100644 --- a/app/controllers/admin/communication/websites/connections_controller.rb +++ b/app/controllers/admin/communication/websites/connections_controller.rb @@ -1,6 +1,4 @@ class Admin::Communication::Websites::ConnectionsController < Admin::Communication::Websites::ApplicationController - before_action :load_from_object, only: [:create, :destroy] - def index @connections = @website.connections.ordered.page params[:page] breadcrumb @@ -13,26 +11,8 @@ class Admin::Communication::Websites::ConnectionsController < Admin::Communicati add_breadcrumb @connection end - # Strange use of create, does not really create a connection - def create - @website.connect @object, @website - head :ok - end - - # Strange use of destroy, does not really create a connection - def destroy - @website.disconnect @object, @website - redirect_back(fallback_location: [:admin, @object]) - end - protected - def load_from_object - object_type = params[:object_type] - object_id = params[:object_id] - @object = object_type.constantize.find object_id - end - def breadcrumb super add_breadcrumb Communication::Website::Connection.model_name.human(count: 2), admin_communication_website_connections_path diff --git a/app/controllers/admin/communication/websites/pages_controller.rb b/app/controllers/admin/communication/websites/pages_controller.rb index aa248025b..eb8db3a61 100644 --- a/app/controllers/admin/communication/websites/pages_controller.rb +++ b/app/controllers/admin/communication/websites/pages_controller.rb @@ -46,6 +46,18 @@ class Admin::Communication::Websites::PagesController < Admin::Communication::We render layout: 'admin/layouts/preview' end + def connect + load_object + @website.connect @object, @page + head :ok + end + + def disconnect + load_object + @website.disconnect @object, @page + redirect_back(fallback_location: [:admin, @object]) + end + def new @page.website = @website breadcrumb @@ -98,6 +110,12 @@ class Admin::Communication::Websites::PagesController < Admin::Communication::We protected + def load_object + object_type = params[:object_type] + object_id = params[:object_id] + @object = object_type.constantize.find object_id + end + def breadcrumb super add_breadcrumb t('admin.communication.website.pages.structure'), diff --git a/app/views/admin/application/_connections.html.erb b/app/views/admin/application/_connections.html.erb new file mode 100644 index 000000000..d8bc0bbc2 --- /dev/null +++ b/app/views/admin/application/_connections.html.erb @@ -0,0 +1,23 @@ +<%= osuny_panel Communication::Website::Connection.model_name.human(count: 2) do %> + <% about.websites.each do |website| %> + <div class="mb-4"> + <p class="mb-0"><b><%= link_to website, [:admin, website] %></b></p> + <ul class="list-unstyled small"> + <% Communication::Website::Connection.for_object(about).in_website(website).each do |connection| %> + <% + source = connection.source + begin + path = url_for [:admin, source] + rescue + end + path = edit_admin_communication_block_path(source) if source.is_a?(Communication::Block) + path = admin_communication_website_page_path( website_id: website.id, + lang: website.default_language, + id: source) if source.is_special_page? + %> + <li><%= link_to_if path, source, path %></li> + <% end %> + </ul> + </tr> + <% end %> +<% end if about.websites.any? %> \ No newline at end of file diff --git a/app/views/admin/application/a11y/_widget.html.erb b/app/views/admin/application/a11y/_widget.html.erb index db26884e8..6601bcd64 100644 --- a/app/views/admin/application/a11y/_widget.html.erb +++ b/app/views/admin/application/a11y/_widget.html.erb @@ -1,6 +1,6 @@ <% color = about.accessible? ? 'text-success' : 'text-danger' -action = "<i class=\"#{ Icon::A11Y } fa-2x float-end #{ color}\"></i>" +action = "<i class=\"#{ Icon::A11Y } #{ if_appstack 'fa-2x' } h4 float-end #{ color}\"></i>" %> <%= osuny_panel t('accessibility.label'), action: action do %> <% if about.accessibility_errors.any? %> diff --git a/app/views/admin/communication/websites/pages/show/special_pages/_organization.html.erb b/app/views/admin/communication/websites/pages/show/special_pages/_organization.html.erb index ed9ed4035..2001d8934 100644 --- a/app/views/admin/communication/websites/pages/show/special_pages/_organization.html.erb +++ b/app/views/admin/communication/websites/pages/show/special_pages/_organization.html.erb @@ -11,7 +11,7 @@ input_html: { data: { type: 'University::Organization', - target: admin_communication_website_connections_path(lang: nil) + target: connect_admin_communication_website_page_path(@page) } } %> @@ -22,9 +22,9 @@ <tr> <td><%= link_to organization, [:admin, organization] %></td> <td><%= link_to 'Déconnecter', - admin_communication_website_connection_path(id: 'no-id', object_id: organization.id, object_type: organization.class), + disconnect_admin_communication_website_page_path(@page, object_id: organization.id, object_type: organization.class), class: button_classes_danger, - method: :delete %></td> + method: :post %></td> </tr> <% end %> </tbody> diff --git a/app/views/admin/layouts/themes/pure/_panel.html.erb b/app/views/admin/layouts/themes/pure/_panel.html.erb index 653f5538d..5923610f3 100644 --- a/app/views/admin/layouts/themes/pure/_panel.html.erb +++ b/app/views/admin/layouts/themes/pure/_panel.html.erb @@ -5,7 +5,7 @@ <h2 class="mb-3"><%= title %></h2> <% end %> <% if action %> - <div class="ms-5"><%= raw action %></div> + <div class="ms-4"><%= raw action %></div> <% end %> </div> <% if subtitle %> diff --git a/app/views/admin/university/organizations/show.html.erb b/app/views/admin/university/organizations/show.html.erb index 502749291..52be2c05d 100644 --- a/app/views/admin/university/organizations/show.html.erb +++ b/app/views/admin/university/organizations/show.html.erb @@ -87,6 +87,8 @@ <% end if @organization.logo.attached? || @organization.logo_on_dark_background.attached? %> <%= render 'admin/application/meta_description/show', about: @organization %> + + <%= render 'admin/application/connections', about: @organization %> </div> </div> @@ -119,39 +121,6 @@ </div> <% end if @organization.experiences.any? %> -<%= osuny_panel Communication::Website::Connection.model_name.human(count: 2) do %> - <table class="table"> - <thead> - <tr> - <th><%= Communication::Website.model_name.human %></th> - <th><%= Communication::Website::Connection.human_attribute_name(:source) %></th> - </tr> - </thead> - <tbody> - <% @organization.websites.each do |website| %> - <tr> - <td><%= link_to website, [:admin, website] %></td> - <td> - <ul class="list-unstyled"> - <% Communication::Website::Connection.for_object(@organization).in_website(website).each do |connection| %> - <% - begin - path = url_for [:admin, connection.source] - if connection.source.is_a? Communication::Block - path = edit_admin_communication_block_path(connection.source) - end - rescue - end - %> - <li><%= link_to connection.source, path %></li> - <% end %> - </ul> - </td> - </tr> - <% end %> - </tbody> - </table> -<% end if @organization.websites.any? %> <% content_for :action_bar_left do %> <%= destroy_link @organization %> diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 8dd62e40f..76dacb059 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -10,7 +10,7 @@ namespace :communication do get :style get :analytics end - resources :connections, controller: 'websites/connections', except: [:new, :edit] + resources :connections, controller: 'websites/connections', only: [:index, :show] resources :pages, controller: 'websites/pages', path: '/:lang/pages' do collection do post :reorder @@ -21,6 +21,8 @@ namespace :communication do get :preview get "translate" => "websites/pages#translate", as: :translate post :duplicate + post :connect + post :disconnect end end resources :categories, controller: 'websites/categories', path: '/:lang/categories' do -- GitLab