2012-09-23 02:39:12 +00:00
|
|
|
class MainController < ApplicationController
|
2013-01-01 22:45:35 +00:00
|
|
|
include TopicsHelper
|
2014-01-29 03:46:58 +00:00
|
|
|
include MapsHelper
|
|
|
|
include UsersHelper
|
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
|
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
# home page
|
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
|
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
# /request
|
|
|
|
def requestinvite
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# /invite
|
|
|
|
def invite
|
|
|
|
@user = current_user
|
2012-10-28 18:37:46 +00:00
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { respond_with(@user) }
|
|
|
|
end
|
2012-10-28 18:37:46 +00:00
|
|
|
end
|
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
### SEARCHING ###
|
|
|
|
|
|
|
|
# get /search/topics?term=SOMETERM
|
|
|
|
def searchtopics
|
2012-12-23 06:12:56 +00:00
|
|
|
@current = current_user
|
2013-01-03 08:53:25 +00:00
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
term = params[:term]
|
|
|
|
|
|
|
|
if term && !term.empty? && term.downcase[0..3] != "map:" && term.downcase[0..6] != "mapper:" && term.downcase != "topic:"
|
|
|
|
|
|
|
|
#remove "topic:" if appended at beginning
|
|
|
|
term = term[6..-1] if term.downcase[0..5] == "topic:"
|
|
|
|
|
|
|
|
#check whether there's a filter by metacode as part of the query
|
|
|
|
filterByMetacode = false
|
|
|
|
Metacode.all.each do |m|
|
|
|
|
lOne = m.name.length+1
|
|
|
|
lTwo = m.name.length
|
|
|
|
|
|
|
|
if term.downcase[0..lTwo] == m.name.downcase + ":"
|
|
|
|
term = term[lOne..-1]
|
|
|
|
filterByMetacode = m
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if filterByMetacode
|
|
|
|
if term == ""
|
|
|
|
@topics = []
|
|
|
|
else
|
|
|
|
search = '%' + term.downcase + '%'
|
|
|
|
@topics = Topic.where('LOWER("name") like ? OR LOWER("desc") like ? OR LOWER("link") like ?', search, search, search).
|
|
|
|
where('metacode_id = ?', filterByMetacode.id).limit(10).order('"name"').visibleToUser(@current,nil)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
search = '%' + term.downcase + '%'
|
|
|
|
@topics = Topic.where('LOWER("name") like ? OR LOWER("desc") like ? OR LOWER("link") like ?', search, search, search).
|
|
|
|
limit(10).order('"name"').visibleToUser(@current,nil)
|
2013-01-03 08:53:25 +00:00
|
|
|
end
|
2014-01-29 03:46:58 +00:00
|
|
|
else
|
|
|
|
@topics = []
|
2012-12-23 06:12:56 +00:00
|
|
|
end
|
2014-01-29 03:46:58 +00:00
|
|
|
render json: autocomplete_array_json(@topics)
|
|
|
|
#if params[:topics_by_user_id] != ""
|
|
|
|
# @user = User.find(params[:topics_by_user_id])
|
|
|
|
# @topics = @topics | Topic.visibleToUser(@current, @user)
|
|
|
|
#end
|
|
|
|
#if params[:topics_by_map_id] != ""
|
|
|
|
# @map = Map.find(params[:topics_by_map_id])
|
|
|
|
# @topics = @topics | @map.topics.delete_if{|topic| not topic.authorize_to_view(@current)}
|
|
|
|
#end
|
|
|
|
#@topics.sort! { |a,b| a.name.downcase <=> b.name.downcase }
|
|
|
|
end
|
|
|
|
|
|
|
|
# get /search/maps?term=SOMETERM
|
|
|
|
def searchmaps
|
|
|
|
@current = current_user
|
2013-01-03 08:53:25 +00:00
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
term = params[:term]
|
|
|
|
if term && !term.empty? && term.downcase[0..5] != "topic:" && term.downcase[0..6] != "mapper:" && term.downcase != "map:"
|
2013-01-03 23:21:46 +00:00
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
#remove "map:" if appended at beginning
|
|
|
|
term = term[4..-1] if term.downcase[0..3] == "map:"
|
|
|
|
|
|
|
|
search = '%' + term.downcase + '%'
|
|
|
|
@maps = Map.where('LOWER("name") like ? OR LOWER("desc") like ?', search, search).
|
|
|
|
limit(10).order('"name"').visibleToUser(@current,nil)
|
|
|
|
else
|
|
|
|
@maps = []
|
2012-12-23 06:12:56 +00:00
|
|
|
end
|
2014-01-29 03:46:58 +00:00
|
|
|
render json: autocomplete_map_array_json(@maps)
|
|
|
|
#if params[:topics_by_user_id] != ""
|
|
|
|
# @user = User.find(params[:topics_by_user_id])
|
|
|
|
# @topics = @topics | Topic.visibleToUser(@current, @user)
|
|
|
|
#end
|
|
|
|
#if params[:topics_by_map_id] != ""
|
|
|
|
# @map = Map.find(params[:topics_by_map_id])
|
|
|
|
# @topics = @topics | @map.topics.delete_if{|topic| not topic.authorize_to_view(@current)}
|
|
|
|
#end
|
|
|
|
#@topics.sort! { |a,b| a.name.downcase <=> b.name.downcase }
|
2012-12-23 06:12:56 +00:00
|
|
|
end
|
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
# get /search/mappers?term=SOMETERM
|
|
|
|
def searchmappers
|
|
|
|
@current = current_user
|
|
|
|
|
|
|
|
term = params[:term]
|
|
|
|
if term && !term.empty? && term.downcase[0..3] != "map:" && term.downcase[0..5] != "topic:" && term.downcase != "mapper:"
|
|
|
|
|
|
|
|
#remove "mapper:" if appended at beginning
|
|
|
|
term = term[7..-1] if term.downcase[0..6] == "mapper:"
|
|
|
|
|
|
|
|
@mappers = User.where('LOWER("name") like ?', '%' + term.downcase + '%').
|
|
|
|
limit(10).order('"name"')
|
|
|
|
else
|
|
|
|
@mappers = []
|
2012-10-29 17:52:29 +00:00
|
|
|
end
|
2014-01-29 03:46:58 +00:00
|
|
|
render json: autocomplete_user_array_json(@mappers)
|
|
|
|
#if params[:topics_by_user_id] != ""
|
|
|
|
# @user = User.find(params[:topics_by_user_id])
|
|
|
|
# @topics = @topics | Topic.visibleToUser(@current, @user)
|
|
|
|
#end
|
|
|
|
#if params[:topics_by_map_id] != ""
|
|
|
|
# @map = Map.find(params[:topics_by_map_id])
|
|
|
|
# @topics = @topics | @map.topics.delete_if{|topic| not topic.authorize_to_view(@current)}
|
|
|
|
#end
|
|
|
|
#@topics.sort! { |a,b| a.name.downcase <=> b.name.downcase }
|
|
|
|
end
|
2012-09-23 02:39:12 +00:00
|
|
|
|
|
|
|
end
|