added filtering back to topic view

This commit is contained in:
Connor Turland 2014-11-11 02:23:39 -05:00
parent 3bb8256f8f
commit 9b0304c403
7 changed files with 174 additions and 46 deletions

View file

@ -908,6 +908,9 @@ Metamaps.JIT = {
}; };
} }
} }
else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && Metamaps.Active.Topic) {
Metamaps.GlobalUI.notifyUser("Cannot create in Topic view.");
}
else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && !authorized) { else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && !authorized) {
Metamaps.GlobalUI.notifyUser("Cannot edit Public map."); Metamaps.GlobalUI.notifyUser("Cannot edit Public map.");
} }
@ -1002,6 +1005,10 @@ Metamaps.JIT = {
Metamaps.GlobalUI.notifyUser("Cannot edit Public map."); Metamaps.GlobalUI.notifyUser("Cannot edit Public map.");
return; return;
} }
else if (Metamaps.Active.Topic) {
Metamaps.GlobalUI.notifyUser("Cannot create in Topic view.");
return;
}
// DOUBLE CLICK // DOUBLE CLICK
//pop up node creation :) //pop up node creation :)
Metamaps.Create.newTopic.addSynapse = false; Metamaps.Create.newTopic.addSynapse = false;

View file

@ -477,6 +477,9 @@ Metamaps.Backbone.init = function () {
Metamaps.Mappers = Metamaps.Mappers ? new self.MapperCollection(Metamaps.Mappers) : new self.MapperCollection(); Metamaps.Mappers = Metamaps.Mappers ? new self.MapperCollection(Metamaps.Mappers) : new self.MapperCollection();
// this is for topic view
Metamaps.Creators = Metamaps.Creators ? new self.MapperCollection(Metamaps.Creators) : new self.MapperCollection();
if (Metamaps.Active.Map) { if (Metamaps.Active.Map) {
Metamaps.Mappings = Metamaps.Mappings ? new self.MappingCollection(Metamaps.Mappings) : new self.MappingCollection(); Metamaps.Mappings = Metamaps.Mappings ? new self.MappingCollection(Metamaps.Mappings) : new self.MappingCollection();
@ -3146,12 +3149,30 @@ Metamaps.Filter = {
var removed = []; var removed = [];
var added = []; var added = [];
Metamaps[collection].each(function(model) { // the first option enables us to accept
var prop = model.get(propertyToCheck) ? model.get(propertyToCheck).toString() : false; // ['Topics', 'Synapses'] as 'collection'
if (prop && newList.indexOf(prop) === -1) { if (typeof collection === "object") {
newList.push(prop); Metamaps[collection[0]].each(function(model) {
} var prop = model.get(propertyToCheck) ? model.get(propertyToCheck).toString() : false;
}); if (prop && newList.indexOf(prop) === -1) {
newList.push(prop);
}
});
Metamaps[collection[1]].each(function(model) {
var prop = model.get(propertyToCheck) ? model.get(propertyToCheck).toString() : false;
if (prop && newList.indexOf(prop) === -1) {
newList.push(prop);
}
});
}
else if (typeof collection === "string") {
Metamaps[collection].each(function(model) {
var prop = model.get(propertyToCheck) ? model.get(propertyToCheck).toString() : false;
if (prop && newList.indexOf(prop) === -1) {
newList.push(prop);
}
});
}
removed = _.difference(self.filters[filtersToUse], newList); removed = _.difference(self.filters[filtersToUse], newList);
added = _.difference(newList, self.filters[filtersToUse]); added = _.difference(newList, self.filters[filtersToUse]);
@ -3194,7 +3215,14 @@ Metamaps.Filter = {
}, },
checkMappers: function () { checkMappers: function () {
var self = Metamaps.Filter; var self = Metamaps.Filter;
self.updateFilters('Mappings', 'user_id', 'Mappers', 'mappers', 'mapper'); var onMap = Metamaps.Active.Map ? true : false;
if (onMap) {
self.updateFilters('Mappings', 'user_id', 'Mappers', 'mappers', 'mapper');
}
else {
// on topic view
self.updateFilters(['Topics', 'Synapses'], 'user_id', 'Creators', 'mappers', 'mapper');
}
}, },
checkSynapses: function () { checkSynapses: function () {
var self = Metamaps.Filter; var self = Metamaps.Filter;
@ -3275,7 +3303,11 @@ Metamaps.Filter = {
if (Metamaps.Active.Map) { if (Metamaps.Active.Map) {
onMap = true; onMap = true;
} }
else passesMapper = true; // for when you're on a topic page else if (Metamaps.Active.Topic) {
onMap = false;
}
var opacityForFilter = onMap ? 0 : 0.4;
Metamaps.Topics.each(function(topic) { Metamaps.Topics.each(function(topic) {
var n = topic.get('node'); var n = topic.get('node');
@ -3285,10 +3317,21 @@ Metamaps.Filter = {
else passesMetacode = true; else passesMetacode = true;
if (onMap) { if (onMap) {
// when on a map,
// we filter by mapper according to the person who added the
// topic or synapse to the map
var user_id = topic.getMapping().get("user_id").toString(); var user_id = topic.getMapping().get("user_id").toString();
if (visible.mappers.indexOf(user_id) == -1) passesMapper = false; if (visible.mappers.indexOf(user_id) == -1) passesMapper = false;
else passesMapper = true; else passesMapper = true;
} }
else {
// when on a topic view,
// we filter by mapper according to the person who created the
// topic or synapse
var user_id = topic.get("user_id").toString();
if (visible.mappers.indexOf(user_id) == -1) passesMapper = false;
else passesMapper = true;
}
if (passesMetacode && passesMapper) { if (passesMetacode && passesMapper) {
if (n) { if (n) {
@ -3299,7 +3342,7 @@ Metamaps.Filter = {
else { else {
if (n) { if (n) {
Metamaps.Control.deselectNode(n, true); Metamaps.Control.deselectNode(n, true);
n.setData('alpha', 0, 'end'); n.setData('alpha', opacityForFilter, 'end');
n.eachAdjacency(function(e){ n.eachAdjacency(function(e){
Metamaps.Control.deselectEdge(e, true); Metamaps.Control.deselectEdge(e, true);
}); });
@ -3316,10 +3359,13 @@ Metamaps.Filter = {
else passesSynapse = true; else passesSynapse = true;
if (onMap) { if (onMap) {
var user_id = synapse.getMapping().get("user_id").toString(); // when on a map,
if (visible.mappers.indexOf(user_id) == -1) passesMapper = false; // we filter by mapper according to the person who added the
else passesMapper = true; // topic or synapse to the map
user_id = synapse.getMapping().get("user_id").toString();
} }
if (visible.mappers.indexOf(user_id) == -1) passesMapper = false;
else passesMapper = true;
var color = Metamaps.Settings.colors.synapses.normal; var color = Metamaps.Settings.colors.synapses.normal;
if (passesSynapse && passesMapper) { if (passesSynapse && passesMapper) {
@ -3332,10 +3378,10 @@ Metamaps.Filter = {
else { else {
if (e) { if (e) {
Metamaps.Control.deselectEdge(e, true); Metamaps.Control.deselectEdge(e, true);
e.setData('alpha', 0, 'end'); e.setData('alpha', opacityForFilter, 'end');
} }
else console.log(synapse); else console.log(synapse);
} }
}); });
// run the animation // run the animation
@ -3586,10 +3632,14 @@ Metamaps.Topic = {
var bb = Metamaps.Backbone; var bb = Metamaps.Backbone;
var start = function (data) { var start = function (data) {
Metamaps.Active.Topic = new bb.Topic(data.topic); Metamaps.Active.Topic = new bb.Topic(data.topic);
Metamaps.Creators = new bb.MapperCollection(data.creators);
Metamaps.Topics = new bb.TopicCollection([data.topic].concat(data.relatives)); Metamaps.Topics = new bb.TopicCollection([data.topic].concat(data.relatives));
Metamaps.Synapses = new bb.SynapseCollection(data.synapses); Metamaps.Synapses = new bb.SynapseCollection(data.synapses);
Metamaps.Backbone.attachCollectionEvents(); Metamaps.Backbone.attachCollectionEvents();
// set filter mapper H3 text
$('#filter_by_mapper h3').html('CREATORS');
// build and render the visualization // build and render the visualization
Metamaps.Visualize.type = "RGraph"; Metamaps.Visualize.type = "RGraph";
Metamaps.JIT.prepareVizData(); Metamaps.JIT.prepareVizData();
@ -3616,6 +3666,7 @@ Metamaps.Topic = {
$('.rightclickmenu').remove(); $('.rightclickmenu').remove();
Metamaps.TopicCard.hideCard(); Metamaps.TopicCard.hideCard();
Metamaps.SynapseCard.hideCard(); Metamaps.SynapseCard.hideCard();
Metamaps.Filter.close();
} }
}, },
centerOn: function (nodeid) { centerOn: function (nodeid) {
@ -4044,6 +4095,9 @@ Metamaps.Map = {
$('.wrapper').addClass('commonsMap'); $('.wrapper').addClass('commonsMap');
} }
// set filter mapper H3 text
$('#filter_by_mapper h3').html('MAPPERS');
// build and render the visualization // build and render the visualization
Metamaps.Visualize.type = "ForceDirected"; Metamaps.Visualize.type = "ForceDirected";
Metamaps.JIT.prepareVizData(); Metamaps.JIT.prepareVizData();
@ -4082,6 +4136,7 @@ Metamaps.Map = {
Metamaps.SynapseCard.hideCard(); Metamaps.SynapseCard.hideCard();
Metamaps.Create.newTopic.hide(); Metamaps.Create.newTopic.hide();
Metamaps.Create.newSynapse.hide(); Metamaps.Create.newSynapse.hide();
Metamaps.Filter.close();
Metamaps.Realtime.endActiveMap(); Metamaps.Realtime.endActiveMap();
} }
}, },
@ -4090,31 +4145,37 @@ Metamaps.Map = {
var nodes_data = "", var nodes_data = "",
synapses_data = ""; synapses_data = "";
var synapses_array = new Array(); var nodes_array = [];
var synapses_array = [];
// collect the unfiltered topics
Metamaps.Visualize.mGraph.graph.eachNode(function (n) { Metamaps.Visualize.mGraph.graph.eachNode(function (n) {
//don't add to the map if it was filtered out // if the opacity is less than 1 then it's filtered
// TODO if (n.getData('alpha') === 1) {
//if (categoryVisible[n.getData('metacode')] == false) { var id = n.getData('topic').id;
// return; nodes_array.push(id);
//} var x, y;
if (n.pos.x && n.pos.y) {
var x, y; x = n.pos.x;
if (n.pos.x && n.pos.y) { y = n.pos.y;
x = n.pos.x; } else {
y = n.pos.y; var x = Math.cos(n.pos.theta) * n.pos.rho;
} else { var y = Math.sin(n.pos.theta) * n.pos.rho;
var x = Math.cos(n.pos.theta) * n.pos.rho; }
var y = Math.sin(n.pos.theta) * n.pos.rho; nodes_data += id + '/' + x + '/' + y + ',';
} }
nodes_data += n.id + '/' + x + '/' + y + ',';
n.eachAdjacency(function (adj) {
synapses_array.push(adj.getData("synapses")[0].id); // TODO
});
}); });
// collect the unfiltered synapses
Metamaps.Synapses.each(function(synapse){
var desc = synapse.get("desc");
//get unique values only var descNotFiltered = Metamaps.Filter.visible.synapses.indexOf(desc) > -1;
synapses_array = $.grep(synapses_array, function (value, key) { // make sure that both topics are being added, otherwise, it
return $.inArray(value, synapses_array) === key; // doesn't make sense to add the synapse
var topicsNotFiltered = nodes_array.indexOf(synapse.get('node1_id')) > -1;
topicsNotFiltered = topicsNotFiltered && nodes_array.indexOf(synapse.get('node2_id')) > -1;
if (descNotFiltered && topicsNotFiltered) {
synapses_array.push(synapse.id);
}
}); });
synapses_data = synapses_array.join(); synapses_data = synapses_array.join();
@ -4310,10 +4371,11 @@ Metamaps.Map = {
} }
today = mm+'/'+dd+'/'+yyyy; today = mm+'/'+dd+'/'+yyyy;
var mapName = map.get("name").split(" ").join([separator = '-']);
var downloadMessage = ""; var downloadMessage = "";
downloadMessage += "Captured map screenshot! "; downloadMessage += "Captured map screenshot! ";
downloadMessage += "<a href='" + imageData.encoded_image + "' "; downloadMessage += "<a href='" + imageData.encoded_image + "' ";
downloadMessage += "download='map-" + map.id + "-screenshot-" + today + ".png'>DOWNLOAD</a>"; downloadMessage += "download='metamap-" + map.id + "-" + mapName + "-" + today + ".png'>DOWNLOAD</a>";
Metamaps.GlobalUI.notifyUser(downloadMessage); Metamaps.GlobalUI.notifyUser(downloadMessage);
$.ajax({ $.ajax({

View file

@ -577,7 +577,7 @@
top: 0; top: 0;
} }
.topicPage .sidebarCollaborate, .topicPage .sidebarFilter { .topicPage .sidebarCollaborate {
display: none; display: none;
} }

View file

@ -83,7 +83,14 @@ class MapsController < ApplicationController
@allmappers = @map.contributors @allmappers = @map.contributors
@alltopics = @map.topics.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) } @alltopics = @map.topics.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
@allsynapses = @map.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) } @allsynapses = @map.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) }
@allmappings = @map.mappings @allmappings = @map.mappings.delete_if {|m|
if m.category == "Synapse"
object = m.synapse
elsif m.category == "Topic"
object = m.topic
end
object.permission == "private" && (!authenticated? || (authenticated? && @current.id != object.user_id))
}
respond_with(@allmappers, @allmappings, @allsynapses, @alltopics, @map) respond_with(@allmappers, @allmappings, @allsynapses, @alltopics, @map)
} }
@ -104,7 +111,14 @@ class MapsController < ApplicationController
@allmappers = @map.contributors @allmappers = @map.contributors
@alltopics = @map.topics.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) } @alltopics = @map.topics.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
@allsynapses = @map.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) } @allsynapses = @map.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) }
@allmappings = @map.mappings @allmappings = @map.mappings.delete_if {|m|
if m.category == "Synapse"
object = m.synapse
elsif m.category == "Topic"
object = m.topic
end
object.permission == "private" && (!authenticated? || (authenticated? && @current.id != object.user_id))
}
@json = Hash.new() @json = Hash.new()
@json['map'] = @map @json['map'] = @map

View file

@ -29,7 +29,7 @@ class TopicsController < ApplicationController
@topic = Topic.find(params[:id]).authorize_to_show(@current) @topic = Topic.find(params[:id]).authorize_to_show(@current)
if not @topic if not @topic
redirect_to root_url and return redirect_to root_url, notice: "Access denied. That topic is private." and return
end end
respond_to do |format| respond_to do |format|
@ -37,7 +37,19 @@ class TopicsController < ApplicationController
@alltopics = ([@topic] + @topic.relatives).delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) } # should limit to topics visible to user @alltopics = ([@topic] + @topic.relatives).delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) } # should limit to topics visible to user
@allsynapses = @topic.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) } @allsynapses = @topic.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) }
respond_with(@allsynapses, @alltopics, @topic) @allcreators = []
@alltopics.each do |t|
if @allcreators.index(t.user) == nil
@allcreators.push(t.user)
end
end
@allsynapses.each do |s|
if @allcreators.index(s.user) == nil
@allcreators.push(s.user)
end
end
respond_with(@allsynapses, @alltopics, @allcreators, @topic)
} }
format.json { render json: @topic } format.json { render json: @topic }
end end
@ -54,9 +66,22 @@ class TopicsController < ApplicationController
@alltopics = @topic.relatives.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) } @alltopics = @topic.relatives.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
@allsynapses = @topic.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) } @allsynapses = @topic.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) }
@allcreators = []
@allcreators.push(@topic.user)
@alltopics.each do |t|
if @allcreators.index(t.user) == nil
@allcreators.push(t.user)
end
end
@allsynapses.each do |s|
if @allcreators.index(s.user) == nil
@allcreators.push(s.user)
end
end
@json = Hash.new() @json = Hash.new()
@json['topic'] = @topic @json['topic'] = @topic
@json['creators'] = @allcreators
@json['relatives'] = @alltopics @json['relatives'] = @alltopics
@json['synapses'] = @allsynapses @json['synapses'] = @allsynapses

