pulling in Connors work on routers

Merge branch 'connor' of https://github.com/Connoropolous/metamaps_gen002 into new
This commit is contained in:
Connor Turland 2014-08-06 10:16:53 -04:00
commit d14d505c3a
14 changed files with 372 additions and 161 deletions

View file

@ -82,8 +82,13 @@ Metamaps.GlobalUI = {
$('.alert.metamaps').delay(10000).fadeOut('fast');
// initialize global backbone models and collections
Metamaps.Active.Mapper = new Metamaps.Backbone.Mapper(Metamaps.Active.Mapper);
Metamaps.Maps = new Metamaps.Backbone.MapsCollection();
if (Metamaps.Active.Mapper) Metamaps.Active.Mapper = new Metamaps.Backbone.Mapper(Metamaps.Active.Mapper);
Metamaps.Mappers = new Metamaps.Backbone.MapperCollection([Metamaps.Active.Mapper]);
Metamaps.Maps = {};
Metamps.Maps.Mine = new Metamaps.Backbone.MapsCollection();
Metamps.Maps.Featured = new Metamaps.Backbone.MapsCollection();
Metamps.Maps.Active = new Metamaps.Backbone.MapsCollection();
Metamps.Maps.New = new Metamaps.Backbone.MapsCollection();
},
openLightbox: function (which) {
var self = Metamaps.GlobalUI;

View file

@ -8,6 +8,10 @@ Metamaps.JIT = {
var self = Metamaps.JIT;
self.prepareVizData();
$(".zoomIn").click(self.zoomIn);
$(".zoomOut").click(self.zoomOut);
$(".centerMap").click(self.centerMap);
$(".zoomExtents").click(self.zoomExtents);
},
/**
* convert our topic JSON into something JIT can use
@ -307,7 +311,7 @@ Metamaps.JIT = {
if (Metamaps.Mouse.boxStartCoordinates) {
Metamaps.Visualize.mGraph.busy = false;
Metamaps.Mouse.boxEndCoordinates = eventInfo.getPos();
Metamaps.JIT.selectNodesWithBox(e);
Metamaps.JIT.selectWithBox(e);
return;
}
@ -331,7 +335,7 @@ Metamaps.JIT = {
if (Metamaps.Mouse.boxStartCoordinates) {
Metamaps.Visualize.mGraph.busy = false;
Metamaps.Mouse.boxEndCoordinates = eventInfo.getPos();
Metamaps.JIT.selectNodesWithBox(e);
Metamaps.JIT.selectWithBox(e);
return;
}
@ -897,7 +901,7 @@ Metamaps.JIT = {
}
return 'nothing'; //case 4?
}, // handleSelectionBeforeDragging
selectNodesWithBox: function (e) {
selectWithBox: function (e) {
var sX = Metamaps.Mouse.boxStartCoordinates.x,
sY = Metamaps.Mouse.boxStartCoordinates.y,
@ -1025,7 +1029,7 @@ Metamaps.JIT = {
Metamaps.Mouse.boxStartCoordinates = false;
Metamaps.Mouse.boxEndCoordinates = false;
Metamaps.Visualize.mGraph.plot();
}, // selectNodesWithBox
}, // selectWithBox
drawSelectBox: function (eventInfo, e) {
var ctx = Metamaps.Visualize.mGraph.canvas.getCtx();
@ -1425,5 +1429,91 @@ Metamaps.JIT = {
y: posChild.y
}, 13, inv, canvas, 0.3);
}
} //renderEdgeArrows
}, //renderEdgeArrows
zoomIn: function () {
Metamaps.Visualize.mGraph.canvas.scale(1.25,1.25);
},
zoomOut: function () {
Metamaps.Visualize.mGraph.canvas.scale(0.8,0.8);
},
centerMap: function () {
var canvas = Metamaps.Visualize.mGraph.canvas;
var offsetScale = canvas.scaleOffsetX;
canvas.scale(1/offsetScale,1/offsetScale);
var offsetX = canvas.translateOffsetX;
var offsetY = canvas.translateOffsetY;
canvas.translate(-1*offsetX,-1*offsetY);
},
zoomExtents: function () {
Metamaps.JIT.centerMap();
var height = $(document).height(),
width = $(document).width(),
maxX, minX, maxY, minY, counter = 0;
var nodes = Metamaps.Visualize.mGraph.graph;
if(Object.keys(nodes).length >1){
nodes.eachNode(function (n) {
var x = n.pos.x,
y = n.pos.y;
if (counter == 0){
maxX = x;
minX = x;
maxY = y;
minY = y;
}
maxX = Math.max(x,maxX);
maxY = Math.max(y,maxY);
minX = Math.min(x,minX);
minY = Math.min(y,minY);
counter++;
});
var spanX = maxX - minX;
var spanY = maxY - minY;
var ratioX = spanX / width;
var ratioY = spanY / height;
var newRatio = Math.max(ratioX,ratioY);
var canvas = Metamaps.Visualize.mGraph.canvas;
canvas.scale(1/newRatio*0.9,1/newRatio*0.9);
counter = 0;
nodes.eachNode(function (n) {
var x = n.pos.x,
y = n.pos.y;
if (counter == 0){
maxX = x;
minX = x;
maxY = y;
minY = y;
}
maxX = Math.max(x,maxX);
maxY = Math.max(y,maxY);
minX = Math.min(x,minX);
minY = Math.min(y,minY);
counter++;
});
var cogX = (maxX + minX)/2;
var cogY = (maxY + minY)/2;
canvas.translate(-1* cogX, -1* cogY);
}
}
};

View file

@ -5,18 +5,29 @@
"explore/:section": "explore", // #explore/active
"maps/:id": "maps" // #maps/7
},
home: function () {
document.title = 'My Maps | Metamaps';
$('#cards').show();
},
explore: function (section) {
console.log(section);
var capitalize = section.charAt(0).toUpperCase() + section.slice(1);
document.title = 'Explore ' + capitalize + ' Maps | Metamaps';
//$('#cards').hide();
},
maps: function (id) {
console.log(id);
document.title = 'Map ' + id + ' | Metamaps';
$('#cards').hide();
}
});
Metamaps.Router = new Router();
Metamaps.Router.init = function () {
/*Backbone.history.start({
Backbone.history.start({
pushState: true,
root: ''
root: '/'
});
console.log('router started');
$(document).on("click", "a:not([data-bypass])", function (evt) {
@ -25,11 +36,13 @@
attr: $(this).attr("href")
};
var root = location.protocol + "//" + location.host + Backbone.history.options.root;
if (href.prop && href.prop === root) href.attr = ""
if (href.prop && href.prop.slice(0, root.length) === root) {
evt.preventDefault();
Backbone.history.navigate(href.attr, true);
}
});*/
});
}
})();

View file

@ -0,0 +1,26 @@
(function () {
Metamaps.Views = {};
Metamaps.Views.MapCard = Backbone.View.extend({
tagName: "div",
className: "map",
events: {
"click .icon": "open",
"click .button.edit": "openEditDialog",
"click .button.delete": "destroy"
},
initialize: function () {
this.listenTo(this.model, "change", this.render);
},
render: function () {
}
});
})();

View file

@ -1679,9 +1679,8 @@ Metamaps.Control = {
},
deleteNode: function (nodeid) { // refers to deleting topics permanently
var node = Metamaps.Visualize.mGraph.graph.getNode(nodeid);
var id = node.getData('id');
Metamaps.Control.deselectNode(node);
Metamaps.Topics.get(id).destroy();
Metamaps.Topics.get(nodeid).destroy();
Metamaps.Control.hideNode(nodeid);
},
removeSelectedNodes: function () { // refers to removing topics permanently from a map
@ -1700,11 +1699,10 @@ Metamaps.Control = {
removeNode: function (nodeid) { // refers to removing topics permanently from a map
var mapperm = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
var node = Metamaps.Visualize.mGraph.graph.getNode(nodeid);
var mappingid = node.getData("mapping").id;
if (mapperm) {
Metamaps.Control.deselectNode(node);
Metamaps.Mappings.get(mappingid).destroy();
node.getData('mapping').destroy();
Metamaps.Control.hideNode(nodeid);
}
},
@ -2059,7 +2057,7 @@ Metamaps.Filter = {
var addedSynapses = [];
Metamaps.Synapses.each(function(synapse) {
if (newSynapsesList.indexOf(synapse.get('desc')) === -1) {
if (synapse.get('desc') && newSynapsesList.indexOf(synapse.get('desc')) === -1) {
newSynapsesList.push(synapse.get('desc').toString());
}
});

View file

@ -791,6 +791,47 @@ li.accountInvite span {
width: 35px;
height: 35px;
}
.zoomIn {
position: absolute;
bottom: 100px;
right: 20px;
z-index: 200;
width: 35px;
height: 35px;
background: blue;
}
.zoomOut {
position: absolute;
bottom: 60px;
right: 20px;
z-index: 200;
width: 35px;
height: 35px;
background: blue;
}
.centerMap {
position: absolute;
bottom: 140px;
right: 20px;
z-index: 200;
width: 35px;
height: 35px;
background: blue;
}
.zoomExtents {
position: absolute;
bottom: 180px;
right: 20px;
z-index: 200;
width: 35px;
height: 35px;
background: blue;
}
.sidebarFilter.loggedout {
right: 35px;
}

View file

@ -12,22 +12,22 @@ class MapsController < ApplicationController
# GET /maps/mappers/:id
def index
if request.path == "/maps"
if request.path == "/explore"
redirect_to activemaps_url and return
end
@current = current_user
@user = nil
if request.path =="/maps/active"
if request.path =="/explore/active"
@maps = Map.order("updated_at DESC").limit(20)
@request = "active"
elsif request.path =="/maps/featured"
elsif request.path =="/explore/featured"
@maps = Map.order("name ASC").find_all_by_featured(true)
@request = "featured"
elsif request.path == "/maps/new"
elsif request.path == "/explore/new"
@maps = Map.order("created_at DESC").limit(20)
@request = "new"

View file

@ -4,7 +4,40 @@
#%>
<div class="templates">
<script type="text/template" id="mapCardTemplate">
<div class="map" id="{{id}}">
<div class="permission {{editPermission}}"> <!-- must be canEdit or cannotEdit -->
<div class="mapCard">
<span class="title">
<span class="best_in_place best_in_place_name" id="best_in_place_map_{{id}}_name" data-url="/maps/{{id}}" data-object="map" data-attribute="name" data-type="textarea">{{name}}</span>
</span>
<div class="links">
<div class="linkItem icon">
<div class="metacodeImage" style="background-image:url(/assets/map.png);"></div>
</div>
<div class="linkItem contributor hoverForTip">
<div class="tip">Created by {{username}} on {{createdAt}}</div>
</div>
<div class="linkItem topicCount">{{topicCount}}</div>
<div class="linkItem synapseCount">[{synapseCount}}</div>
<div class="linkItem mapPerm {{mkPermission}}"></div>
<a href="/maps/{{id}}" class="linkItem topicPopout"></a>
<div class="clearfloat"></div>
</div>
<div class="scroll">
<div class="desc">
<span class="best_in_place best_in_place_desc" id="best_in_place_map_{{id}}_desc" data-url="/maps/{{id}}" data-object="map" data-attribute="desc" data-nil="Click to add description." data-type="textarea">{{desc}}</span>
<div class="clearfloat"></div>
</div>
</div>
<div class="clearfloat"></div>
</div>
</div>
</div>
</script>
<script type="text/template" id="topicSearchTemplate">
<div class="result{{rtype}}">
<div class="topicMetacode">

View file

@ -36,7 +36,7 @@
<div class="wrapper <%= controller_name == "main" && action_name == "home" ? "homePage" : "" %>" id="wrapper">
<div class="homeButton">
<a href="/"></a>
<a href="<%= root_url %>"></a>
</div>
<div class="sidebarSearch">

View file

@ -101,7 +101,7 @@ $(document).ready(function() {
<div class="mapOrder">
<span class="displaying">Displaying:</span>
<div class="whichMaps">
<a href="/maps/mappers/<%= @current.id %>" class="active">Yours</a> /
<a href="/" class="active">My Maps</a> /
<a href="/explore/active">Recently Active</a> /
<a href="/explore/featured">Featured</a> /
<a href="/explore/new">Newest First</a>

View file

@ -17,12 +17,12 @@
<% end %>
<% if @request != "topic" %>
<a href="/maps/active" class="<%= @request == "active" ? "active" : "" %>">Recently Active</a> /
<a href="/maps/featured" class="<%= @request == "featured" ? "active" : "" %>">Featured</a> /
<a href="/maps/new" class="<%= @request == "new" ? "active" : "" %>">Newest First</a>
<% if authenticated? %>
/ <a href="/maps/mappers/<%= @current.id %>" class="<%= @request == "you" ? "active" : "" %>">Yours</a>
<a href="/maps/mappers/<%= @current.id %>" class="<%= @request == "you" ? "active" : "" %>">My Maps</a> /
<% end %>
<a href="/explore/active" class="<%= @request == "active" ? "active" : "" %>">Recently Active</a> /
<a href="/explore/featured" class="<%= @request == "featured" ? "active" : "" %>">Featured</a> /
<a href="/explore/new" class="<%= @request == "new" ? "active" : "" %>">Newest First</a>
<% end %>
</div>
<div class="clearfloat"></div>

View file

@ -42,6 +42,11 @@
</div>
</div>
<div class="zoomIn">+</div>
<div class="zoomOut">-</div>
<div class="centerMap">C</div>
<div class="zoomExtents">E</div>
<div class="index">
<div class="openCheatsheet openLightbox" data-open="cheatsheet"></div>
<span class="mapInfo"></span>

View file

@ -19,9 +19,9 @@ Metamaps::Application.routes.draw do
get :autocomplete_topic, :on => :collection
end
match 'maps/active', to: 'maps#index', via: :get, as: :activemaps
match 'maps/featured', to: 'maps#index', via: :get, as: :featuredmaps
match 'maps/new', to: 'maps#index', via: :get, as: :newmaps
match 'explore/active', to: 'maps#index', via: :get, as: :activemaps
match 'explore/featured', to: 'maps#index', via: :get, as: :featuredmaps
match 'explore/new', to: 'maps#index', via: :get, as: :newmaps
match 'maps/mappers/:id', to: 'maps#index', via: :get, as: :usermaps
match 'maps/topics/:id', to: 'maps#index', via: :get, as: :topicmaps
resources :maps, except: [:new, :edit]

View file

@ -1,129 +1,129 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140707161810) do
create_table "in_metacode_sets", :force => true do |t|
t.integer "metacode_id"
t.integer "metacode_set_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "in_metacode_sets", ["metacode_id"], :name => "index_in_metacode_sets_on_metacode_id"
add_index "in_metacode_sets", ["metacode_set_id"], :name => "index_in_metacode_sets_on_metacode_set_id"
create_table "mappings", :force => true do |t|
t.text "category"
t.integer "xloc"
t.integer "yloc"
t.integer "topic_id"
t.integer "synapse_id"
t.integer "map_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "maps", :force => true do |t|
t.text "name"
t.boolean "arranged"
t.text "desc"
t.text "permission"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "featured"
end
create_table "metacode_sets", :force => true do |t|
t.string "name"
t.text "desc"
t.integer "user_id"
t.boolean "mapperContributed"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "metacode_sets", ["user_id"], :name => "index_metacode_sets_on_user_id"
create_table "metacodes", :force => true do |t|
t.text "name"
t.string "icon"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "synapses", :force => true do |t|
t.text "desc"
t.text "category"
t.text "weight"
t.text "permission"
t.integer "node1_id"
t.integer "node2_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "topics", :force => true do |t|
t.text "name"
t.text "desc"
t.text "link"
t.text "permission"
t.integer "user_id"
t.integer "metacode_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.string "audio_file_name"
t.string "audio_content_type"
t.integer "audio_file_size"
t.datetime "audio_updated_at"
end
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.text "settings"
t.string "code", :limit => 8
t.string "joinedwithcode", :limit => 8
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"
t.string "perishable_token"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "encrypted_password", :limit => 128, :default => ""
t.string "remember_token"
t.datetime "remember_created_at"
t.string "reset_password_token"
t.datetime "last_sign_in_at"
t.string "last_sign_in_ip"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.string "current_sign_in_ip"
t.datetime "reset_password_sent_at"
t.boolean "admin"
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
end
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140707161810) do
create_table "in_metacode_sets", :force => true do |t|
t.integer "metacode_id"
t.integer "metacode_set_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "in_metacode_sets", ["metacode_id"], :name => "index_in_metacode_sets_on_metacode_id"
add_index "in_metacode_sets", ["metacode_set_id"], :name => "index_in_metacode_sets_on_metacode_set_id"
create_table "mappings", :force => true do |t|
t.text "category"
t.integer "xloc"
t.integer "yloc"
t.integer "topic_id"
t.integer "synapse_id"
t.integer "map_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "maps", :force => true do |t|
t.text "name"
t.boolean "arranged"
t.text "desc"
t.text "permission"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "featured"
end
create_table "metacode_sets", :force => true do |t|
t.string "name"
t.text "desc"
t.integer "user_id"
t.boolean "mapperContributed"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "metacode_sets", ["user_id"], :name => "index_metacode_sets_on_user_id"
create_table "metacodes", :force => true do |t|
t.text "name"
t.string "icon"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "synapses", :force => true do |t|
t.text "desc"
t.text "category"
t.text "weight"
t.text "permission"
t.integer "node1_id"
t.integer "node2_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "topics", :force => true do |t|
t.text "name"
t.text "desc"
t.text "link"
t.text "permission"
t.integer "user_id"
t.integer "metacode_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.string "audio_file_name"
t.string "audio_content_type"
t.integer "audio_file_size"
t.datetime "audio_updated_at"
end
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.text "settings"
t.string "code", :limit => 8
t.string "joinedwithcode", :limit => 8
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"
t.string "perishable_token"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "encrypted_password", :limit => 128, :default => ""
t.string "remember_token"
t.datetime "remember_created_at"
t.string "reset_password_token"
t.datetime "last_sign_in_at"
t.string "last_sign_in_ip"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.string "current_sign_in_ip"
t.datetime "reset_password_sent_at"
t.boolean "admin"
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
end