2012-09-23 02:39:12 +00:00
|
|
|
class MainController < ApplicationController
|
2013-01-01 22:45:35 +00:00
|
|
|
include TopicsHelper
|
2012-09-23 02:39:12 +00:00
|
|
|
|
2012-10-29 17:52:29 +00:00
|
|
|
before_filter :require_user, only: [:invite]
|
|
|
|
|
2012-09-23 02:39:12 +00:00
|
|
|
respond_to :html, :js, :json
|
|
|
|
|
2013-01-08 04:03:41 +00:00
|
|
|
def home
|
2013-01-18 22:08:06 +00:00
|
|
|
@maps = Map.visibleToUser(@current, nil).sort! { |a,b| b.created_at <=> a.created_at }
|
2013-12-02 01:47:28 +00:00
|
|
|
@maps = @maps.slice(0,5)
|
2013-01-08 04:03:41 +00:00
|
|
|
|
2013-02-04 00:13:21 +00:00
|
|
|
respond_with(@maps)
|
2013-01-08 04:03:41 +00:00
|
|
|
end
|
|
|
|
|
2012-12-14 18:31:39 +00:00
|
|
|
def console
|
2012-10-28 18:37:46 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-12-23 06:12:56 +00:00
|
|
|
def search
|
|
|
|
@current = current_user
|
2013-01-01 22:45:35 +00:00
|
|
|
@topics = Array.new()
|
2013-01-03 08:53:25 +00:00
|
|
|
@synapses = Array.new()
|
|
|
|
if params[:topics_by_name] != ""
|
|
|
|
like_keyword = "%"+params[:topics_by_name]+"%"
|
2013-02-22 02:36:33 +00:00
|
|
|
like_keyword.downcase! #convert to lowercase for better comparison
|
|
|
|
@topics = Topic.where("LOWER(name) LIKE ?", like_keyword)
|
2013-01-03 08:53:25 +00:00
|
|
|
end
|
2012-12-23 06:12:56 +00:00
|
|
|
if params[:topics_by_user_id] != ""
|
|
|
|
@user = User.find(params[:topics_by_user_id])
|
2013-01-03 08:53:25 +00:00
|
|
|
@topics = @topics | Topic.visibleToUser(@current, @user)
|
|
|
|
end
|
|
|
|
if params[:topics_by_map_id] != ""
|
2012-12-23 06:12:56 +00:00
|
|
|
@map = Map.find(params[:topics_by_map_id])
|
2013-01-03 08:53:25 +00:00
|
|
|
@topics = @topics | @map.topics.delete_if{|topic| not topic.authorize_to_view(@current)}
|
|
|
|
end
|
|
|
|
|
|
|
|
@topics.each do |t|
|
|
|
|
t.synapses.each do |s|
|
|
|
|
@synapses = @synapses.push(s) if not @synapses.include? s
|
|
|
|
end
|
2012-12-23 06:12:56 +00:00
|
|
|
end
|
2013-01-03 08:53:25 +00:00
|
|
|
|
2013-01-03 23:21:46 +00:00
|
|
|
@topics.sort! { |a,b| a.name.downcase <=> b.name.downcase }
|
|
|
|
|
2012-12-23 06:12:56 +00:00
|
|
|
respond_to do |format|
|
2013-01-03 08:53:25 +00:00
|
|
|
format.js { respond_with(@topics,@synapses) }
|
2012-12-23 06:12:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-04 00:13:21 +00:00
|
|
|
|
|
|
|
def requestinvite
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-10-29 17:52:29 +00:00
|
|
|
def invite
|
|
|
|
@user = current_user
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { respond_with(@user) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-23 02:39:12 +00:00
|
|
|
|
|
|
|
end
|