View file

@ -17,22 +17,41 @@
#and metacodes is filled with all the metacodes that are being used on the map. #and metacodes is filled with all the metacodes that are being used on the map.
if @map if @map
@map.topics.each_with_index do |topic, index| @alltopics.each_with_index do |topic, index|
if @metacodes.index(topic.metacode) == nil if @metacodes.index(topic.metacode) == nil
@metacodes.push(topic.metacode) @metacodes.push(topic.metacode)
end end
end end
@map.synapses.each_with_index do |synapse, index| @allsynapses.each_with_index do |synapse, index|
if @synapses.index{|s| s.desc == synapse.desc} == nil if @synapses.index{|s| s.desc == synapse.desc} == nil
@synapses.push(synapse) @synapses.push(synapse)
end end
end end
@map.mappings.each_with_index do |mapping, index| @allmappings.each_with_index do |mapping, index|
if @mappers.index(mapping.user) == nil if @mappers.index(mapping.user) == nil
@mappers.push(mapping.user) @mappers.push(mapping.user)
end end
end end
elsif @topic
@alltopics.each_with_index do |topic, index|
if @metacodes.index(topic.metacode) == nil
@metacodes.push(topic.metacode)
end
if @mappers.index(topic.user) == nil
@mappers.push(topic.user)
end
end
@allsynapses.each_with_index do |synapse, index|
if @synapses.index{|s| s.desc == synapse.desc} == nil
@synapses.push(synapse)
end
if @mappers.index(synapse.user) == nil
@mappers.push(synapse.user)
end
end
end
if @map || @topic
@metacodes.sort! {|x,y| @metacodes.sort! {|x,y|
n1 = x.name || "" n1 = x.name || ""
n2 = y.name || "" n2 = y.name || ""
@ -70,7 +89,7 @@
<div class="filterBox"> <div class="filterBox">
<h2>FILTER BY</h2> <h2>FILTER BY</h2>
<div id="filter_by_mapper" class="filterBySection"> <div id="filter_by_mapper" class="filterBySection">
<h3>MAPPERS</h3> <h3><%= @map ? "MAPPERS" : @topic ? "CREATORS" : "" %></h3>
<span class="hideAll hideAllMappers">NONE</span> <span class="hideAll hideAllMappers">NONE</span>
<span class="showAll showAllMappers">ALL</span> <span class="showAll showAllMappers">ALL</span>
<div class="clearfloat"></div> <div class="clearfloat"></div>

View file

@ -19,6 +19,7 @@
Metamaps.currentSection = "topic"; Metamaps.currentSection = "topic";
Metamaps.currentPage = <%= @topic.id.to_s %>; Metamaps.currentPage = <%= @topic.id.to_s %>;
Metamaps.Active.Topic = <%= @topic.to_json.html_safe %>; Metamaps.Active.Topic = <%= @topic.to_json.html_safe %>;
Metamaps.Creators = <%= @allcreators.to_json.html_safe %>;
Metamaps.Topics = <%= @alltopics.to_json.html_safe %>; Metamaps.Topics = <%= @alltopics.to_json.html_safe %>;
Metamaps.Synapses = <%= @allsynapses.to_json.html_safe %>; Metamaps.Synapses = <%= @allsynapses.to_json.html_safe %>;
Metamaps.Visualize.type = "RGraph"; Metamaps.Visualize.type = "RGraph";