fixed filters, updated ruby models further for returning json

This commit is contained in:
Connor Turland 2014-08-12 12:01:01 -04:00
parent f0eb4da6a9
commit 173179d682
7 changed files with 48 additions and 24 deletions

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'));
},
@ -921,7 +912,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();
@ -1033,7 +1024,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);
},
@ -2180,7 +2171,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

@ -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

@ -45,8 +45,12 @@ end
self.user.name
end
def user_image
self.user.image.url
end
def as_json(options={})
super(:methods =>[:user_name, :topic_count, :synapse_count])
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

@ -40,7 +40,8 @@ has_many :mappings
end
def as_json(options={})
{ :name =>self.name,
{ :id => self.id,
:name => self.name,
:email => self.email,
:image => self.image.url
}