change from category/topic_id/synapse_id to mappable_type/mappable_id
This commit is contained in:
parent
5dc53543f7
commit
3e8c971155
3 changed files with 15 additions and 25 deletions
|
@ -457,11 +457,11 @@ Metamaps.Backbone.init = function () {
|
|||
return Metamaps.Map.get(this.get('map_id'));
|
||||
},
|
||||
getTopic: function () {
|
||||
if (this.get('category') === 'Topic') return Metamaps.Topic.get(this.get('topic_id'));
|
||||
if (this.get('mappable_type') === 'Topic') return Metamaps.Topic.get(this.get('mappable_id'));
|
||||
else return false;
|
||||
},
|
||||
getSynapse: function () {
|
||||
if (this.get('category') === 'Synapse') return Metamaps.Synapse.get(this.get('synapse_id'));
|
||||
if (this.get('mappable_type') === 'Synapse') return Metamaps.Synapse.get(this.get('mappable_id'));
|
||||
else return false;
|
||||
}
|
||||
});
|
||||
|
@ -4109,10 +4109,10 @@ Metamaps.Topic = {
|
|||
Metamaps.Topics.add(topic);
|
||||
|
||||
var mapping = new Metamaps.Backbone.Mapping({
|
||||
category: "Topic",
|
||||
xloc: Metamaps.Create.newTopic.x,
|
||||
yloc: Metamaps.Create.newTopic.y,
|
||||
topic_id: topic.cid
|
||||
mappable_id: topic.cid,
|
||||
mappable_type: "Topic",
|
||||
});
|
||||
Metamaps.Mappings.add(mapping);
|
||||
|
||||
|
@ -4131,10 +4131,10 @@ Metamaps.Topic = {
|
|||
var topic = self.get(id);
|
||||
|
||||
var mapping = new Metamaps.Backbone.Mapping({
|
||||
category: "Topic",
|
||||
xloc: Metamaps.Create.newTopic.x,
|
||||
yloc: Metamaps.Create.newTopic.y,
|
||||
topic_id: topic.id
|
||||
mappable_type: "Topic",
|
||||
mappable_id: topic.id,
|
||||
});
|
||||
Metamaps.Mappings.add(mapping);
|
||||
|
||||
|
@ -4149,10 +4149,10 @@ Metamaps.Topic = {
|
|||
|
||||
var nextCoords = Metamaps.Map.getNextCoord();
|
||||
var mapping = new Metamaps.Backbone.Mapping({
|
||||
category: "Topic",
|
||||
xloc: nextCoords.x,
|
||||
yloc: nextCoords.y,
|
||||
topic_id: topic.id
|
||||
mappable_type: "Topic",
|
||||
mappable_id: topic.id,
|
||||
});
|
||||
Metamaps.Mappings.add(mapping);
|
||||
|
||||
|
@ -4287,8 +4287,8 @@ Metamaps.Synapse = {
|
|||
Metamaps.Synapses.add(synapse);
|
||||
|
||||
mapping = new Metamaps.Backbone.Mapping({
|
||||
category: "Synapse",
|
||||
synapse_id: synapse.cid
|
||||
mappable_type: "Synapse",
|
||||
mappable_id: synapse.cid,
|
||||
});
|
||||
Metamaps.Mappings.add(mapping);
|
||||
|
||||
|
@ -4308,8 +4308,8 @@ Metamaps.Synapse = {
|
|||
var synapse = self.get(id);
|
||||
|
||||
var mapping = new Metamaps.Backbone.Mapping({
|
||||
category: "Synapse",
|
||||
synapse_id: synapse.id
|
||||
mappable_type: "Synapse",
|
||||
mappable_id: synapse.id,
|
||||
});
|
||||
Metamaps.Mappings.add(mapping);
|
||||
|
||||
|
|
|
@ -52,6 +52,6 @@ class MappingsController < ApplicationController
|
|||
private
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def mapping_params
|
||||
params.require(:mapping).permit(:id, :category, :xloc, :yloc, :topic_id, :synapse_id, :map_id, :user_id)
|
||||
params.require(:mapping).permit(:id, :xloc, :yloc, :mappable_id, :mappable_type, :map_id, :user_id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -75,11 +75,7 @@ class MapsController < ApplicationController
|
|||
@alltopics = @map.topics.to_a.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
|
||||
@allsynapses = @map.synapses.to_a.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) }
|
||||
@allmappings = @map.mappings.to_a.delete_if {|m|
|
||||
if m.category == "Synapse"
|
||||
object = m.synapse
|
||||
elsif m.category == "Topic"
|
||||
object = m.topic
|
||||
end
|
||||
object = m.mappable
|
||||
!object || (object.permission == "private" && (!authenticated? || (authenticated? && @current.id != object.user_id)))
|
||||
}
|
||||
|
||||
|
@ -103,11 +99,7 @@ class MapsController < ApplicationController
|
|||
@alltopics = @map.topics.to_a.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
|
||||
@allsynapses = @map.synapses.to_a.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) }
|
||||
@allmappings = @map.mappings.to_a.delete_if {|m|
|
||||
if m.category == "Synapse"
|
||||
object = m.synapse
|
||||
elsif m.category == "Topic"
|
||||
object = m.topic
|
||||
end
|
||||
object = m.mappable
|
||||
!object || (object.permission == "private" && (!authenticated? || (authenticated? && @current.id != object.user_id)))
|
||||
}
|
||||
|
||||
|
@ -141,7 +133,6 @@ class MapsController < ApplicationController
|
|||
@all.each do |topic|
|
||||
topic = topic.split('/')
|
||||
@mapping = Mapping.new()
|
||||
@mapping.category = "Topic"
|
||||
@mapping.user = @user
|
||||
@mapping.map = @map
|
||||
@mapping.topic = Topic.find(topic[0])
|
||||
|
@ -155,7 +146,6 @@ class MapsController < ApplicationController
|
|||
@synAll = @synAll.split(',')
|
||||
@synAll.each do |synapse_id|
|
||||
@mapping = Mapping.new()
|
||||
@mapping.category = "Synapse"
|
||||
@mapping.user = @user
|
||||
@mapping.map = @map
|
||||
@mapping.synapse = Synapse.find(synapse_id)
|
||||
|
|
Loading…
Reference in a new issue