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
|
|
|
|
|
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]+"%"
|
|
|
|
@topics = Topic.where("name LIKE ?", like_keyword)
|
|
|
|
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
|
|
|
|
|
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
|