change line encoding of models/topic.rb to unix

This commit is contained in:
Devin Howard 2015-03-01 20:25:39 -05:00
parent 44c8779d89
commit a525f9d89e

View file

@ -1,159 +1,159 @@
class Topic < ActiveRecord::Base class Topic < ActiveRecord::Base
include TopicsHelper include TopicsHelper
belongs_to :user belongs_to :user
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id' has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id'
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id' has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id'
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 has_many :mappings
has_many :maps, :through => :mappings has_many :maps, :through => :mappings
# This method associates the attribute ":image" with a file attachment # This method associates the attribute ":image" with a file attachment
has_attached_file :image has_attached_file :image
#, styles: { #, styles: {
# thumb: '100x100>', # thumb: '100x100>',
# square: '200x200#', # square: '200x200#',
# medium: '300x300>' # medium: '300x300>'
#} #}
# Validate the attached image is image/jpg, image/png, etc # Validate the attached image is image/jpg, image/png, etc
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/ validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
# This method associates the attribute ":image" with a file attachment # This method associates the attribute ":image" with a file attachment
has_attached_file :audio has_attached_file :audio
# Validate the attached audio is audio/wav, audio/mp3, etc # Validate the attached audio is audio/wav, audio/mp3, etc
validates_attachment_content_type :audio, :content_type => /\Aaudio\/.*\Z/ validates_attachment_content_type :audio, :content_type => /\Aaudio\/.*\Z/
def synapses def synapses
synapses1 + synapses2 synapses1 + synapses2
end end
def relatives def relatives
topics1 + topics2 topics1 + topics2
end end
belongs_to :metacode belongs_to :metacode
def user_name def user_name
self.user.name self.user.name
end end
def user_image def user_image
self.user.image.url self.user.image.url
end end
def map_count def map_count
self.maps.count self.maps.count
end end
def synapse_count def synapse_count
self.synapses.count self.synapses.count
end end
def inmaps def inmaps
self.maps.map(&:name) self.maps.map(&:name)
end end
def inmapsLinks def inmapsLinks
self.maps.map(&:id) self.maps.map(&:id)
end end
def as_json(options={}) def as_json(options={})
super(:methods =>[:user_name, :user_image, :map_count, :synapse_count, :inmaps, :inmapsLinks]) super(:methods =>[:user_name, :user_image, :map_count, :synapse_count, :inmaps, :inmapsLinks])
end end
def topic_autocomplete_method def topic_autocomplete_method
"Get: #{self.name}" "Get: #{self.name}"
end end
def mk_permission def mk_permission
if self.permission == "commons" if self.permission == "commons"
"co" "co"
elsif self.permission == "public" elsif self.permission == "public"
"pu" "pu"
elsif self.permission == "private" elsif self.permission == "private"
"pr" "pr"
end end
end end
# has no viewable synapses helper function # has no viewable synapses helper function
def has_viewable_synapses(current) def has_viewable_synapses(current)
result = false result = false
self.synapses.each do |synapse| self.synapses.each do |synapse|
if synapse.authorize_to_view(current) if synapse.authorize_to_view(current)
result = true result = true
end end
end end
return result return result
end end
def synapses_csv(output_format = "array") def synapses_csv(output_format = "array")
output = [] output = []
self.synapses.each do |synapse| self.synapses.each do |synapse|
if synapse.category == "from-to" if synapse.category == "from-to"
if synapse.node1_id == self.id if synapse.node1_id == self.id
output << synapse.node1_id.to_s + "->" + synapse.node2_id.to_s output << synapse.node1_id.to_s + "->" + synapse.node2_id.to_s
elsif synapse.node2_id == self.id elsif synapse.node2_id == self.id
output << synapse.node2_id.to_s + "<-" + synapse.node1_id.to_s output << synapse.node2_id.to_s + "<-" + synapse.node1_id.to_s
else else
abort("invalid synapse on topic in synapse_csv") abort("invalid synapse on topic in synapse_csv")
end end
elsif synapse.category == "both" elsif synapse.category == "both"
if synapse.node1_id == self.id if synapse.node1_id == self.id
output << synapse.node1_id.to_s + "<->" + synapse.node2_id.to_s output << synapse.node1_id.to_s + "<->" + synapse.node2_id.to_s
elsif synapse.node2_id == self.id elsif synapse.node2_id == self.id
output << synapse.node2_id.to_s + "<->" + synapse.node1_id.to_s output << synapse.node2_id.to_s + "<->" + synapse.node1_id.to_s
else else
abort("invalid synapse on topic in synapse_csv") abort("invalid synapse on topic in synapse_csv")
end end
end end
end end
if output_format == "array" if output_format == "array"
return output return output
elsif output_format == "text" elsif output_format == "text"
return output.join("; ") return output.join("; ")
else else
abort("invalid argument to synapses_csv") abort("invalid argument to synapses_csv")
end end
return output return output
end end
##### PERMISSIONS ###### ##### PERMISSIONS ######
# returns false if user not allowed to 'show' Topic, Synapse, or Map # returns false if user not allowed to 'show' Topic, Synapse, or Map
def authorize_to_show(user) def authorize_to_show(user)
if (self.permission == "private" && self.user != user) if (self.permission == "private" && self.user != user)
return false return false
end end
return self return self
end end
# returns false if user not allowed to 'edit' Topic, Synapse, or Map # returns false if user not allowed to 'edit' Topic, Synapse, or Map
def authorize_to_edit(user) def authorize_to_edit(user)
if (self.permission == "private" && self.user != user) if (self.permission == "private" && self.user != user)
return false return false
elsif (self.permission == "public" && self.user != user) elsif (self.permission == "public" && self.user != user)
return false return false
end end
return self return self
end end
def authorize_to_delete(user) def authorize_to_delete(user)
if (self.user != user) if (self.user != user)
return false return false
end end
return self return self
end end
# returns Boolean if user allowed to view Topic, Synapse, or Map # returns Boolean if user allowed to view Topic, Synapse, or Map
def authorize_to_view(user) def authorize_to_view(user)
if (self.permission == "private" && self.user != user) if (self.permission == "private" && self.user != user)
return false return false
end end
return true return true
end end
end end