Skip to content
Snippets Groups Projects
Commit 841a5fe3 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

wip

parent ee84fbc9
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ class Admin::Communication::Websites::ConnectionsController < Admin::Communicati
before_action :load_from_object, only: [:create, :destroy]
def index
@connections = @website.connections.page params[:page]
@connections = @website.connections.ordered.page params[:page]
breadcrumb
end
......@@ -15,13 +15,13 @@ class Admin::Communication::Websites::ConnectionsController < Admin::Communicati
# Strange use of create, does not really create a connection
def create
@website.connect @object
@website.connect @object, @website
head :ok
end
# Strange use of destroy, does not really create a connection
def destroy
@website.disconnect @object
@website.disconnect @object, @website
redirect_back(fallback_location: [:admin, @object])
end
......
......@@ -17,10 +17,4 @@ class Communication::Block::Template::Partner < Communication::Block::Template::
def organizations
@organizations ||= elements.collect(&:organization).compact.uniq
end
def connect
organizations.each do |organization|
website.connect organization
end if website
end
end
......@@ -28,7 +28,9 @@ class Communication::Website::Connection < ApplicationRecord
belongs_to :university
belongs_to :website
belongs_to :object, polymorphic: true
belongs_to :source, polymorphic: true, optional: true
belongs_to :source, polymorphic: true
scope :ordered, -> { order(updated_at: :desc, )}
def for_same_object
self.class.where( university: university,
......@@ -38,6 +40,6 @@ class Communication::Website::Connection < ApplicationRecord
end
def to_s
"#{id}"
"#{id.split('-').first}"
end
end
......@@ -14,35 +14,37 @@ module Communication::Website::WithConnections
def clean_connections!
start = Time.now
connect self, self
connect self
# connections.where('updated_at < ?', start).destroy_all
end
def connect(object, source = nil)
source = object if source.nil?
connect_object object, source
return unless object.respond_to?(:dependencies)
dependencies = object.dependencies
puts "#{dependencies.count} dependencies to connect"
dependencies.each do |dependency|
# Connexion à la source primaire
connect_object dependency, source
# Connexion à la dépendance la plus proche
connect_object dependency, object
end
end
# TODO pas pensé
def disconnect(object, source = nil)
source = object if source.nil?
disconnect_object object, source
return unless object.respond_to?(:dependencies)
object.dependencies.each do |dependency|
disconnect_object dependency, source
disconnect_object dependency, object # Faut-il la double connexion ?
end
end
protected
def connect_object(object, source)
puts "connect_object #{object} from #{source}"
# puts "connect_object #{object} from #{source}"
connection = connections.where(university: university, object: object, source: source).first_or_create
connection.touch if connection.persisted?
end
......
......@@ -9,9 +9,9 @@ module WithWebsites
def connect_to_websites
if respond_to?(:website)
website.connect self, self
website.connect self
elsif respond_to?(:websites)
websites.each { |website| website.connect self, self }
websites.each { |website| website.connect self }
end
end
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment