This commit is contained in:
Shai Mor 2014-08-12 12:56:20 -04:00
commit 304c9f3b4b
20 changed files with 131 additions and 81 deletions

View file

@ -1,7 +1,7 @@
Metamaps.Backbone = {};
Metamaps.Backbone.Map = Backbone.Model.extend({
urlRoot: '/maps',
blacklist: ['created_at', 'updated_at', 'topics', 'synapses', 'mappings', 'mappers'],
blacklist: ['created_at', 'updated_at', 'user_name', 'topic_count', 'synapse_count', 'topics', 'synapses', 'mappings', 'mappers'],
toJSON: function (options) {
return _.omit(this.attributes, this.blacklist);
},
@ -14,15 +14,16 @@ Metamaps.Backbone.Map = Backbone.Model.extend({
},
fetchContained: function () {
var bb = Metamaps.Backbone;
var that = this;
var start = function (data) {
this.set('mappers', new bb.MapperCollection(data.mappers));
this.set('topics', new bb.TopicCollection(data.topics));
this.set('synapses', new bb.SynapseCollection(data.synapses));
this.set('mappings', new bb.MappingCollection(data.mappings));
that.set('mappers', new bb.MapperCollection(data.mappers));
that.set('topics', new bb.TopicCollection(data.topics));
that.set('synapses', new bb.SynapseCollection(data.synapses));
that.set('mappings', new bb.MappingCollection(data.mappings));
}
$.ajax({
url: "/maps/" + this.id + "/contains",
url: "/maps/" + this.id + "/contains.json",
success: start,
async: false
});
@ -56,11 +57,11 @@ Metamaps.Backbone.Map = Backbone.Model.extend({
id: this.id,
name: this.get('name'),
desc: this.get('desc'),
username: this.getUser().get('name'),
mkPermission: this.get("permission") ? this.get("permission").substring(0, 2) : "commons",
username: this.get('user_name'),
mkPermission: this.get("permission") ? this.get("permission").substring(0, 2) : "co",
editPermission: this.authorizeToEdit(Metamaps.Active.Mapper) ? 'canEdit' : 'cannotEdit',
topicCount: this.getTopics().length,
synapseCount: this.getSynapses().length,
topicCount: this.get('topic_count'),
synapseCount: this.get('synapse_count'),
createdAt: this.get('created_at')
};
return obj;
@ -78,16 +79,21 @@ Metamaps.Backbone.MapsCollection = Backbone.Collection.extend({
comparator: function (a, b) {
a = a.get(this.sortBy);
b = b.get(this.sortBy);
var temp;
if (this.sortBy === 'name') {
a = a ? a.toLowerCase() : "";
b = b ? b.toLowerCase() : "";
}
else {
// this is for updated_at and created_at
temp = a;
a = b;
b = temp;
}
return a > b ? 1 : a < b ? -1 : 0;
},
getMaps: function () {
Metamaps.Loading.loader.show();
var self = this;
this.fetch({

View file

@ -75,10 +75,6 @@ Metamaps.GlobalUI = {
});
$('#lightbox_screen, #lightbox_close').click(self.closeLightbox);
// hide notices after 10 seconds
$('.notice.metamaps').delay(10000).fadeOut('fast');
$('.alert.metamaps').delay(10000).fadeOut('fast');
// initialize global backbone models and collections
if (Metamaps.Active.Mapper) Metamaps.Active.Mapper = new Metamaps.Backbone.Mapper(Metamaps.Active.Mapper);

View file

@ -52,15 +52,14 @@
Metamaps.GlobalUI.Search.close(0, true);
$('.mapsWrapper').fadeOut(300);
setTimeout(function(){
Metamaps.Router.navigate("");
}, 500);
}
Metamaps.Famous.viz.hide();
Metamaps.Active.Map = null;
Metamaps.Active.Topic = null;
setTimeout(function(){
Metamaps.Router.navigate("");
}, 500);
},
explore: function (section) {
@ -76,7 +75,10 @@
Metamaps.Views.exploreMaps.setCollection( Metamaps.Maps[capitalize] );
if (Metamaps.Maps[capitalize].length === 0) {
Metamaps.Maps[capitalize].getMaps(); // this will trigger an explore maps render
Metamaps.Loading.loader.show();
setTimeout(function(){
Metamaps.Maps[capitalize].getMaps(); // this will trigger an explore maps render
}, 1000); // wait 500 milliseconds till the other animations are done to do the fetch
}
else {
Metamaps.Views.exploreMaps.render();
@ -95,10 +97,6 @@
Metamaps.Famous.viz.hide();
Metamaps.Active.Map = null;
Metamaps.Active.Topic = null;
setTimeout(function(){
Metamaps.Router.navigate("/explore/" + section);
}, 500);
},
maps: function (id) {

View file

@ -47,8 +47,6 @@ Metamaps.Views.init = function () {
},
render: function () {
Metamaps.Loading.loader.hide();
var that = this;
this.$el.empty();
@ -57,12 +55,18 @@ Metamaps.Views.init = function () {
that.$el.append( view.render().el );
});
Metamaps.Loading.loader.hide();
setTimeout(function(){
var path = Metamaps.currentSection == "" ? "" : "/explore/" + Metamaps.currentPage;
Metamaps.Router.navigate(path);
}, 500);
},
handleSuccess: function () {
this.render();
},
handleError: function () {
alert('error!');
console.log('error loading maps!'); //TODO
}
});

View file

@ -126,9 +126,6 @@ Metamaps.Backbone.init = function () {
},
getDate: function () {
},
getUser: function () {
return Metamaps.Mapper.get(this.get('user_id'));
},
getMetacode: function () {
return Metamaps.Metacodes.get(this.get('metacode_id'));
@ -212,9 +209,6 @@ Metamaps.Backbone.init = function () {
if (mapper && this.get('user_id') === mapper.get('id')) return true;
else return false;
},
getUser: function () {
return Metamaps.Mapper.get(this.get('user_id'));
},
getTopic1: function () {
return Metamaps.Topic.get(this.get('node1_id'));
},
@ -291,9 +285,6 @@ Metamaps.Backbone.init = function () {
});
}
},
getUser: function () {
return Metamaps.Mapper.get(this.get('user_id'));
},
getMap: function () {
return Metamaps.Map.get(this.get('map_id'));
},
@ -924,7 +915,7 @@ Metamaps.TopicCard = {
nodeValues.imgsrc = topic.getMetacode().get("icon");
nodeValues.name = topic.get("name");
nodeValues.userid = topic.get("user_id");
nodeValues.username = topic.getUser().get("name");
nodeValues.username = topic.get("user_name");
nodeValues.date = topic.getDate();
// the code for this is stored in /views/main/_metacodeOptions.html.erb
nodeValues.metacode_select = $('#metacodeOptions').html();
@ -1036,7 +1027,7 @@ Metamaps.SynapseCard = {
add_user_info: function (synapse) {
var u = '<div id="edgeUser" class="hoverForTip">';
u += '<div class="tip">Created by ' + synapse.getUser().get("name") + '</div></div>';
u += '<div class="tip">Created by ' + synapse.get("user_name") + '</div></div>';
$('#edit_synapse').append(u);
},
@ -1399,7 +1390,7 @@ Metamaps.Realtime = {
var mapperm = Metamaps.Active.Map && Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
if (mapperm) {
self.socket = io.connect('http://localhost:5001');
self.socket = io.connect('http://gentle-savannah-1303.herokuapp.com');
self.socket.on('connect', function () {
console.log('socket connected');
self.setupSocket();
@ -2183,7 +2174,7 @@ Metamaps.Filter = {
},
checkMappers: function () {
var self = Metamaps.Filter;
self.updateFilters('both', 'user_id', 'Mapper', 'mappers', 'mapper');
self.updateFilters('both', 'user_id', 'Mappers', 'mappers', 'mapper');
},
checkSynapses: function () {
var self = Metamaps.Filter;

View file

@ -201,15 +201,10 @@ input[type="submit"]:hover {
.forgotPassword {
display: block;
width: 250px;
position: absolute;
left: 50%;
top: 0;
margin: 100px 0 0 -145px;
background: url(bg.png);
background-color: #E0E0E0;
padding: 20px;
border-radius: 5px;
color: black;
border: 1px solid #000;
box-shadow: 6px 6px 8px rgba(0, 0, 0, 0.4);
}
.centerGreyForm input[type="text"],

View file

@ -363,7 +363,7 @@ float:left;
}
.addLink div {
display: inline-block;
float: left;
}
#addLinkBack {
@ -383,7 +383,7 @@ padding: 7px 31px 7px 31px;
height: 16px;
width: 172px;
margin: 0 0 0 0;
border: 1px solid #EFEFEF;
border: 1px solid #BDBDBD;
outline: none;
font-size: 16px;
line-height: 16px;
@ -399,6 +399,7 @@ font-family: 'LatoLight';
width: 32px;
height: 32px;
cursor: pointer;
float:none;
}
.cardSettings {

View file

@ -9,17 +9,9 @@ class MainController < ApplicationController
# home page
def home
@current = current_user
if !authenticated?
@maps = Map.find_all_by_featured(true).shuffle!
@maps = @maps.slice(0,3)
elsif authenticated?
#@maps = Map.order("updated_at DESC").where("permission != ?", "private").limit(3)
@maps = Map.order("name ASC").find_all_by_user_id(@current.id)
end
respond_to do |format|
format.html { respond_with(@maps, @current) }
format.html { respond_with(@current) }
end
end

View file

@ -32,6 +32,26 @@ end
return contributors
end
def topic_count
self.topics.length
end
def synapse_count
self.synapses.length
end
def user_name
self.user.name
end
def user_image
self.user.image.url
end
def as_json(options={})
super(:methods =>[:user_name, :user_image, :topic_count, :synapse_count])
end
##### PERMISSIONS ######

View file

@ -5,6 +5,18 @@ belongs_to :synapse, :class_name => "Synapse", :foreign_key => "synapse_id"
belongs_to :map, :class_name => "Map", :foreign_key => "map_id"
belongs_to :user
def user_name
self.user.name
end
def user_image
self.user.image.url
end
def as_json(options={})
super(:methods =>[:user_name, :user_image])
end
# sends push updates through redis to websockets for realtime updates
def message action, origin_user_id

View file

@ -8,6 +8,18 @@ belongs_to :topic2, :class_name => "Topic", :foreign_key => "node2_id"
has_many :mappings
has_many :maps, :through => :mappings
def user_name
self.user.name
end
def user_image
self.user.image.url
end
def as_json(options={})
super(:methods =>[:user_name, :user_image])
end
# sends push updates through redis to websockets for realtime updates
def message action, origin_user_id

View file

@ -37,7 +37,19 @@ has_many :maps, :through => :mappings
topics1 + topics2
end
belongs_to :metacode
belongs_to :metacode
def user_name
self.user.name
end
def user_image
self.user.image.url
end
def as_json(options={})
super(:methods =>[:user_name, :user_image])
end
# sends push updates through redis to websockets for realtime updates
def message action, origin_user_id

View file

@ -38,6 +38,14 @@ has_many :mappings
trans << '( +clone -flop ) -compose multiply -composite '
trans << ') -alpha off -compose copy_opacity -composite '
end
def as_json(options={})
{ :id => self.id,
:name => self.name,
:email => self.email,
:image => self.image.url
}
end
if ActiveRecord::Base.connection.table_exists? 'users'
codes = ActiveRecord::Base.connection.execute("SELECT code FROM users").map {|user| user["code"] }

View file

@ -5,7 +5,7 @@
<% if authenticated? %>
<% account = current_user %>
<h3 class="accountHeader">Hello <%= account.name.split[0...1][0] %>!</h3>
<h3 class="accountHeader"><%= account.name.split[0...1][0] %></h3>
<ul>
<li class="accountIcon accountSettings"><%= link_to "Account", edit_user_url(account),
:data => { :bypass => 'true'} %></li>
@ -38,8 +38,9 @@
<% end %>
<div class="links">
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %>
<%= link_to "Forgot your password?", new_password_path(resource_name),
:data => { :bypass => 'true'} %>
<% end -%>
<a href="/request">Request Invite</a>
<a href="/request" data-bypass="true">Request Invite</a>
</div>
<% end %>

View file

@ -4,7 +4,8 @@
# User edit form
#%>
<% content_for :title, @user.name + "'s Settings | Metamaps" %>
<% content_for :title, @user.name + "'s Settings | Metamaps" %>
<div id="yield">
<%= formula_form_for @user, url: user_url do |form| %>
<h3>Edit Account</h3>
<label for="user_image">Profile Picture</label>
@ -15,4 +16,5 @@
<%= form.input :password, label: "Password", class: "password", :autocomplete => :off %>
<%= form.submit "Update", class: "update" %>
<% end %>
</div>

View file

@ -1,7 +1,6 @@
<% content_for :title, "Change Password | Metamaps" %>
<h1 class="index">Change Password</h1>
<div id="yield">
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put, :class => "forgotPassword centerGreyForm" }) do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>
@ -17,5 +16,5 @@
<div><%= f.submit "Change my password" %></div>
<% end %>
</div>

View file

@ -1,7 +1,6 @@
<% content_for :title, "Password Reset | Metamaps" %>
<h1 class="index">Password Reset</h1>
<div id="yield">
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post, :class => "forgotPassword centerGreyForm" }) do |f| %>
<%= devise_error_messages! %>
@ -13,5 +12,6 @@
<div><%= f.submit "Send me reset password instructions" %></div>
<% end %>
</div>

View file

@ -1,7 +1,6 @@
<% content_for :title, "Sign Up | Metamaps" %>
<h1 class="index">Sign Up</h1>
<div id="yield">
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :post, :class => "new_user centerGreyForm" }) do |f| %>
<%= devise_error_messages! %>
@ -24,7 +23,7 @@
<div><%= f.submit "Sign up" %></div>
<div><br />Don't have an access code?<br /><a href="/request">Request an Invite</a></div>
<div><br />Don't have an access code?<br /><a href="/request" data-bypass="true">Request an Invite</a></div>
<% end %>
</div>

View file

@ -1,7 +1,6 @@
<% content_for :title, "Sign In | Metamaps" %>
<h1 class="index">Sign In</h1>
<div id="yield">
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => { :method => :post, :class => "new_user centerGreyForm" }) do |f| %>
<h3>Sign in</h3>
@ -19,10 +18,11 @@
<br />
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<%= link_to "Forgot your password?", new_password_path(resource_name),
:data => { :bypass => 'true'} %><br />
<% end -%>
<br />
<div>Don't have an account?<br /><a href="/request">Request an Invite</a></div>
<div>Don't have an account?<br /><a href="/request" data-bypass="true">Request an Invite</a></div>
<% end %>
</div>

View file

@ -100,10 +100,12 @@ define(function(require, exports, module) {
f.loadYield = function () {
Metamaps.Loading.loader.hide();
var yield = document.getElementById('yield').innerHTML;
f.yield.surf.setContent(yield);
f.yield.surf.deploy(f.yield.surf._currTarget);
f.yield.show();
var yield = document.getElementById('yield') ? document.getElementById('yield').innerHTML : false;
if (yield) {
f.yield.surf.setContent(yield);
f.yield.surf.deploy(f.yield.surf._currTarget);
f.yield.show();
}
};