diff --git a/app/assets/javascripts/metamaps/Metamaps.Backbone.js b/app/assets/javascripts/metamaps/Metamaps.Backbone.js
index b36e77a9..d75814c6 100644
--- a/app/assets/javascripts/metamaps/Metamaps.Backbone.js
+++ b/app/assets/javascripts/metamaps/Metamaps.Backbone.js
@@ -25,10 +25,4 @@ Metamaps.Backbone.Mapper = Backbone.Model.extend({
Metamaps.Backbone.MapperCollection = Backbone.Collection.extend({
model: Metamaps.Backbone.Mapper,
url: '/users'
-});
-Metamaps.Active.Mapper = new Metamaps.Backbone.Mapper({
- id: userid,
- name: username
-});
-Metamaps.Mappers = new Metamaps.Backbone.MapperCollection([Metamaps.Active.Mapper]);
-Metamaps.Maps = new Metamaps.Backbone.MapsCollection();
\ No newline at end of file
+});
\ No newline at end of file
diff --git a/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js b/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js
index 8e4ae2ae..3e517193 100644
--- a/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js
+++ b/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js
@@ -65,7 +65,6 @@ Metamaps.GlobalUI = {
var self = Metamaps.GlobalUI;
self.Search.init();
- self.MainMenu.init();
self.CreateMap.init();
self.Account.init();
@@ -81,6 +80,11 @@ Metamaps.GlobalUI = {
// hide notices after 10 seconds
$('.notice.metamaps').delay(10000).fadeOut('fast');
$('.alert.metamaps').delay(10000).fadeOut('fast');
+
+ // initialize global backbone models and collections
+ Metamaps.Active.Mapper = new Metamaps.Backbone.Mapper(Metamaps.Active.Mapper);
+ Metamaps.Mappers = new Metamaps.Backbone.MapperCollection([Metamaps.Active.Mapper]);
+ Metamaps.Maps = new Metamaps.Backbone.MapsCollection();
},
openLightbox: function (which) {
var self = Metamaps.GlobalUI;
@@ -91,7 +95,18 @@ Metamaps.GlobalUI = {
self.lightbox = which;
$('#lightbox_overlay').show();
- $('#lightbox_main').css('margin-top', '-' + ($('#lightbox_main').height() / 2) + 'px');
+
+ var heightOfContent = '-' + ($('#lightbox_main').height() / 2) + 'px';
+ // animate the content in from the bottom
+ $('#lightbox_main').animate({
+ 'top': '50%',
+ 'margin-top': heightOfContent
+ }, 200, 'easeOutCubic');
+
+ // fade the black overlay in
+ $('#lightbox_screen').animate({
+ 'opacity': '0.42'
+ }, 200);
if (Metamaps.Create && !Metamaps.Create.metacodeScrollerInit) {
$('.customMetacodeList, .metacodeSetList').mCustomScrollbar({
@@ -111,7 +126,19 @@ Metamaps.GlobalUI = {
var self = Metamaps.GlobalUI;
if (event) event.preventDefault();
- $('#lightbox_overlay').hide();
+
+ // animate the lightbox content offscreen
+ $('#lightbox_main').animate({
+ 'top': '100%',
+ 'margin-top': '0'
+ }, 200, 'easeInCubic');
+
+ // fade the black overlay out
+ $('#lightbox_screen').animate({
+ 'opacity': '0.0'
+ }, 200, function () {
+ $('#lightbox_overlay').hide();
+ });
if (self.lightbox === 'forkmap') Metamaps.GlobalUI.CreateMap.reset('fork_map');
if (self.lightbox === 'newmap') Metamaps.GlobalUI.CreateMap.reset('new_map');
@@ -135,72 +162,6 @@ Metamaps.GlobalUI = {
}
};
-Metamaps.GlobalUI.MainMenu = {
- isOpen: false,
- timeOut: null,
- changing: false,
- init: function () {
- var self = Metamaps.GlobalUI.MainMenu;
-
- $(".logo").hover(self.open, self.close);
-
- // when on touch screen, make touching on the logo do what hovering does on desktop
- $("#mainTitle a").bind('touchend', function (evt) {
- if (!self.isOpen) {
- self.openMenu();
- evt.preventDefault();
- evt.stopPropagation();
- }
- });
- },
- open: function () {
- var self = Metamaps.GlobalUI.MainMenu;
-
- clearTimeout(self.timeOut);
- if (!self.isOpen && !self.changing) {
- self.changing = true;
-
- // toggle the upper right rounded corner off
- $('.footer').css('border-top-right-radius', '0');
-
- // move the hamburger menu icon a little bit further out
- $('.logo').animate({
- 'background-position-x': '-7px'
- }, 200);
-
- // fade the main part of the menu in
- $('.footer .menu').fadeIn(200, function () {
- self.changing = false;
- self.isOpen = true;
- });
- }
- },
- close: function () {
- var self = Metamaps.GlobalUI.MainMenu;
-
- self.timeOut = setTimeout(function () {
- if (!self.changing) {
- self.changing = true;
-
- // set back to having a rounder upper right corner
- $('.footer').css('border-top-right-radius', '5px');
-
- // move the hamburger menu icon further to the left, more hidden again
- $('.logo').animate({
- 'background-position-x': '-10px'
- }, 200);
-
- // fade out the main menu
- $('.footer .menu').fadeOut(200, function () {
- self.changing = false;
- self.isOpen = false;
- });
- }
- }, 500);
- }
-};
-
-
Metamaps.GlobalUI.CreateMap = {
newMap: null,
emptyMapForm: "",
@@ -431,9 +392,8 @@ Metamaps.GlobalUI.Search = {
startTypeahead: function () {
var self = Metamaps.GlobalUI.Search;
- // TODO stop using userid
- var mapheader = userid ? '
added by me
' : '
';
- var topicheader = userid ? 'added by me
' : '
';
+ var mapheader = Metamaps.Active.Mapper ? 'added by me
' : '
';
+ var topicheader = Metamaps.Active.Mapper ? 'added by me
' : '
';
var mapperheader = '
';
var topics = {
@@ -447,8 +407,8 @@ Metamaps.GlobalUI.Search = {
url: '/search/topics?term=%QUERY',
replace: function () {
var q = '/search/topics?term=' + $('.sidebarSearchField').val();
- if ($("#limitTopicsToMe").is(':checked')) {
- q += "&user=" + userid.toString();
+ if (Metamaps.Active.Mapper && $("#limitTopicsToMe").is(':checked')) {
+ q += "&user=" + Metamaps.Active.Mapper.id.toString();
}
return q;
},
@@ -479,8 +439,8 @@ Metamaps.GlobalUI.Search = {
url: '/search/maps?term=%QUERY',
replace: function () {
var q = '/search/maps?term=' + $('.sidebarSearchField').val();
- if ($("#limitMapsToMe").is(':checked')) {
- q += "&user=" + userid.toString();
+ if (Metamaps.Active.Mapper && $("#limitMapsToMe").is(':checked')) {
+ q += "&user=" + Metamaps.Active.Mapper.id.toString();
}
return q;
},
diff --git a/app/assets/javascripts/metamaps/Metamaps.JIT.js b/app/assets/javascripts/metamaps/Metamaps.JIT.js
index 08a2b906..3c372c64 100644
--- a/app/assets/javascripts/metamaps/Metamaps.JIT.js
+++ b/app/assets/javascripts/metamaps/Metamaps.JIT.js
@@ -15,7 +15,7 @@ Metamaps.JIT = {
prepareVizData: function () {
var self = Metamaps.JIT;
var topic;
-
+ var mapping;
var node;
var nodes = {};
var existingEdge;
@@ -32,19 +32,19 @@ Metamaps.JIT = {
existingEdge = _.findWhere(edges, {
nodeFrom: edge.nodeFrom,
nodeTo: edge.nodeTo
- });
- // also try the opposite
- if (!existingEdge) {
- existingEdge = _.findWhere(edges, {
+ }) ||
+ _.findWhere(edges, {
nodeFrom: edge.nodeTo,
nodeTo: edge.nodeFrom
});
- }
if (existingEdge) {
// for when you're dealing with multiple relationships between the same two topics
- existingEdge['$mappingIDs'].push(m.isNew() ? m.cid : m.id);
- existingEdge['$synapseIDs'].push(m.get('synapse_id'));
+ if (Metamaps.Active.Map) {
+ mapping = s.getMapping();
+ existingEdge['$mappingIDs'].push(mapping.isNew() ? mapping.cid : mapping.id);
+ }
+ existingEdge['$synapseIDs'].push(s.id);
} else {
// for when you're dealing with a topic that has relationships to many different nodes
nodes[edge.nodeFrom].adjacencies.push(edge);
@@ -358,7 +358,7 @@ Metamaps.JIT = {
var pos = node.pos.getc(true),
dim = node.getData('dim'),
topic = node.getData('topic'),
- cat = topic ? topic.getMetacode().get('name') : false,
+ metacode = topic ? topic.getMetacode() : false,
ctx = canvas.getCtx();
// if the topic is selected draw a circle around it
@@ -370,13 +370,17 @@ Metamaps.JIT = {
ctx.stroke();
}
- if (!cat || !imgArray[cat].complete || (typeof imgArray[cat].naturalWidth !== "undefined" && imgArray[cat].naturalWidth === 0)) {
+ if (!metacode ||
+ !metacode.get('image') ||
+ !metacode.get('image').complete ||
+ (typeof metacode.get('image').naturalWidth !== "undefined" &&
+ metacode.get('image').naturalWidth === 0)) {
ctx.beginPath();
ctx.arc(pos.x, pos.y, dim, 0, 2 * Math.PI, false);
ctx.fillStyle = '#B6B2FD';
ctx.fill();
} else {
- ctx.drawImage(imgArray[cat], pos.x - dim, pos.y - dim, dim * 2, dim * 2);
+ ctx.drawImage(metacode.get('image'), pos.x - dim, pos.y - dim, dim * 2, dim * 2);
}
},
'contains': function (node, pos) {
@@ -415,27 +419,6 @@ Metamaps.JIT = {
return $jit.Graph.Plot.edgeHelper.line.contains(from, to, pos, adj.Edge.epsilon);
}
}
- },
- embed: {
- graphSettings: {
-
- },
- nodeSettings: {
-
- },
- edgeSettings: {
- 'customEdge': {
- 'render': function (adj, canvas) {
- Metamaps.JIT.edgeRenderEmbed(adj, canvas)
- },
- 'contains': function (adj, pos) {
- var from = adj.nodeFrom.pos.getc(true),
- to = adj.nodeTo.pos.getc(true);
-
- return this.edgeHelper.line.contains(from, to, pos, adj.Edge.epsilon);
- }
- }
- }
}
}, // ForceDirected
ForceDirected3D: {
@@ -525,17 +508,6 @@ Metamaps.JIT = {
},
edgeSettings: {
- },
- embed: {
- graphSettings: {
-
- },
- nodeSettings: {
-
- },
- edgeSettings: {
-
- }
}
}, // ForceDirected3D
RGraph: {
@@ -546,205 +518,18 @@ Metamaps.JIT = {
Metamaps.Visualize.mGraph.busy = false;
}
},
- graphSettings: {
- //id of the visualization container
- injectInto: 'infovis',
- //Enable zooming and panning
- //by scrolling and DnD
- Navigation: {
- enable: true,
- type: 'HTML',
- //Enable panning events only if we're dragging the empty
- //canvas (and not a node).
- panning: 'avoid nodes',
- zooming: 28 //zoom speed. higher is more sensible
- },
- background: {
- type: 'Metamaps',
+ // this will just be used to patch the ForceDirected graphsettings with the few things which actually differ
+ background: {
+ //type: 'Metamaps',
+ levelDistance: 200,
+ numberOfCircles: 4,
CanvasStyles: {
strokeStyle: '#333',
lineWidth: 1.5
}
- },
- //NodeStyles: {
- // enable: true,
- // type: 'Native',
- // stylesHover: {
- // dim: 30
- // },
- // duration: 300
- //},
- // Change node and edge styles such as
- // color and width.
- // These properties are also set per node
- // with dollar prefixed data-properties in the
- // JSON structure.
- Node: {
- overridable: true,
- color: '#2D6A5D',
- type: 'customNode',
- dim: 25
- },
- Edge: {
- overridable: true,
- color: '#222222',
- type: 'customEdge',
- lineWidth: 2,
- alpha: 0.4
- },
- //Native canvas text styling
- Label: {
- type: 'HTML', //Native or HTML
- size: 20,
- //style: 'bold'
- },
- //Add Tips
- Tips: {
- enable: false,
- onShow: function (tip, node) {}
- },
- // Add node events
- Events: {
- enable: true,
- enableForEdges: true,
- type: 'HTML',
- onMouseMove: function (node, eventInfo, e) {
- Metamaps.JIT.onMouseMoveHandler(node, eventInfo, e);
- },
- //Update node positions when dragged
- onDragMove: function (node, eventInfo, e) {
- Metamaps.JIT.onDragMoveTopicHandler(node, eventInfo, e);
- },
- onDragEnd: function (node, eventInfo, e) {
- Metamaps.JIT.onDragEndTopicHandler(node, eventInfo, e, false);
- },
- onDragCancel: function (node, eventInfo, e) {
- Metamaps.JIT.onDragCancelHandler(node, eventInfo, e, false);
- },
- //Implement the same handler for touchscreens
- onTouchStart: function (node, eventInfo, e) {
- //$jit.util.event.stop(e); //stop default touchmove event
- //Metamaps.Visualize.mGraph.events.onMouseDown(e, null, eventInfo);
- Metamaps.Visualize.mGraph.events.touched = true;
- Metamaps.Touch.touchPos = eventInfo.getPos();
- var canvas = Metamaps.Visualize.mGraph.canvas,
- ox = canvas.translateOffsetX;
- oy = canvas.translateOffsetY,
- sx = canvas.scaleOffsetX,
- sy = canvas.scaleOffsetY;
- Metamaps.Touch.touchPos.x *= sx;
- Metamaps.Touch.touchPos.y *= sy;
- Metamaps.Touch.touchPos.x += ox;
- Metamaps.Touch.touchPos.y += oy;
-
- touchDragNode = node;
- },
- //Implement the same handler for touchscreens
- onTouchMove: function (node, eventInfo, e) {
- if (Metamaps.Touch.touchDragNode) Metamaps.JIT.onDragMoveTopicHandler(Metamaps.Touch.touchDragNode, eventInfo, e);
- else {
- Metamaps.JIT.touchPanZoomHandler(eventInfo, e);
- Metamaps.Visualize.mGraph.labels.hideLabel(Metamaps.Visualize.mGraph.graph.getNode(Metamaps.TopicCard.openTopicCard));
- }
- },
- //Implement the same handler for touchscreens
- onTouchEnd: function (node, eventInfo, e) {
-
- },
- //Implement the same handler for touchscreens
- onTouchCancel: function (node, eventInfo, e) {
-
- },
- //Add also a click handler to nodes
- onClick: function (node, eventInfo, e) {
-
- if (Metamaps.Mouse.boxStartCoordinates) {
- Metamaps.Visualize.mGraph.busy = false;
- Metamaps.Mouse.boxEndCoordinates = eventInfo.getPos();
- Metamaps.JIT.selectNodesWithBox();
- return;
- }
-
- if (e.target.id != "infovis-canvas") return false;
-
- //clicking on a edge, node, or clicking on blank part of canvas?
- if (node.nodeFrom) {
- Metamaps.JIT.selectEdgeOnClickHandler(node, e);
- } else if (node && !node.nodeFrom) {
- Metamaps.JIT.selectNodeOnClickHandler(node, e);
- } else {
- Metamaps.JIT.canvasClickHandler(eventInfo.getPos(), e);
- } //if
- }
- },
- //Number of iterations for the FD algorithm
- iterations: 200,
- //Edge length
- levelDistance: 200,
},
- nodeSettings: {
- 'customNode': {
- 'render': function (node, canvas) {
- var pos = node.pos.getc(true),
- dim = node.getData('dim'),
- cat = node.getData('metacode'),
- ctx = canvas.getCtx();
- // if the topic is on the Canvas draw a white circle around it
- if (node.selected) {
- ctx.beginPath();
- ctx.arc(pos.x, pos.y, dim + 3, 0, 2 * Math.PI, false);
- ctx.strokeStyle = Metamaps.Settings.colors.topics.selected;
- ctx.lineWidth = 2;
- ctx.stroke();
- }
- try {
- ctx.drawImage(imgArray[cat], pos.x - dim, pos.y - dim, dim * 2, dim * 2);
- } catch (e) {
- alert("You've got an topic causing an issue! It's ->this-> one: " + cat);
- }
- },
- 'contains': function (node, pos) {
- var npos = node.pos.getc(true),
- dim = node.getData('dim');
- return this.nodeHelper.circle.contains(npos, pos, dim);
- }
- }
- },
- edgeSettings: {
- 'customEdge': {
- 'render': function (adj, canvas) {
- Metamaps.JIT.edgeRender(adj, canvas)
- },
- 'contains': function (adj, pos) {
- var from = adj.nodeFrom.pos.getc(true),
- to = adj.nodeTo.pos.getc(true);
-
- return this.edgeHelper.line.contains(from, to, pos, adj.Edge.epsilon);
- }
- }
- },
- embed: {
- graphSettings: {
-
- },
- nodeSettings: {
-
- },
- edgeSettings: {
- 'customEdge': {
- 'render': function (adj, canvas) {
- Metamaps.JIT.edgeRenderEmbed(adj, canvas)
- },
- 'contains': function (adj, pos) {
- var from = adj.nodeFrom.pos.getc(true),
- to = adj.nodeTo.pos.getc(true);
-
- return this.edgeHelper.line.contains(from, to, pos, adj.Edge.epsilon);
- }
- }
- }
- }
- }, // RGraph
+ levelDistance: 200
+ },
onMouseEnter: function (edge) {
$('canvas').css('cursor', 'pointer');
@@ -928,7 +713,7 @@ Metamaps.JIT = {
Metamaps.Visualize.mGraph.plot();
}
// if it's a right click or holding down alt, start synapse creation ->third option is for firefox
- else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && userid != null) {
+ else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && Metamaps.Active.Mapper) {
if (tempInit == false) {
tempNode = node;
tempInit = true;
@@ -1070,7 +855,7 @@ Metamaps.JIT = {
}, // nodeDoubleClickHandler
edgeDoubleClickHandler: function (adj, e) {
- Metamaps.SynapseCard.showCard(adj, e);
+ Metamaps.SynapseCard.showCard(adj, e);
}, // nodeDoubleClickHandler
nodeWasDoubleClicked: function () {
@@ -1212,13 +997,13 @@ Metamaps.JIT = {
// add the proper options to the menu
var menustring = '';
- if (userid != null) menustring += 'Delete ';
- if (Metamaps.Active.Map.id && userid != null) menustring += 'Remove from map ';
+ if (Metamaps.Active.Mapper) menustring += 'Delete ';
+ if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += 'Remove from map ';
menustring += 'Hide until refresh ';
if (!Metamaps.Active.Map) menustring += 'Center this topic ';
menustring += 'Open in new tab ';
- if (userid) {
+ if (Metamaps.Active.Mapper) {
var options = 'commons \
public \
private \
@@ -1329,8 +1114,8 @@ Metamaps.JIT = {
// the 'node' variable is a JIT node, the one that was clicked on
// the 'e' variable is the click event
- var authorized;
-
+ var authorized;
+
e.preventDefault();
e.stopPropagation();
diff --git a/app/assets/javascripts/metamaps/metamaps.js b/app/assets/javascripts/metamaps/metamaps.js
index 6b7be77e..cc796c14 100644
--- a/app/assets/javascripts/metamaps/metamaps.js
+++ b/app/assets/javascripts/metamaps/metamaps.js
@@ -78,10 +78,16 @@ Metamaps.Mappings = {}; // will be initialized in Metamaps.Backbone.init as a Ma
Metamaps.Backbone.init = function () {
var self = Metamaps.Backbone;
- self.Metacode = Backbone.Model.extend({});
+ self.Metacode = Backbone.Model.extend({
+ initialize: function () {
+ var image = new Image();
+ image.src = this.get('icon');
+ this.set('image',image);
+ }
+ });
self.MetacodeCollection = Backbone.Collection.extend({
model: this.Metacode,
- url: '/metacodes'
+ url: '/metacodes',
});
self.Topic = Backbone.Model.extend({
@@ -118,6 +124,9 @@ Metamaps.Backbone.init = function () {
return Metamaps.Metacodes.get(this.get('metacode_id'));
},
getMapping: function () {
+
+ if (!Metamaps.Active.Map) return false;
+
return Metamaps.Mappings.findWhere({
map_id: Metamaps.Active.Map.id,
topic_id: this.isNew() ? this.cid : this.id
@@ -131,24 +140,34 @@ Metamaps.Backbone.init = function () {
}
},
createNode: function () {
- var mapping = this.getMapping();
+ var mapping;
var node = {
adjacencies: [],
- data: {
- $mapping: null,
- $mappingID: mapping ? mapping.id : null
- },
id: this.isNew() ? this.cid : this.id,
name: this.get('name')
};
+
+ if (Metamaps.Active.Map) {
+ mapping = this.getMapping();
+ node.data = {
+ $mapping: null,
+ $mappingID: mapping.id
+ };
+ }
+
return node;
},
updateNode: function () {
- var mapping = this.getMapping();
+ var mapping;
var node = this.get('node');
node.setData('topic', this);
- node.setData('mapping', mapping);
node.id = this.isNew() ? this.cid : this.id;
+
+ if (Metamaps.Active.Map) {
+ mapping = this.getMapping();
+ node.setData('mapping', mapping);
+ }
+
return node;
},
});
@@ -173,7 +192,7 @@ Metamaps.Backbone.init = function () {
if (this.isNew()) {
this.set({
"user_id": Metamaps.Active.Mapper.id,
- "permission": Metamaps.Active.Map.get('permission'),
+ "permission": Metamaps.Active.Map ? Metamaps.Active.Map.get('permission') : 'commons',
"category": "from-to"
});
}
@@ -202,6 +221,9 @@ Metamaps.Backbone.init = function () {
];
},
getMapping: function () {
+
+ if (!Metamaps.Active.Map) return false;
+
return Metamaps.Mappings.findWhere({
map_id: Metamaps.Active.Map.id,
synapse_id: this.isNew() ? this.cid : this.id
@@ -215,27 +237,37 @@ Metamaps.Backbone.init = function () {
}
},
createEdge: function () {
- var mapping = this.getMapping();
- var mappingID = mapping.isNew() ? mapping.cid : mapping.id;
+ var mapping, mappingID;
var synapseID = this.isNew() ? this.cid : this.id;
var edge = {
nodeFrom: this.get('node1_id'),
nodeTo: this.get('node2_id'),
data: {
- $mappings: [],
- $mappingIDs: [mappingID],
$synapses: [],
$synapseIDs: [synapseID],
}
};
+
+ if (Metamaps.Active.Map) {
+ mapping = this.getMapping();
+ mappingID = mapping.isNew() ? mapping.cid : mapping.id;
+ edge.data.$mappings = [];
+ edge.data.$mappingIDs = [mappingID];
+ }
+
return edge;
},
updateEdge: function () {
- var mapping = this.getMapping();
+ var mapping;
var edge = this.get('edge');
- edge.getData('mappings').push(mapping);
edge.getData('synapses').push(this);
+
+ if (Metamaps.Active.Map) {
+ mapping = this.getMapping();
+ edge.getData('mappings').push(mapping);
+ }
+
return edge;
},
});
@@ -288,8 +320,12 @@ Metamaps.Backbone.init = function () {
Metamaps.Mappings = new self.MappingCollection(Metamaps.Mappings);
- Metamaps.Active.Map = new self.Map(Metamaps.Active.Map);
- Metamaps.Maps.add(Metamaps.Active.Map);
+ if (Metamaps.Active.Map) {
+ Metamaps.Active.Map = new self.Map(Metamaps.Active.Map);
+ Metamaps.Maps.add(Metamaps.Active.Map);
+ }
+
+ if (Metamaps.Active.Topic) Metamaps.Active.Topic = new self.Topic(Metamaps.Active.Topic);
}; // end Metamaps.Backbone.init
@@ -370,8 +406,10 @@ Metamaps.Create = {
$('#metacodeImg, #metacodeImgTitle').empty();
$('#metacodeImg').removeData('cloudcarousel');
var newMetacodes = "";
+ var metacode;
for (var i = 0; i < codesToSwitchTo.length; i++) {
- newMetacodes += ' ';
+ metacode = Metamaps.Metacodes.findWhere({ name: codesToSwitchTo[i] });
+ newMetacodes += ' ';
};
$('#metacodeImg').empty().append(newMetacodes).CloudCarousel({
titleBox: $('#metacodeImgTitle'),
@@ -383,7 +421,7 @@ Metamaps.Create = {
bringToFront: true
});
- $('#lightbox_overlay').hide();
+ Metamaps.GlobalUI.closeLightbox();
$('#topic_name').focus();
var mdata = {
@@ -656,7 +694,7 @@ Metamaps.TopicCard = {
});
$('.CardOnGraph').find('.metacodeTitle').text(metacodeName)
.attr('class', 'metacodeTitle mbg' + metacodeName.replace(/\s/g, ''));
- $('.CardOnGraph').find('.metacodeImage').css('background-image', 'url(' + imgArray[metacodeName].src + ')');
+ $('.CardOnGraph').find('.metacodeImage').css('background-image', 'url(' + metacode.get('icon') + ')');
topic.save({
metacode_id: metacode.id
});
@@ -1088,6 +1126,19 @@ Metamaps.Visualize = {
if (self.type == "RGraph") {
self.mGraph.graph.eachNode(function (n) {
+ topic = Metamaps.Topics.get(n.id);
+ topic.set('node', n);
+ topic.updateNode();
+
+ n.eachAdjacency(function (edge) {
+ l = edge.getData('synapseIDs').length;
+ for (i = 0; i < l; i++) {
+ synapse = Metamaps.Synapses.get(edge.getData('synapseIDs')[i]);
+ synapse.set('edge', edge);
+ synapse.updateEdge();
+ }
+ });
+
var pos = n.getPos();
pos.setc(-200, -200);
});
@@ -1102,7 +1153,7 @@ Metamaps.Visualize = {
mapping = topic.getMapping();
n.eachAdjacency(function (edge) {
- l = edge.getData('mappingIDs').length;
+ l = edge.getData('synapseIDs').length;
for (i = 0; i < l; i++) {
synapse = Metamaps.Synapses.get(edge.getData('synapseIDs')[i]);
synapse.set('edge', edge);
@@ -1125,37 +1176,25 @@ Metamaps.Visualize = {
* @param vizData a json structure containing the data to be rendered.
*/
__buildGraph: function (vizData) {
- var self = Metamaps.Visualize;
+ var self = Metamaps.Visualize
+ RGraphSettings = $.extend(true, {}, Metamaps.JIT.ForceDirected.graphSettings);
- // normally this will be true, and will enter into this first scenario
- if (!Metamaps.Settings.embed) {
- if (self.type == "RGraph") {
- $jit.RGraph.Plot.NodeTypes.implement(Metamaps.JIT.RGraph.nodeSettings);
- $jit.RGraph.Plot.EdgeTypes.implement(Metamaps.JIT.RGraph.edgeSettings);
- self.mGraph = new $jit.RGraph(Metamaps.JIT.RGraph.graphSettings);
- } else if (self.type == "ForceDirected") {
- $jit.ForceDirected.Plot.NodeTypes.implement(Metamaps.JIT.ForceDirected.nodeSettings);
- $jit.ForceDirected.Plot.EdgeTypes.implement(Metamaps.JIT.ForceDirected.edgeSettings);
- self.mGraph = new $jit.ForceDirected(Metamaps.JIT.ForceDirected.graphSettings);
- } else if (self.type == "ForceDirected3D") {
- // init ForceDirected3D
- self.mGraph = new $jit.ForceDirected3D(Metamaps.JIT.ForceDirected3D.graphSettings);
- self.cameraPosition = self.mGraph.canvas.canvases[0].camera.position;
- }
- } else { // in the case where these visualizations are to be embedded in other sites TODO
- if (self.type == "RGraph") {
- $jit.RGraph.Plot.NodeTypes.implement(Metamaps.JIT.RGraph.embed.nodeSettings);
- $jit.RGraph.Plot.EdgeTypes.implement(Metamaps.JIT.RGraph.embed.edgeSettings);
- self.mGraph = new $jit.RGraph(Metamaps.JIT.RGraph.embed.graphSettings);
- } else if (self.type == "ForceDirected") {
- $jit.ForceDirected.Plot.NodeTypes.implement(Metamaps.JIT.ForceDirected.embed.nodeSettings);
- $jit.ForceDirected.Plot.EdgeTypes.implement(Metamaps.JIT.ForceDirected.embed.edgeSettings);
- self.mGraph = new $jit.ForceDirected(Metamaps.JIT.ForceDirected.embed.graphSettings);
- } else if (self.type == "ForceDirected3D") {
- // init ForceDirected3D
- self.mGraph = new $jit.ForceDirected3D(Metamaps.JIT.ForceDirected3D.embed.graphSettings);
- self.cameraPosition = self.mGraph.canvas.canvases[0].camera.position;
- }
+ if (self.type == "RGraph") {
+ $jit.RGraph.Plot.NodeTypes.implement(Metamaps.JIT.ForceDirected.nodeSettings);
+ $jit.RGraph.Plot.EdgeTypes.implement(Metamaps.JIT.ForceDirected.edgeSettings);
+
+ RGraphSettings.background = Metamaps.JIT.RGraph.background;
+ RGraphSettings.levelDistance = Metamaps.JIT.RGraph.levelDistance;
+
+ self.mGraph = new $jit.RGraph(RGraphSettings);
+ } else if (self.type == "ForceDirected") {
+ $jit.ForceDirected.Plot.NodeTypes.implement(Metamaps.JIT.ForceDirected.nodeSettings);
+ $jit.ForceDirected.Plot.EdgeTypes.implement(Metamaps.JIT.ForceDirected.edgeSettings);
+ self.mGraph = new $jit.ForceDirected(Metamaps.JIT.ForceDirected.graphSettings);
+ } else if (self.type == "ForceDirected3D") {
+ // init ForceDirected3D
+ self.mGraph = new $jit.ForceDirected3D(Metamaps.JIT.ForceDirected3D.graphSettings);
+ self.cameraPosition = self.mGraph.canvas.canvases[0].camera.position;
}
// load JSON data, if it's not empty
@@ -1167,8 +1206,7 @@ Metamaps.Visualize = {
if (self.type == "RGraph") {
self.mGraph.fx.animate(Metamaps.JIT.RGraph.animate);
} else if (self.type == "ForceDirected" && self.savedLayout) {
- return Metamaps.Organize.loadSavedLayout();
- //self.mGraph.animate(Metamaps.JIT.ForceDirected.animateSavedLayout);
+ Metamaps.Organize.loadSavedLayout();
} else if (self.type == "ForceDirected3D" || !self.savedLayout) {
self.mGraph.animate(Metamaps.JIT.ForceDirected.animateFDLayout);
}
@@ -1228,7 +1266,6 @@ Metamaps.Util = {
}
}; // end Metamaps.Util
-
/*
*
* REALTIME
@@ -1254,7 +1291,7 @@ Metamaps.Realtime = {
$(".sidebarCollaborate").hover(self.open, self.close);
- var mapperm = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
+ var mapperm = Metamaps.Active.Map && Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
if (mapperm) {
self.socket = io.connect('http://localhost:5001');
@@ -1307,15 +1344,16 @@ Metamaps.Realtime = {
setupSocket: function () {
var self = Metamaps.Realtime;
var socket = Metamaps.Realtime.socket;
-
+ var myId = Metamaps.Active.Mapper.id;
+
socket.emit('newMapperNotify', {
- userid: Metamaps.Active.Mapper.id,
+ userid: myId,
username: Metamaps.Active.Mapper.get("name"),
mapid: Metamaps.Active.Map.id
});
// if you're the 'new guy' update your list with who's already online
- socket.on(userid + '-' + Metamaps.Active.Map.id + '-UpdateMapperList', self.updateMapperList);
+ socket.on(myId + '-' + Metamaps.Active.Map.id + '-UpdateMapperList', self.updateMapperList);
// receive word that there's a new mapper on the map
socket.on('maps-' + Metamaps.Active.Map.id + '-newmapper', self.newPeerOnMap);
@@ -1861,7 +1899,7 @@ Metamaps.Filter = {
});
$('.sidebarFilterBox').hide().css({
position: 'absolute',
- top: '35px',
+ top: '45px',
right: '-36px'
});
diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css
index 73671bf0..b3adaf2f 100644
--- a/app/assets/stylesheets/application.css
+++ b/app/assets/stylesheets/application.css
@@ -193,9 +193,9 @@ input[type="submit"]:hover {
* Layout stuffs
*/
-#barometer_tab {
+/*#barometer_tab {
display: none;
-}
+}*/
#saveMapLayout {
display: none;
}
@@ -508,7 +508,6 @@ label[for="user_remember_me"] {
border-right: none;
border-bottom-left-radius: 5px;
border-top-left-radius: 5px;
- background: #0F1519;
}
.wrapper div.index .openCheatsheet {
position: absolute;
@@ -559,8 +558,8 @@ label[for="user_remember_me"] {
.sidebarAccount {
position: absolute;
- top: 5px;
- right: 0;
+ top: 10px;
+ right: 10px;
z-index: 200;
width: 35px;
height: 35px;
@@ -573,17 +572,15 @@ label[for="user_remember_me"] {
background-size: 24px 24px;
cursor: pointer;
}
-
.sidebarAccountIcon img {
border-radius: 17px;
}
-
.sidebarAccountBox {
position: absolute;
display: none;
height: auto;
background: #000;
- top: 35px;
+ top: 45px;
right: 0;
padding: 10px;
border: 1px solid black;
@@ -687,8 +684,8 @@ li.accountInvite span {
.sidebarFork {
position: absolute;
- top: 5px;
- right: 71px;
+ top: 10px;
+ right: 120px;
z-index: 200;
width: 35px;
height: 35px;
@@ -701,10 +698,7 @@ li.accountInvite span {
background-size: 28px 28px;
cursor: pointer;
}
-.sidebarForkIcon:hover {
-
-}
-.sidebarForkBox {
+.sidebarForkIcon:hover {} .sidebarForkBox {
position: absolute;
display: none;
height: auto;
@@ -754,10 +748,7 @@ li.accountInvite span {
background-size: 22px 22px;
cursor: pointer;
}
-.sidebarSaveIcon:hover {
-
-}
-.sidebarSaveBox {
+.sidebarSaveIcon:hover {} .sidebarSaveBox {
position: absolute;
display: none;
height: auto;
@@ -791,8 +782,8 @@ li.accountInvite span {
.sidebarFilter {
position: absolute;
- top: 5px;
- right: 35px;
+ top: 10px;
+ right: 160px;
z-index: 200;
width: 35px;
height: 35px;
@@ -808,9 +799,7 @@ li.accountInvite span {
background-size: 28px 28px;
cursor: pointer;
}
-.sidebarFilterIcon:hover {
-
-}
+.sidebarFilterIcon:hover {}
/* we set a few of these params off screen to begin with, so that when we initialize the scroll bar it works, but then
we hide the element and position it correctly */
@@ -881,8 +870,8 @@ h3.filterByMetacode {
.sidebarCollaborate {
position: absolute;
- top: 5px;
- right: 143px;
+ top: 10px;
+ right: 200px;
z-index: 200;
width: 35px;
height: 35px;
@@ -906,7 +895,7 @@ h3.filterByMetacode {
height: auto;
width: auto;
background: #000;
- top: 35px;
+ top: 45px;
right: 0;
padding: 10px;
border: 1px solid black;
@@ -962,16 +951,17 @@ h3.realtimeBoxTitle {
.sidebarSearch {
position: absolute;
- top: 5px;
- left: 0;
+ top: 10px;
+ left: 10px;
height: 35px;
z-index: 200;
}
.sidebarSearchIcon {
float: left;
- width: 35px;
+ width: 80px;
+ border-radius: 2px;
height: 35px;
- background: #0F1519 url('search_icon_32x32.png') no-repeat center center;
+ background: #00BCD4 url('search_icon_32x32.png') no-repeat center center;
background-size: 25px 25px;
cursor: pointer;
}
@@ -1691,9 +1681,9 @@ div.mapInfoStat {
width: 100%;
position: absolute;
background-color: #000;
- opacity: 0.42;
- filter: alpha(opacity=42);
- -moz-opacity: 0.42;
+ opacity: 0.0;
+ filter: alpha(opacity=0);
+ -moz-opacity: 0.0;
}
#lightbox_overlay #lightbox_main #lightbox_header {
padding: 6px 5px 1px 0;
@@ -2032,6 +2022,7 @@ div.mapInfoStat {
box-shadow: none;
}
/* Cheatsheet */
+
#cheatSheet {
width: 100%;
height: 350px;
@@ -2040,15 +2031,14 @@ div.mapInfoStat {
line-height: 21px;
border: none;
}
-
#cheatSheet .sectionTitle {
font-family: Lato, Arial, sans-serif;
- font-weight:bold;
+ font-weight: bold;
}
#cheatSheet .csItem {
margin: 5px 0;
- font-size:15px;
- line-height:18px;
+ font-size: 15px;
+ line-height: 18px;
}
#cheatSheet .csItem img {
display: inline-block;
@@ -2058,7 +2048,7 @@ div.mapInfoStat {
font-family: Lato, Arial, sans-serif;
}
#cheatSheet .indented {
- margin-left:15px;
+ margin-left: 15px;
}
/* Admin Pages */
@@ -2246,41 +2236,32 @@ div.mapInfoStat {
height: 100%;
overflow: hidden;
}
+
+
+.addMap {
+ display: block;
+ position: fixed;
+ right: 55px;
+ top: 10px;
+ width: 55px;
+ height: 35px;
+ background: #00BCD4 url('MMCCicon_add_map.png') no-repeat 3px -4px;
+ background-size: 40px 40px;
+ cursor: pointer;
+ z-index: 2;
+ border-radius: 2px;
+}
/* --- styling the logo button ---*/
.footer {
display: block;
position: fixed;
- bottom: 5px;
- height: 35px;
+ bottom: 10px;
+ left:50%;
+ margin-left:-55px;
z-index: 15000;
- border-bottom-right-radius: 5px;
- border-top-right-radius: 5px;
- background: #0F1519;
}
-.addMap {
- position: absolute;
- right: -49px;
- top: 0px;
- width: 44px;
- height: 35px;
- background: url('MMCCicon_add_map.png') no-repeat 3px -4px;
- background-size: 40px 40px;
- border-radius: 5px;
- cursor: pointer;
-}
-.addMap:hover {} .logo {
- z-index: 12;
- display: block;
- width: 136px;
- background: url(menu_icon_32.png) no-repeat -10px 8px;
- padding: 5px 0px 1px 15px;
- background-size: 22px 20px;
-}
-#mainTitle {
- padding: 0 5px;
-}
-#mainTitle a {
+#logo a {
color: #FFF;
font-family: "vinyl", sans-serif;
font-style: italic;
@@ -2289,52 +2270,6 @@ div.mapInfoStat {
font-size: 30px;
line-height: 30px;
}
-.footer .menu {
- display: none;
- position: absolute;
- border: none;
- bottom: 35px;
- left: -1px;
- height: 123px;
- z-index: 12;
- width: 122px;
- color: white;
- white-space: nowrap;
- text-align: center;
- font-size: 16px;
- overflow: hidden;
- padding: 0 0 0 30px;
- margin: 0;
- background: #0F1519 url(beta_gen002.png) no-repeat 6px 12px;
-}
-.footer ul li {
- margin: 0;
- clear: both;
- float: none;
- list-style-type: none;
- display: block;
- padding: 0;
- text-align: center;
- font-family: 'vinyl';
- font-style: italic;
- height: 30px;
- line-height: 34px;
- font-size: 17px;
- cursor: pointer;
-}
-.footer ul li:hover {} li.meta a,
-li.tutorial a,
-li.exploreMaps a {
- display: block;
-}
-li.meta,
-li.tutorial,
-li.exploreMaps {
- border-top: 1px solid white;
-}
-.footer ul li a {
- color: #FFF;
-}
.home_bg {
display: block;
height: 100%;
diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb
index 37d9fdc3..a3a1da03 100644
--- a/app/controllers/maps_controller.rb
+++ b/app/controllers/maps_controller.rb
@@ -1,180 +1,182 @@
class MapsController < ApplicationController
-
- before_filter :require_user, only: [:create, :update, :destroy]
-
- respond_to :html, :js, :json
-
- autocomplete :map, :name, :full => true, :extra_data => [:user_id]
-
- # GET /maps/recent
- # GET /maps/featured
- # GET /maps/new
- # GET /maps/mappers/:id
- def index
-
- if request.path == "/maps"
- redirect_to activemaps_url and return
- end
-
- @current = current_user
- @user = nil
-
- if request.path =="/maps/active"
- @maps = Map.order("updated_at DESC").limit(20)
- @request = "active"
-
- elsif request.path =="/maps/featured"
- @maps = Map.order("name ASC").find_all_by_featured(true)
- @request = "featured"
-
- elsif request.path == "/maps/new"
- @maps = Map.order("created_at DESC").limit(20)
- @request = "new"
-
- elsif request.path.index('/maps/mappers/') != nil # looking for maps by a mapper
- @user = User.find(params[:id])
- @maps = Map.order("name ASC").find_all_by_user_id(@user.id)
- @request = "you" if authenticated? && @user == @current
- @request = "other" if authenticated? && @user != @current
-
- elsif request.path.index('/maps/topics/') != nil # looking for maps by a certain topic they include
- @topic = Topic.find(params[:id]).authorize_to_show(@current)
- if !@topic
- redirect_to featuredmaps_url, notice: "Access denied." and return
- end
- @maps = @topic.maps
- @request = "topic"
- end
-
- #read this next line as 'delete a map if its private and you're either 1. logged out or 2. logged in but not the map creator
- @maps.delete_if {|m| m.permission == "private" && (!authenticated? || (authenticated? && @current.id != m.user_id)) }
-
- respond_with(@maps, @request, @user)
- end
-
- # GET maps/:id
- def show
-
- @current = current_user
- @map = Map.find(params[:id]).authorize_to_show(@current)
-
- if not @map
- redirect_to root_url and return
- end
-
- @alltopics = @map.topics # should limit to topics visible to user
- @allsynapses = @map.synapses # should also be limited
- @allmappings = @map.mappings
- @allmetacodes = Metacode.all
-
- respond_to do |format|
- format.html { respond_with(@allmetacodes, @allmappings, @allsynapses, @alltopics, @map, @user) }
- format.json { render json: @map }
- end
- end
-
- # GET maps/:id/embed
- def embed
- @current = current_user
- @map = Map.find(params[:id]).authorize_to_show(@current)
-
- if not @map
- redirect_to root_url and return
- end
-
- @alltopics = @map.topics # should limit to topics visible to user
- @allsynapses = @map.synapses # should also be limited
- @allmappings = @map.mappings
- @allmetacodes = Metacode.all
-
- respond_to do |format|
- format.html { respond_with(@allmetacodes, @allmappings, @allsynapses, @alltopics, @map, @user) }
- format.json { render json: @map }
- end
- end
-
- # POST maps
- def create
-
- @user = current_user
- @map = Map.new()
- @map.name = params[:name]
- @map.desc = params[:desc]
- @map.permission = params[:permission]
- @map.user = @user
- @map.arranged = false
- @map.save
-
- if params[:topicsToMap]
- @all = params[:topicsToMap]
- @all = @all.split(',')
- @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])
- @mapping.xloc = topic[1]
- @mapping.yloc = topic[2]
- @mapping.save
- end
- if params[:synapsesToMap]
- @synAll = params[:synapsesToMap]
- @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)
- @mapping.save
+ before_filter :require_user, only: [:create, :update, :destroy]
+
+ respond_to :html, :json
+
+ autocomplete :map, :name, :full => true, :extra_data => [:user_id]
+
+ # GET /maps/recent
+ # GET /maps/featured
+ # GET /maps/new
+ # GET /maps/mappers/:id
+ def index
+
+ if request.path == "/maps"
+ redirect_to activemaps_url and return
end
- end
- @map.arranged = true
- @map.save
- end
-
- respond_to do |format|
- format.json { render :json => @map }
- end
- end
-
- # PUT maps/:id
- def update
- @current = current_user
- @map = Map.find(params[:id]).authorize_to_edit(@current)
-
- if @map
- @map.name = params[:name] if params[:name]
- @map.desc = params[:desc] if params[:desc]
- @map.permission = params[:permission] if params[:permission]
- @map.save
- end
+ @current = current_user
+ @user = nil
- respond_to do |format|
- format.json { render :json => @map }
+ if request.path =="/maps/active"
+ @maps = Map.order("updated_at DESC").limit(20)
+ @request = "active"
+
+ elsif request.path =="/maps/featured"
+ @maps = Map.order("name ASC").find_all_by_featured(true)
+ @request = "featured"
+
+ elsif request.path == "/maps/new"
+ @maps = Map.order("created_at DESC").limit(20)
+ @request = "new"
+
+ elsif request.path.index('/maps/mappers/') != nil # looking for maps by a mapper
+ @user = User.find(params[:id])
+ @maps = Map.order("name ASC").find_all_by_user_id(@user.id)
+ @request = "you" if authenticated? && @user == @current
+ @request = "other" if authenticated? && @user != @current
+
+ elsif request.path.index('/maps/topics/') != nil # looking for maps by a certain topic they include
+ @topic = Topic.find(params[:id]).authorize_to_show(@current)
+ if !@topic
+ redirect_to featuredmaps_url, notice: "Access denied." and return
+ end
+ @maps = @topic.maps
+ @request = "topic"
+ end
+
+ #read this next line as 'delete a map if its private and you're either 1. logged out or 2. logged in but not the map creator
+ @maps.delete_if {|m| m.permission == "private" && (!authenticated? || (authenticated? && @current.id != m.user_id)) }
+
+ respond_to do |format|
+ format.html { respond_with(@maps, @request, @user) }
+ end
end
- end
-
- # DELETE maps/:id
- def destroy
- @current = current_user
-
- @map = Map.find(params[:id])
-
- @mappings = @map.mappings
-
- @mappings.each do |mapping|
- mapping.delete
- end
-
- @map.delete
-
- respond_to do |format|
- format.html { redirect_to "/maps/mappers/" + @current.id.to_s, notice: "Map deleted." }
+
+ # GET maps/:id
+ def show
+
+ @current = current_user
+ @map = Map.find(params[:id]).authorize_to_show(@current)
+
+ if not @map
+ redirect_to root_url and return
+ end
+
+ @alltopics = @map.topics # should limit to topics visible to user
+ @allsynapses = @map.synapses # should also be limited
+ @allmappings = @map.mappings
+ @allmetacodes = Metacode.all
+
+ respond_to do |format|
+ format.html { respond_with(@allmetacodes, @allmappings, @allsynapses, @alltopics, @map, @user) }
+ format.json { render json: @map }
+ end
+ end
+
+ # GET maps/:id/embed
+ def embed
+ @current = current_user
+ @map = Map.find(params[:id]).authorize_to_show(@current)
+
+ if not @map
+ redirect_to root_url and return
+ end
+
+ @alltopics = @map.topics # should limit to topics visible to user
+ @allsynapses = @map.synapses # should also be limited
+ @allmappings = @map.mappings
+ @allmetacodes = Metacode.all
+
+ respond_to do |format|
+ format.html { respond_with(@allmetacodes, @allmappings, @allsynapses, @alltopics, @map, @user) }
+ format.json { render json: @map }
+ end
+ end
+
+ # POST maps
+ def create
+
+ @user = current_user
+ @map = Map.new()
+ @map.name = params[:name]
+ @map.desc = params[:desc]
+ @map.permission = params[:permission]
+ @map.user = @user
+ @map.arranged = false
+ @map.save
+
+ if params[:topicsToMap]
+ @all = params[:topicsToMap]
+ @all = @all.split(',')
+ @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])
+ @mapping.xloc = topic[1]
+ @mapping.yloc = topic[2]
+ @mapping.save
+ end
+
+ if params[:synapsesToMap]
+ @synAll = params[:synapsesToMap]
+ @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)
+ @mapping.save
+ end
+ end
+
+ @map.arranged = true
+ @map.save
+ end
+
+ respond_to do |format|
+ format.json { render :json => @map }
+ end
+ end
+
+ # PUT maps/:id
+ def update
+ @current = current_user
+ @map = Map.find(params[:id]).authorize_to_edit(@current)
+
+ if @map
+ @map.name = params[:name] if params[:name]
+ @map.desc = params[:desc] if params[:desc]
+ @map.permission = params[:permission] if params[:permission]
+ @map.save
+ end
+
+ respond_to do |format|
+ format.json { render :json => @map }
+ end
+ end
+
+ # DELETE maps/:id
+ def destroy
+ @current = current_user
+
+ @map = Map.find(params[:id])
+
+ @mappings = @map.mappings
+
+ @mappings.each do |mapping|
+ mapping.delete
+ end
+
+ @map.delete
+
+ respond_to do |format|
+ format.html { redirect_to "/maps/mappers/" + @current.id.to_s, notice: "Map deleted." }
+ end
end
- end
end
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index 04ed5249..dc7ee02d 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -1,112 +1,115 @@
class TopicsController < ApplicationController
- include TopicsHelper
+ include TopicsHelper
- before_filter :require_user, only: [:create, :update, :destroy]
-
- respond_to :html, :js, :json
-
- # GET /topics/autocomplete_topic
- def autocomplete_topic
- @current = current_user
- term = params[:term]
- if term && !term.empty?
- # !connor term here needs to have .downcase
- @topics = Topic.where('LOWER("name") like ?', term.downcase + '%').order('"name"')
-
- #read this next line as 'delete a topic if its private and you're either 1. logged out or 2. logged in but not the topic creator
- @topics.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
- else
- @topics = []
- end
- render json: autocomplete_array_json(@topics)
- end
-
- # GET topics/:id
- def show
- @current = current_user
- @topic = Topic.find(params[:id]).authorize_to_show(@current)
-
- if @topic
- @relatives = @topic.network_as_json(@current).html_safe
- else
- redirect_to root_url and return
- end
-
- respond_to do |format|
- format.html { respond_with(@topic, @user) }
- #format.json { respond_with(@relatives) }
- format.json { render :json => @topic }
- end
- end
+ before_filter :require_user, only: [:create, :update, :destroy]
- # POST /topics
- # POST /topics.json
- def create
- @topic = Topic.new(params[:topic])
+ respond_to :html, :js, :json
- respond_to do |format|
- if @topic.save
- format.json { render json: @topic, status: :created }
- else
- format.json { render json: @topic.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # PUT /topics/1
- # PUT /topics/1.json
- def update
- @topic = Topic.find(params[:id])
+ # GET /topics/autocomplete_topic
+ def autocomplete_topic
+ @current = current_user
+ term = params[:term]
+ if term && !term.empty?
+ # !connor term here needs to have .downcase
+ @topics = Topic.where('LOWER("name") like ?', term.downcase + '%').order('"name"')
- respond_to do |format|
- if @topic.update_attributes(params[:topic])
- format.json { head :no_content }
- else
- format.json { render json: @topic.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # DELETE topics/:id
- def destroy
- @current = current_user
- @topic = Topic.find(params[:id]).authorize_to_edit(@current)
-
- if @topic
- @synapses = @topic.synapses
- @mappings = @topic.mappings
-
- @synapses.each do |synapse|
- synapse.mappings.each do |m|
-
- @map = m.map
- @map.touch(:updated_at)
-
- #push notify to anyone viewing same map in realtime (see mapping.rb to understand the 'message' action)
- m.message 'destroy',@current.id
-
- m.delete
+ #read this next line as 'delete a topic if its private and you're either
+ #1. logged out or 2. logged in but not the topic creator
+ @topics.delete_if {|t| t.permission == "private" &&
+ (!authenticated? || (authenticated? && @current.id != t.user_id)) }
+ else
+ @topics = []
end
-
- synapse.delete
- end
-
- @mappings.each do |mapping|
-
- @map = mapping.map
- @map.touch(:updated_at)
-
- #push notify to anyone viewing a map with this topic in realtime (see mapping.rb to understand the 'message' action)
- mapping.message 'destroy',@current.id
-
- mapping.delete
- end
-
- @topic.delete
+ render json: autocomplete_array_json(@topics)
end
-
- respond_to do |format|
- format.js { render :json => "success" }
+
+ # GET topics/:id
+ def show
+ @current = current_user
+ @topic = Topic.find(params[:id]).authorize_to_show(@current)
+
+ if not @topic
+ redirect_to root_url and return
+ end
+
+ @alltopics = [@topic] + @topic.relatives # should limit to topics visible to user
+ @allsynapses = @topic.synapses # should also be limited
+ @allmetacodes = Metacode.all
+
+ respond_to do |format|
+ format.html { respond_with(@allmetacodes, @allsynapses, @alltopics, @topic, @user) }
+ format.json { render json: @topic }
+ end
+ end
+
+ # POST /topics
+ # POST /topics.json
+ def create
+ @topic = Topic.new(params[:topic])
+
+ respond_to do |format|
+ if @topic.save
+ format.json { render json: @topic, status: :created }
+ else
+ format.json { render json: @topic.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /topics/1
+ # PUT /topics/1.json
+ def update
+ @topic = Topic.find(params[:id])
+
+ respond_to do |format|
+ if @topic.update_attributes(params[:topic])
+ format.json { head :no_content }
+ else
+ format.json { render json: @topic.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE topics/:id
+ def destroy
+ @current = current_user
+ @topic = Topic.find(params[:id]).authorize_to_edit(@current)
+
+ if @topic
+ @synapses = @topic.synapses
+ @mappings = @topic.mappings
+
+ @synapses.each do |synapse|
+ synapse.mappings.each do |m|
+
+ @map = m.map
+ @map.touch(:updated_at)
+
+ #push notify to anyone viewing same map in realtime (see mapping.rb to understand the 'message' action)
+ m.message 'destroy',@current.id
+
+ m.delete
+ end
+
+ synapse.delete
+ end
+
+ @mappings.each do |mapping|
+
+ @map = mapping.map
+ @map.touch(:updated_at)
+
+ #push notify to anyone viewing a map with this topic in realtime (see mapping.rb to understand the 'message' action)
+ mapping.message 'destroy',@current.id
+
+ mapping.delete
+ end
+
+ @topic.delete
+ end
+
+ respond_to do |format|
+ format.js { render :json => "success" }
+ end
end
- end
end
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 4d6360f3..585a41a0 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -1,98 +1,90 @@
<%#
- # @file
- # Main application file. Holds scaffolding present on every page.
- # Then a certain non-partial view (no _ preceding filename) will be
- # displayed within, based on URL
- #%>
+# @file
+# Main application file. Holds scaffolding present on every page.
+# Then a certain non-partial view (no _ preceding filename) will be
+# displayed within, based on URL
+#%>
-
-
- <%=h yield(:title) %>
- <% if authenticated? %>
-
- <% else %>
-
- <% end %>
-
- <%= stylesheet_link_tag "application", :media => "all" %>
- <%= javascript_include_tag "application" %>
- <% if (controller_name == "maps" || controller_name == "topics") && action_name == "show" %>
- <%= javascript_include_tag "compileMapPages" %>
- <% end %>
-
-
-
-
- <%= csrf_meta_tags %>
-
+
+
+ <%=h yield(:title) %>
+<%= stylesheet_link_tag "application", :media => "all" %>
+<%= javascript_include_tag "application" %>
+<% if (controller_name == "maps" && action_name == "show" || action_name == "embed") ||
+ (controller_name == "topics" && action_name == "show") %>
+<%= javascript_include_tag "compileMapPages" %>
+<% end %>
+
+
+
+
+<%= csrf_meta_tags %>
+
" >
- <% if notice %>
- <%= notice %>
- <% end %>
- <% if alert %>
- <%= alert %>
- <% end %>
-
- <%= content_tag :div, class: authenticated? ? "main authenticated" : "main unauthenticated" do %>
+ <% if notice %>
+ <%= notice %>
+ <% end %>
+ <% if alert %>
+ <%= alert %>
+ <% end %>
- " id="wrapper">
-
-