topic related things weren't working at all
This commit is contained in:
parent
f24def8be6
commit
8bd032472d
2 changed files with 24 additions and 17 deletions
|
@ -24,9 +24,10 @@ class TopicsController < ApplicationController
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
@alltopics = ([@topic] + policy_scope(Topic.relatives(@topic.id)))
|
@alltopics = [@topic].concat(policy_scope(Topic.relatives1(@topic.id)).to_a).concat(policy_scope(Topic.relatives2(@topic.id)).to_a)
|
||||||
@allsynapses = policy_scope(Synapse.for_topic(@topic.id))
|
@allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a
|
||||||
|
puts @alltopics.length
|
||||||
|
puts @allsynapses.length
|
||||||
@allcreators = @alltopics.map(&:user).uniq
|
@allcreators = @alltopics.map(&:user).uniq
|
||||||
@allcreators += @allsynapses.map(&:user).uniq
|
@allcreators += @allsynapses.map(&:user).uniq
|
||||||
|
|
||||||
|
@ -41,8 +42,8 @@ class TopicsController < ApplicationController
|
||||||
@topic = Topic.find(params[:id])
|
@topic = Topic.find(params[:id])
|
||||||
authorize @topic
|
authorize @topic
|
||||||
|
|
||||||
@alltopics = [@topic] + policy_scope(@topic.relatives)
|
@alltopics = [@topic].concat(policy_scope(Topic.relatives1(@topic.id)).to_a).concat(policy_scope(Topic.relatives2(@topic.id)).to_a)
|
||||||
@allsynapses = policy_scope(@topic.synapses)
|
@allsynapses = policy_scope(Synapse.for_topic(@topic.id))
|
||||||
|
|
||||||
@allcreators = @alltopics.map(&:user).uniq
|
@allcreators = @alltopics.map(&:user).uniq
|
||||||
@allcreators += @allsynapses.map(&:user).uniq
|
@allcreators += @allsynapses.map(&:user).uniq
|
||||||
|
@ -65,8 +66,8 @@ class TopicsController < ApplicationController
|
||||||
|
|
||||||
topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : []
|
topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : []
|
||||||
|
|
||||||
@alltopics = policy_scope(@topic.relatives).to_a.uniq
|
@alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq
|
||||||
@alltopics.delete_if! do |topic|
|
@alltopics.delete_if do |topic|
|
||||||
topicsAlreadyHas.index(topic.id) != nil
|
topicsAlreadyHas.index(topic.id) != nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -87,14 +88,15 @@ class TopicsController < ApplicationController
|
||||||
|
|
||||||
topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : []
|
topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : []
|
||||||
|
|
||||||
alltopics = policy_scope(@topic.relatives).to_a.uniq.delete_if do |topic|
|
alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq
|
||||||
|
alltopics.delete_if do |topic|
|
||||||
topicsAlreadyHas.index(topic.id.to_s) != nil
|
topicsAlreadyHas.index(topic.id.to_s) != nil
|
||||||
end
|
end
|
||||||
|
|
||||||
#find synapses between topics in alltopics array
|
#find synapses between topics in alltopics array
|
||||||
allsynapses = policy_scope(@topic.synapses)
|
allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a
|
||||||
synapse_ids = (allsynapses.map(&:topic1_id) + allsynapses.map(&:topic2_id)).uniq
|
synapse_ids = (allsynapses.map(&:node1_id) + allsynapses.map(&:node2_id)).uniq
|
||||||
allsynapses.delete_if! do |synapse|
|
allsynapses.delete_if do |synapse|
|
||||||
synapse_ids.index(synapse.id) != nil
|
synapse_ids.index(synapse.id) != nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ class Topic < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', dependent: :destroy
|
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', dependent: :destroy
|
||||||
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', dependent: :destroy
|
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', dependent: :destroy
|
||||||
has_many :topics1, :through => :synapses2, :source => :topic1
|
has_many :topics1, :through => :synapses2, source: :topic1
|
||||||
has_many :topics2, :through => :synapses1, :source => :topic2
|
has_many :topics2, :through => :synapses1, source: :topic2
|
||||||
|
|
||||||
has_many :mappings, as: :mappable, dependent: :destroy
|
has_many :mappings, as: :mappable, dependent: :destroy
|
||||||
has_many :maps, :through => :mappings
|
has_many :maps, :through => :mappings
|
||||||
|
@ -41,10 +41,15 @@ class Topic < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :metacode
|
belongs_to :metacode
|
||||||
|
|
||||||
scope :relatives, ->(topic_id = nil) {
|
scope :relatives1, ->(topic_id = nil) {
|
||||||
includes(:synapses1)
|
includes(:topics1)
|
||||||
.includes(:synapses2)
|
.where('synapses.node1_id = ?', topic_id)
|
||||||
.where('synapses.node1_id = ? OR synapses.node2_id = ?', topic_id, topic_id)
|
.references(:synapses)
|
||||||
|
}
|
||||||
|
|
||||||
|
scope :relatives2, ->(topic_id = nil) {
|
||||||
|
includes(:topics2)
|
||||||
|
.where('synapses.node2_id = ?', topic_id)
|
||||||
.references(:synapses)
|
.references(:synapses)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue