From 173179d682e3620dac1f4ce4a03eab35d6163966 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Tue, 12 Aug 2014 12:01:01 -0400 Subject: [PATCH] fixed filters, updated ruby models further for returning json --- app/assets/javascripts/metamaps/Metamaps.js | 15 +++------------ app/controllers/main_controller.rb | 10 +--------- app/models/map.rb | 6 +++++- app/models/mapping.rb | 12 ++++++++++++ app/models/synapse.rb | 12 ++++++++++++ app/models/topic.rb | 14 +++++++++++++- app/models/user.rb | 3 ++- 7 files changed, 48 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/metamaps/Metamaps.js b/app/assets/javascripts/metamaps/Metamaps.js index a14f9640..a33a0989 100644 --- a/app/assets/javascripts/metamaps/Metamaps.js +++ b/app/assets/javascripts/metamaps/Metamaps.js @@ -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 = '
'; - u += '
Created by ' + synapse.getUser().get("name") + '
'; + u += '
Created by ' + synapse.get("user_name") + '
'; $('#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; diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index eac994fa..fe7de0fe 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -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 diff --git a/app/models/map.rb b/app/models/map.rb index 2bfcd663..cc86b6d3 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -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 ###### diff --git a/app/models/mapping.rb b/app/models/mapping.rb index ada72cf9..0de78e09 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -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 diff --git a/app/models/synapse.rb b/app/models/synapse.rb index 1415997e..f7dc58c6 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -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 diff --git a/app/models/topic.rb b/app/models/topic.rb index 668c94fe..79183195 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index c5bb0969..bf2ddd9a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 }