diff --git a/app/controllers/admin/communication/websites/connections_controller.rb b/app/controllers/admin/communication/websites/connections_controller.rb index 0c0da98dfa2d29911d289f95a625915a06b358f7..4578da5cbab648c049e39de5c0b72a6553d84d06 100644 --- a/app/controllers/admin/communication/websites/connections_controller.rb +++ b/app/controllers/admin/communication/websites/connections_controller.rb @@ -1,16 +1,25 @@ class Admin::Communication::Websites::ConnectionsController < Admin::Communication::Websites::ApplicationController - before_action :load_object, except: :index + before_action :load_from_object, only: [:create, :destroy] def index @connections = @website.connections.page params[:page] breadcrumb end + def show + @connection = @website.connections.find params[:id] + @others = @connection.for_same_object + breadcrumb + add_breadcrumb @connection + end + + # Strange use of create, does not really create a connection def create @website.connect @object head :ok end + # Strange use of destroy, does not really create a connection def destroy @website.disconnect @object redirect_back(fallback_location: [:admin, @object]) @@ -18,7 +27,7 @@ class Admin::Communication::Websites::ConnectionsController < Admin::Communicati protected - def load_object + def load_from_object object_type = params[:object_type] object_id = params[:object_id] @object = object_type.constantize.find object_id @@ -26,6 +35,6 @@ class Admin::Communication::Websites::ConnectionsController < Admin::Communicati def breadcrumb super - add_breadcrumb Communication::Website::Connection.model_name.human(count: 2) + add_breadcrumb Communication::Website::Connection.model_name.human(count: 2), admin_communication_website_connections_path end end \ No newline at end of file diff --git a/app/models/communication/website/connection.rb b/app/models/communication/website/connection.rb index 425d0594f2bea1314ef9f5a2553e5d12d64db77a..cc486243778cb82bf2ee9c00c3192f98f9eafe83 100644 --- a/app/models/communication/website/connection.rb +++ b/app/models/communication/website/connection.rb @@ -29,4 +29,15 @@ class Communication::Website::Connection < ApplicationRecord belongs_to :website belongs_to :object, polymorphic: true belongs_to :source, polymorphic: true, optional: true + + def for_same_object + self.class.where( university: university, + website: website, + object: object) + .where.not(id: id) + end + + def to_s + "#{id}" + end end diff --git a/app/models/communication/website/with_connections.rb b/app/models/communication/website/with_connections.rb index c90c7af3d687496ad46feabce95eb501d049f9d7..99a98d148340a16c9f1afff13b2297f89cb256d2 100644 --- a/app/models/communication/website/with_connections.rb +++ b/app/models/communication/website/with_connections.rb @@ -13,9 +13,9 @@ module Communication::Website::WithConnections end def clean_connections! - # start = Time.now + start = Time.now connect self - # connections.where('updated_at < ?', start).destroy_all + connections.where('updated_at < ?', start).destroy_all end def connect(object, source = nil) @@ -25,6 +25,7 @@ module Communication::Website::WithConnections puts "#{dependencies.count} dependencies to connect" dependencies.each do |dependency| connect_object dependency, source + connect_object dependency, object end end diff --git a/app/views/admin/communication/websites/connections/_list.html.erb b/app/views/admin/communication/websites/connections/_list.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..4a42f37bcb029f1eb1e25bc098b06a1706541d0c --- /dev/null +++ b/app/views/admin/communication/websites/connections/_list.html.erb @@ -0,0 +1,40 @@ +<div class="table-responsive"> + <table class="<%= table_classes %>"> + <thead> + <tr> + <th><%= Communication::Website::Connection.human_attribute_name('id') %></th> + <th><%= Communication::Website::Connection.human_attribute_name('object') %></th> + <th><%= Communication::Website::Connection.human_attribute_name('object_type') %></th> + <th><%= Communication::Website::Connection.human_attribute_name('source') %></th> + <th><%= Communication::Website::Connection.human_attribute_name('source_type') %></th> + <th><%= Communication::Website::Connection.human_attribute_name('updated_at') %></th> + </tr> + </thead> + <tbody> + <% connections.each do |connection| %> + <% + object = connection.object + object_name = object.to_s + object_name = object.id if object.is_a?(ActiveStorage::Blob) + begin + object_link = url_for [:admin, object] + rescue + end + source = connection.source + begin + source_link = url_for [:admin, source] + rescue + end + %> + <tr> + <td><%= link_to connection, [:admin, connection] %></td> + <td><%= link_to_if object_link, object_name, object_link %></td> + <td><%= connection.object_type %></td> + <td><%= link_to_if source_link, source, source_link %></td> + <td><%= connection.source_type %></td> + <td><%= l connection.updated_at %></td> + </tr> + <% end %> + </tbody> + </table> +</div> \ No newline at end of file diff --git a/app/views/admin/communication/websites/connections/index.html.erb b/app/views/admin/communication/websites/connections/index.html.erb index add7e82185f2bde47284b994be195c56ff57c382..6dd7d698cb71f851b10bb4f54ab77aa9d2b8618a 100644 --- a/app/views/admin/communication/websites/connections/index.html.erb +++ b/app/views/admin/communication/websites/connections/index.html.erb @@ -1,43 +1,5 @@ <% content_for :title, Communication::Website::Connection.model_name.human(count: 2) %> <% content_for :title_right, @connections.total_count %> -<div class="table-responsive"> - <table class="<%= table_classes %>"> - <thead> - <tr> - <th><%= Communication::Website::Connection.human_attribute_name('object') %></th> - <th><%= Communication::Website::Connection.human_attribute_name('object_type') %></th> - <th><%= Communication::Website::Connection.human_attribute_name('source') %></th> - <th><%= Communication::Website::Connection.human_attribute_name('source_type') %></th> - <th><%= Communication::Website::Connection.human_attribute_name('updated_at') %></th> - </tr> - </thead> - <tbody> - <% @connections.each do |connection| %> - <% - object = connection.object - object_name = object.to_s - object_name = object.id if object.is_a?(ActiveStorage::Blob) - begin - object_link = url_for [:admin, object] - rescue - end - source = connection.source - begin - source_link = url_for [:admin, source] - rescue - end - %> - <tr> - <td><%= link_to_if object_link, object_name, object_link %></td> - <td><%= connection.object_type %></td> - <td><%= link_to_if source_link, source, source_link %></td> - <td><%= connection.source_type %></td> - <td><%= l connection.updated_at %></td> - </tr> - <% end %> - </tbody> - </table> -</div> - +<%= render 'admin/communication/websites/connections/list', connections: @connections %> <%= paginate @connections, theme: 'bootstrap-5' %> \ No newline at end of file diff --git a/app/views/admin/communication/websites/connections/show.html.erb b/app/views/admin/communication/websites/connections/show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..10be4f529a00ffb5ee1ec1d4e1d4df597268f980 --- /dev/null +++ b/app/views/admin/communication/websites/connections/show.html.erb @@ -0,0 +1,24 @@ +<% content_for :title, @connection %> + +<div class="row"> + <div class="col-lg-6 mb-5"> + <%= osuny_label Communication::Website::Connection.human_attribute_name('object') %> + <p><%= @connection.object %></p> + <%= osuny_label Communication::Website::Connection.human_attribute_name('object_type') %> + <p><%= @connection.object_type %></p> + <%= osuny_label Communication::Website::Connection.human_attribute_name('object_id') %> + <p><%= @connection.object_id %></p> + </div> + <div class="col-lg-6 mb-5"> + <%= osuny_label Communication::Website::Connection.human_attribute_name('source') %> + <p><%= @connection.source %></p> + <%= osuny_label Communication::Website::Connection.human_attribute_name('source_type') %> + <p><%= @connection.source_type %></p> + <%= osuny_label Communication::Website::Connection.human_attribute_name('source_id') %> + <p><%= @connection.source_id %></p> + </div> +</div> + +<%= osuny_panel Communication::Website::Connection.human_attribute_name('others') do %> + <%= render 'admin/communication/websites/connections/list', connections: @others %> +<% end %> \ No newline at end of file diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 093c4fe60e8e164a5554eb1932abb52991b3fb2f..8dd62e40f6097f437edc00686a1aa028704932c8 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', only: [:index, :create, :destroy] + resources :connections, controller: 'websites/connections', except: [:new, :edit] resources :pages, controller: 'websites/pages', path: '/:lang/pages' do collection do post :reorder